| @@ 17-51 (lines=35) @@ | ||
| 14 | use Zenify\DoctrineFilters\Tests\ContainerFactory; |
|
| 15 | ||
| 16 | ||
| 17 | final class EnableFiltersSubscriberTest extends TestCase |
|
| 18 | { |
|
| 19 | ||
| 20 | /** |
|
| 21 | * @var EntityManagerInterface |
|
| 22 | */ |
|
| 23 | private $entityManager; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * @var EventDispatcherInterface |
|
| 27 | */ |
|
| 28 | private $eventDispatcher; |
|
| 29 | ||
| 30 | ||
| 31 | protected function setUp() |
|
| 32 | { |
|
| 33 | $container = (new ContainerFactory)->create(); |
|
| 34 | $this->eventDispatcher = $container->getByType(EventDispatcherInterface::class); |
|
| 35 | $this->entityManager = $container->getByType(EntityManagerInterface::class); |
|
| 36 | } |
|
| 37 | ||
| 38 | ||
| 39 | public function testDispatchEvent() |
|
| 40 | { |
|
| 41 | $filters = $this->entityManager->getFilters(); |
|
| 42 | $this->assertCount(0, $filters->getEnabledFilters()); |
|
| 43 | ||
| 44 | $applicationMock = $this->prophesize(Application::class); |
|
| 45 | $applicationStartupEvent = new ApplicationStartupEvent($applicationMock->reveal()); |
|
| 46 | $this->eventDispatcher->dispatch(ApplicationStartupEvent::NAME, $applicationStartupEvent); |
|
| 47 | ||
| 48 | $this->assertCount(2, $filters->getEnabledFilters()); |
|
| 49 | } |
|
| 50 | ||
| 51 | } |
|
| 52 | ||
| @@ 15-51 (lines=37) @@ | ||
| 12 | use Zenify\DoctrineFilters\Tests\ContainerFactory; |
|
| 13 | ||
| 14 | ||
| 15 | final class FilterManagerTest extends TestCase |
|
| 16 | { |
|
| 17 | ||
| 18 | /** |
|
| 19 | * @var EntityManagerInterface |
|
| 20 | */ |
|
| 21 | private $entityManager; |
|
| 22 | ||
| 23 | /** |
|
| 24 | * @var FilterManagerInterface |
|
| 25 | */ |
|
| 26 | private $filterManager; |
|
| 27 | ||
| 28 | ||
| 29 | protected function setUp() |
|
| 30 | { |
|
| 31 | $container = (new ContainerFactory)->create(); |
|
| 32 | $this->entityManager = $container->getByType(EntityManagerInterface::class); |
|
| 33 | $this->filterManager = $container->getByType(FilterManagerInterface::class); |
|
| 34 | } |
|
| 35 | ||
| 36 | ||
| 37 | public function testEnabledFilters() |
|
| 38 | { |
|
| 39 | $filterCollection = $this->entityManager->getFilters(); |
|
| 40 | $this->assertInstanceOf(FilterCollection::class, $filterCollection); |
|
| 41 | $this->assertCount(0, $filterCollection->getEnabledFilters()); |
|
| 42 | ||
| 43 | $this->filterManager->enableFilters(); |
|
| 44 | ||
| 45 | $this->assertCount(2, $filterCollection->getEnabledFilters()); |
|
| 46 | foreach ($filterCollection->getEnabledFilters() as $filter) { |
|
| 47 | $this->assertInstanceOf(FilterInterface::class, $filter); |
|
| 48 | } |
|
| 49 | } |
|
| 50 | ||
| 51 | } |
|
| 52 | ||