Exception.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\Exception\Test\Unit;
  36. use Hoa\Event;
  37. use Hoa\Exception\Exception as SUT;
  38. use Hoa\Test;
  39. /**
  40. * Class \Hoa\Exception\Test\Unit\Exception.
  41. *
  42. * Test suite of the exception class.
  43. *
  44. * @copyright Copyright © 2007-2017 Hoa community
  45. * @license New BSD License
  46. */
  47. class Exception extends Test\Unit\Suite
  48. {
  49. public function case_is_an_idle_exception()
  50. {
  51. $this
  52. ->when($result = new SUT('foo'))
  53. ->then
  54. ->object($result)
  55. ->isInstanceOf('Hoa\Exception\Idle');
  56. }
  57. public function case_event_is_registered()
  58. {
  59. $this
  60. ->given(new SUT('foo'))
  61. ->when($result = Event::eventExists('hoa://Event/Exception'))
  62. ->then
  63. ->boolean($result)
  64. ->isTrue();
  65. }
  66. public function case_event_is_sent()
  67. {
  68. $self = $this;
  69. $this
  70. ->given(
  71. Event::getEvent('hoa://Event/Exception')->attach(
  72. function (Event\Bucket $bucket) use ($self, &$called) {
  73. $called = true;
  74. $self
  75. ->object($bucket->getSource())
  76. ->isInstanceOf('Hoa\Exception\Exception')
  77. ->string($bucket->getSource()->getMessage())
  78. ->isEqualTo('foo')
  79. ->object($bucket->getData())
  80. ->isIdenticalTo($bucket->getSource());
  81. }
  82. )
  83. )
  84. ->when(new SUT('foo'))
  85. ->then
  86. ->boolean($called)
  87. ->isTrue();
  88. }
  89. }