ExceptionTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Exception
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once 'Zend/Exception.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Exception
  26. * @subpackage UnitTests
  27. * @group Zend_Exception
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_ExceptionTest extends PHPUnit_Framework_TestCase
  32. {
  33. public function testConstructorDefaults()
  34. {
  35. $e = new Zend_Exception();
  36. $this->assertEquals('', $e->getMessage());
  37. $this->assertEquals(0, $e->getCode());
  38. $this->assertNull($e->getPrevious());
  39. }
  40. public function testMessage()
  41. {
  42. $e = new Zend_Exception('msg');
  43. $this->assertEquals('msg', $e->getMessage());
  44. }
  45. public function testCode()
  46. {
  47. $e = new Zend_Exception('msg', 100);
  48. $this->assertEquals(100, $e->getCode());
  49. }
  50. public function testPrevious()
  51. {
  52. $p = new Zend_Exception('p', 0);
  53. $e = new Zend_Exception('e', 0, $p);
  54. $this->assertEquals($p, $e->getPrevious());
  55. }
  56. public function testToString()
  57. {
  58. $p = new Zend_Exception('p', 0);
  59. $e = new Zend_Exception('e', 0, $p);
  60. $s = $e->__toString();
  61. $this->assertContains('p', $s);
  62. $this->assertContains('Next', $s);
  63. $this->assertContains('e', $s);
  64. }
  65. }