FunctionsTest.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Core;
  16. use Cake\TestSuite\TestCase;
  17. /**
  18. * Test cases for functions in Core\functions.php
  19. */
  20. class FunctionsTest extends TestCase
  21. {
  22. /**
  23. * Test cases for env()
  24. */
  25. public function testEnv()
  26. {
  27. $_ENV['DOES_NOT_EXIST'] = null;
  28. $this->assertNull(env('DOES_NOT_EXIST'));
  29. $this->assertEquals('default', env('DOES_NOT_EXIST', 'default'));
  30. $_ENV['DOES_EXIST'] = 'some value';
  31. $this->assertEquals('some value', env('DOES_EXIST'));
  32. $this->assertEquals('some value', env('DOES_EXIST', 'default'));
  33. $_ENV['EMPTY_VALUE'] = '';
  34. $this->assertEquals('', env('EMPTY_VALUE'));
  35. $this->assertEquals('', env('EMPTY_VALUE', 'default'));
  36. $_ENV['ZERO'] = '0';
  37. $this->assertEquals('0', env('ZERO'));
  38. $this->assertEquals('0', env('ZERO', '1'));
  39. }
  40. /**
  41. * Test error messages coming out when debug is on, manually setting the stack frame
  42. *
  43. * @expectedException PHPUnit\Framework\Error\Deprecated
  44. * @expectedExceptionMessage This is going away - [internal], line: ??
  45. */
  46. public function testDeprecationWarningEnabled()
  47. {
  48. error_reporting(E_ALL);
  49. deprecationWarning('This is going away', 1);
  50. }
  51. /**
  52. * Test error messages coming out when debug is on, not setting the stack frame manually
  53. *
  54. * @expectedException PHPUnit\Framework\Error\Deprecated
  55. * @expectedExceptionMessageRegExp /This is going away - (.*?)[\/\\]TestCase.php, line\: \d+/
  56. */
  57. public function testDeprecationWarningEnabledDefaultFrame()
  58. {
  59. error_reporting(E_ALL);
  60. deprecationWarning('This is going away');
  61. }
  62. /**
  63. * Test no error when debug is off.
  64. *
  65. * @return void
  66. */
  67. public function testDeprecationWarningLevelDisabled()
  68. {
  69. error_reporting(E_ALL ^ E_USER_DEPRECATED);
  70. $this->assertNull(deprecationWarning('This is going away'));
  71. }
  72. /**
  73. * testing getTypeName()
  74. *
  75. * @return void
  76. */
  77. public function testgetTypeName()
  78. {
  79. $this->assertEquals('stdClass', getTypeName(new \stdClass()));
  80. $this->assertEquals('array', getTypeName([]));
  81. $this->assertEquals('string', getTypeName(''));
  82. }
  83. }