|
|
@@ -0,0 +1,168 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+declare(strict_types=1);
|
|
|
+
|
|
|
+namespace App\tests\Unit\State\Provider;
|
|
|
+
|
|
|
+use ApiPlatform\Metadata\Get;
|
|
|
+use ApiPlatform\Metadata\GetCollection;
|
|
|
+use ApiPlatform\State\Pagination\TraversablePaginator;
|
|
|
+use App\ApiResources\Freemium\FreemiumEvent;
|
|
|
+use App\Entity\Booking\Event;
|
|
|
+use App\Entity\Core\Categories;
|
|
|
+use App\Repository\Booking\EventRepository;
|
|
|
+use App\Service\Doctrine\FiltersConfigurationService;
|
|
|
+use App\Service\State\Provider\ProviderUtils;
|
|
|
+use App\State\Provider\Freemium\FreemiumEventProvider;
|
|
|
+use Doctrine\Common\Collections\ArrayCollection;
|
|
|
+use PHPUnit\Framework\MockObject\MockObject;
|
|
|
+use PHPUnit\Framework\TestCase;
|
|
|
+use Symfony\Component\ObjectMapper\ObjectMapperInterface;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Unit tests for ShopService.
|
|
|
+ */
|
|
|
+class FreemiumEventProviderTest extends TestCase
|
|
|
+{
|
|
|
+ private readonly MockObject|ProviderUtils $providerUtils;
|
|
|
+ private readonly MockObject|ObjectMapperInterface $objectMapper;
|
|
|
+ private readonly MockObject|EventRepository $eventRepository;
|
|
|
+ private readonly MockObject|FiltersConfigurationService $filtersConfigurationService;
|
|
|
+
|
|
|
+ public function setUp(): void
|
|
|
+ {
|
|
|
+ $this->providerUtils = $this->getMockBuilder(ProviderUtils::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->objectMapper = $this->getMockBuilder(ObjectMapperInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->eventRepository = $this->getMockBuilder(EventRepository::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->filtersConfigurationService = $this->getMockBuilder(FiltersConfigurationService::class)->disableOriginalConstructor()->getMock();
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getFreemiumEventProviderMockFor(string $methodName): FreemiumEventProvider|MockObject
|
|
|
+ {
|
|
|
+ $freemiumEventProvider = $this
|
|
|
+ ->getMockBuilder(FreemiumEventProvider::class)
|
|
|
+ ->setConstructorArgs(
|
|
|
+ [
|
|
|
+ $this->providerUtils,
|
|
|
+ $this->objectMapper,
|
|
|
+ $this->eventRepository,
|
|
|
+ $this->filtersConfigurationService,
|
|
|
+ ]
|
|
|
+ )
|
|
|
+ ->setMethodsExcept([$methodName])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ return $freemiumEventProvider;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test provide method for GetCollection operation
|
|
|
+ */
|
|
|
+ public function testProvideGetCollectionMethod(): void
|
|
|
+ {
|
|
|
+ $freemiumEventProvide = $this->getFreemiumEventProviderMockFor('provide');
|
|
|
+
|
|
|
+ $operation = new GetCollection();
|
|
|
+
|
|
|
+ $freemiumEventProvide->expects(self::once())
|
|
|
+ ->method('provideCollection')
|
|
|
+ ->with($operation, [])
|
|
|
+ ->willReturn(new TraversablePaginator(new \ArrayIterator([]), 0, 10, 0))
|
|
|
+ ;
|
|
|
+
|
|
|
+ $freemiumEventProvide->provide($operation);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test provide method for Get operation
|
|
|
+ */
|
|
|
+ public function testProvideGetMethod(): void
|
|
|
+ {
|
|
|
+ $freemiumEventProvide = $this->getFreemiumEventProviderMockFor('provide');
|
|
|
+ $freemiumEvent= $this->getMockBuilder(FreemiumEvent::class)->getMock();
|
|
|
+
|
|
|
+ $operation = new Get();
|
|
|
+
|
|
|
+ $freemiumEventProvide->expects(self::once())
|
|
|
+ ->method('provideItem')
|
|
|
+ ->with([], [])
|
|
|
+ ->willReturn($freemiumEvent)
|
|
|
+ ;
|
|
|
+
|
|
|
+ $freemiumEventProvide->provide($operation);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test provideCollection method
|
|
|
+ */
|
|
|
+ public function testProvideCollectionMethod(): void
|
|
|
+ {
|
|
|
+ $freemiumEventProvide = $this->getFreemiumEventProviderMockFor('provideCollection');
|
|
|
+ $freemiumEvent= $this->getMockBuilder(FreemiumEvent::class)->getMock();
|
|
|
+
|
|
|
+ $operation = new GetCollection();
|
|
|
+
|
|
|
+ $this->filtersConfigurationService->expects(self::once())
|
|
|
+ ->method('suspendTimeConstraintFilters');
|
|
|
+
|
|
|
+ $traversable = new TraversablePaginator(new \ArrayIterator([$freemiumEvent, $freemiumEvent]), 0, 10, 2);
|
|
|
+ $this->providerUtils->expects(self::once())
|
|
|
+ ->method('applyCollectionExtensionsAndPagination')
|
|
|
+ ->with(Event::class, $operation, [])
|
|
|
+ ->willReturn($traversable);
|
|
|
+
|
|
|
+ $this->objectMapper->expects(self::exactly(2))
|
|
|
+ ->method('map')
|
|
|
+ ->willReturnOnConsecutiveCalls($freemiumEvent, $freemiumEvent);
|
|
|
+
|
|
|
+ $this->filtersConfigurationService->expects(self::once())
|
|
|
+ ->method('restoreTimeConstraintFilters');
|
|
|
+
|
|
|
+ $this->providerUtils->expects(self::once())
|
|
|
+ ->method('getTraversablePaginator')
|
|
|
+ ->with([$freemiumEvent, $freemiumEvent], $traversable)
|
|
|
+ ->willReturn($traversable)
|
|
|
+ ;
|
|
|
+
|
|
|
+ $freemiumEventProvide->provideCollection($operation, []);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test provideItem method
|
|
|
+ */
|
|
|
+ public function testProvideItemMethod(): void
|
|
|
+ {
|
|
|
+ $uriVariables = ['id' => 1];
|
|
|
+ $freemiumEventProvide = $this->getFreemiumEventProviderMockFor('provideItem');
|
|
|
+
|
|
|
+ $event= $this->getMockBuilder(Event::class)->getMock();
|
|
|
+ $category= $this->getMockBuilder(Categories::class)->getMock();
|
|
|
+ $categories = new ArrayCollection([$category, $category]);
|
|
|
+ $event->method('getCategories')->willReturn($categories);
|
|
|
+
|
|
|
+ $this->filtersConfigurationService->expects(self::once())
|
|
|
+ ->method('suspendTimeConstraintFilters');
|
|
|
+
|
|
|
+ $this->eventRepository->expects(self::once())
|
|
|
+ ->method('find')
|
|
|
+ ->with(1)
|
|
|
+ ->willReturn($event)
|
|
|
+ ;
|
|
|
+
|
|
|
+ $this->filtersConfigurationService->expects(self::once())
|
|
|
+ ->method('restoreTimeConstraintFilters');
|
|
|
+
|
|
|
+ $freemiumEvent= new FreemiumEvent();
|
|
|
+ $this->objectMapper->expects(self::once())
|
|
|
+ ->method('map')
|
|
|
+ ->willReturn($freemiumEvent);
|
|
|
+
|
|
|
+ $event->expects(self::once())
|
|
|
+ ->method('getCategories')
|
|
|
+ ->willReturn($categories)
|
|
|
+ ;
|
|
|
+
|
|
|
+ $freemiumEventProvide->provideItem($uriVariables, []);
|
|
|
+ $this->assertEquals(2, count($freemiumEvent->getCategories()));
|
|
|
+ }
|
|
|
+}
|