Bucket.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * Hoa
  4. *
  5. *
  6. * @license
  7. *
  8. * New BSD License
  9. *
  10. * Copyright © 2007-2017, Hoa community. All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * * Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * * Neither the name of the Hoa nor the names of its contributors may be
  20. * used to endorse or promote products derived from this software without
  21. * specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. namespace Hoa\Event\Test\Unit;
  36. use Hoa\Event as LUT;
  37. use Hoa\Event\Bucket as SUT;
  38. use Hoa\Test;
  39. /**
  40. * Class \Hoa\Event\Test\Unit\Bucket.
  41. *
  42. * Test suite of the bucket.
  43. *
  44. * @copyright Copyright © 2007-2017 Hoa community
  45. * @license New BSD License
  46. */
  47. class Bucket extends Test\Unit\Suite
  48. {
  49. public function case_constructor()
  50. {
  51. $this
  52. ->when($result = new SUT('foo'))
  53. ->then
  54. ->object($result)
  55. ->isInstanceOf('Hoa\Event\Bucket')
  56. ->string($result->getData())
  57. ->isEqualTo('foo');
  58. }
  59. public function case_send()
  60. {
  61. $self = $this;
  62. $this
  63. ->given(
  64. $eventId = 'hoa://Event/Test',
  65. $source = new \Mock\Hoa\Event\Source(),
  66. LUT::register($eventId, $source),
  67. $bucket = new SUT('foo'),
  68. LUT::getEvent($eventId)->attach(
  69. function (SUT $receivedBucket) use ($self, $bucket, &$called) {
  70. $called = true;
  71. $self
  72. ->object($receivedBucket)
  73. ->isIdenticalTo($bucket);
  74. }
  75. )
  76. )
  77. ->when($result = $bucket->send($eventId, $source))
  78. ->then
  79. ->variable($result)
  80. ->isNull()
  81. ->boolean($called)
  82. ->isTrue();
  83. }
  84. public function case_set_source()
  85. {
  86. $this
  87. ->given(
  88. $bucket = new SUT(),
  89. $sourceA = new \Mock\Hoa\Event\Source()
  90. )
  91. ->when($result = $bucket->setSource($sourceA))
  92. ->then
  93. ->variable($result)
  94. ->isNull()
  95. ->object($bucket->getSource())
  96. ->isIdenticalTo($sourceA)
  97. ->given($sourceB = new \Mock\Hoa\Event\Source())
  98. ->when($result = $bucket->setSource($sourceB))
  99. ->then
  100. ->object($result)
  101. ->isIdenticalTo($sourceA)
  102. ->object($bucket->getSource())
  103. ->isIdenticalTo($sourceB);
  104. }
  105. public function case_set_data()
  106. {
  107. $this
  108. ->given(
  109. $bucket = new SUT(),
  110. $datumA = 'foo'
  111. )
  112. ->when($result = $bucket->setData($datumA))
  113. ->then
  114. ->variable($result)
  115. ->isNull()
  116. ->string($bucket->getData())
  117. ->isEqualTo($datumA)
  118. ->given($datumB = 'bar')
  119. ->when($result = $bucket->setData($datumB))
  120. ->then
  121. ->string($result)
  122. ->isEqualTo($datumA)
  123. ->string($bucket->getData())
  124. ->isEqualTo($datumB);
  125. }
  126. }