ServiceConfigTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 4.2.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\Core;
  17. use Cake\Core\Configure;
  18. use Cake\Core\ServiceConfig;
  19. use Cake\TestSuite\TestCase;
  20. /**
  21. * ServiceConfigTest
  22. */
  23. class ServiceConfigTest extends TestCase
  24. {
  25. public function testGet(): void
  26. {
  27. Configure::write('first', 'first-val');
  28. Configure::write('nested.path', 'nested-val');
  29. $config = new ServiceConfig();
  30. $this->assertSame('first-val', $config->get('first'));
  31. $this->assertSame('nested-val', $config->get('nested.path'));
  32. $this->assertNull($config->get('nope'));
  33. $this->assertNull($config->get('nope'));
  34. $this->assertSame('default', $config->get('nested.nope', 'default'));
  35. }
  36. public function testHas(): void
  37. {
  38. Configure::write('first', 'first-val');
  39. Configure::write('nested.path', 'nested-val');
  40. Configure::write('nullval', null);
  41. $config = new ServiceConfig();
  42. $this->assertFalse($config->has('nope'));
  43. $this->assertTrue($config->has('first'));
  44. $this->assertTrue($config->has('nested.path'));
  45. $this->assertFalse($config->has('nullval'));
  46. }
  47. }