SecurityExceptionTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 3.2.6
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\Controller\Exception;
  17. use Cake\Controller\Exception\SecurityException;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * SecurityException Test class
  21. */
  22. class SecurityExceptionTest extends TestCase
  23. {
  24. /**
  25. * @var \Cake\Controller\Exception\SecurityException
  26. */
  27. protected $securityException;
  28. /**
  29. * setUp method
  30. */
  31. public function setUp(): void
  32. {
  33. parent::setUp();
  34. $this->securityException = new SecurityException();
  35. }
  36. /**
  37. * Test the getType() function.
  38. */
  39. public function testGetType(): void
  40. {
  41. $this->assertSame(
  42. 'secure',
  43. $this->securityException->getType(),
  44. '::getType should always return the type of `secure`.'
  45. );
  46. }
  47. /**
  48. * Test the setMessage() function.
  49. */
  50. public function testSetMessage(): void
  51. {
  52. $sampleMessage = 'foo';
  53. $this->securityException->setMessage($sampleMessage);
  54. $this->assertSame(
  55. $sampleMessage,
  56. $this->securityException->getMessage(),
  57. '::getMessage should always return the message set.'
  58. );
  59. }
  60. /**
  61. * Test the setReason() and corresponding getReason() function.
  62. */
  63. public function testSetGetReason(): void
  64. {
  65. $sampleReason = 'canary';
  66. $this->securityException->setReason($sampleReason);
  67. $this->assertSame(
  68. $sampleReason,
  69. $this->securityException->getReason(),
  70. '::getReason should always return the reason set.'
  71. );
  72. }
  73. }