FunctionsTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. * @expectedExceptionMessageRegExp /This is going away - (.*?)[\/\\]TestCase.php, line\: \d+/
  45. */
  46. public function testDeprecationWarningEnabled()
  47. {
  48. $this->withErrorReporting(E_ALL, function () {
  49. deprecationWarning('This is going away', 1);
  50. });
  51. }
  52. /**
  53. * Test error messages coming out when debug is on, not setting the stack frame manually
  54. *
  55. * @expectedException PHPUnit\Framework\Error\Deprecated
  56. * @expectedExceptionMessageRegExp /This is going away - (.*?)[\/\\]FunctionsTest.php, line\: \d+/
  57. */
  58. public function testDeprecationWarningEnabledDefaultFrame()
  59. {
  60. $this->withErrorReporting(E_ALL, function () {
  61. deprecationWarning('This is going away');
  62. });
  63. }
  64. /**
  65. * Test no error when debug is off.
  66. *
  67. * @return void
  68. */
  69. public function testDeprecationWarningLevelDisabled()
  70. {
  71. $this->withErrorReporting(E_ALL ^ E_USER_DEPRECATED, function () {
  72. $this->assertNull(deprecationWarning('This is going away'));
  73. });
  74. }
  75. /**
  76. * testing getTypeName()
  77. *
  78. * @return void
  79. */
  80. public function testgetTypeName()
  81. {
  82. $this->assertEquals('stdClass', getTypeName(new \stdClass()));
  83. $this->assertEquals('array', getTypeName([]));
  84. $this->assertEquals('string', getTypeName(''));
  85. }
  86. }