ServicesResetterTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
  13. use Symfony\Component\HttpKernel\Tests\Fixtures\ClearableService;
  14. use Symfony\Component\HttpKernel\Tests\Fixtures\MultiResettableService;
  15. use Symfony\Component\HttpKernel\Tests\Fixtures\ResettableService;
  16. class ServicesResetterTest extends TestCase
  17. {
  18. protected function setUp(): void
  19. {
  20. ResettableService::$counter = 0;
  21. ClearableService::$counter = 0;
  22. MultiResettableService::$resetFirstCounter = 0;
  23. MultiResettableService::$resetSecondCounter = 0;
  24. }
  25. public function testResetServices()
  26. {
  27. $resetter = new ServicesResetter(new \ArrayIterator([
  28. 'id1' => new ResettableService(),
  29. 'id2' => new ClearableService(),
  30. 'id3' => new MultiResettableService(),
  31. ]), [
  32. 'id1' => ['reset'],
  33. 'id2' => ['clear'],
  34. 'id3' => ['resetFirst', 'resetSecond'],
  35. ]);
  36. $resetter->reset();
  37. $this->assertSame(1, ResettableService::$counter);
  38. $this->assertSame(1, ClearableService::$counter);
  39. $this->assertSame(1, MultiResettableService::$resetFirstCounter);
  40. $this->assertSame(1, MultiResettableService::$resetSecondCounter);
  41. }
  42. }