ServiceProviderTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\Container;
  18. use Cake\TestSuite\TestCase;
  19. use TestApp\ServiceProvider\PersonServiceProvider;
  20. /**
  21. * ServiceProviderTest
  22. */
  23. class ServiceProviderTest extends TestCase
  24. {
  25. public function testBootstrapHook(): void
  26. {
  27. $container = new Container();
  28. $container->addServiceProvider(new PersonServiceProvider());
  29. $this->assertTrue(
  30. $container->has('boot'),
  31. 'Should have service defined in bootstrap.'
  32. );
  33. $this->assertSame('boot', $container->get('boot')->name);
  34. }
  35. public function testServicesHook(): void
  36. {
  37. $container = new Container();
  38. $container->addServiceProvider(new PersonServiceProvider());
  39. $this->assertTrue($container->has('sally'), 'Should have service');
  40. $this->assertSame('sally', $container->get('sally')->name);
  41. }
  42. }