diff --git a/composer.json b/composer.json index fbfd6cf..c71b3c6 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,6 @@ "symfony/http-foundation": "^5.4 || ^6.0", "symfony/http-kernel": "^5.4 || ^6.0", "symfony/intl": "^5.4 || ^6.0", - "symfony/messenger": "^5.4 || ^6.0", "symfony/options-resolver": "^5.4 || ^6.0", "symfony/routing": "^5.4 || ^6.0", "symfony/security-bundle": "^5.4 || ^6.0", diff --git a/src/Command/LoadPickupPointsCommand.php b/src/Command/LoadPickupPointsCommand.php deleted file mode 100644 index e996f14..0000000 --- a/src/Command/LoadPickupPointsCommand.php +++ /dev/null @@ -1,78 +0,0 @@ -providerRegistry = $providerRegistry; - $this->messageBus = $messageBus; - - parent::__construct(); - } - - public function configure(): void - { - $this - ->setDescription('Load all pickup points into local database') - ->addArgument('provider', InputArgument::OPTIONAL, 'If given, the command will only fetch pickup points from this provider') - ; - } - - public function execute(InputInterface $input, OutputInterface $output): int - { - $this->io = new SymfonyStyle($input, $output); - - $providerCode = $input->getArgument('provider'); - - if (is_string($providerCode)) { - $providers = [$this->providerRegistry->get($providerCode)]; - } else { - $providers = $this->providerRegistry->all(); - } - - $this->dispatch($providers); - - return 0; - } - - private function dispatch(array $providers): void - { - ProgressBar::setFormatDefinition('custom', ' %current%/%max%: %message%'); - - $progressBar = $this->io->createProgressBar(count($providers)); - $progressBar->setFormat('custom'); - - foreach ($providers as $provider) { - $progressBar->setMessage(sprintf('Dispatching command to load pickup points for %s', (string) $provider)); - $this->messageBus->dispatch(new LoadPickupPoints($provider)); - $progressBar->advance(); - } - $progressBar->finish(); - - $this->io->newLine(); - $this->io->success('All commands dispatched!'); - } -} diff --git a/src/DependencyInjection/Compiler/RegisterProvidersPass.php b/src/DependencyInjection/Compiler/RegisterProvidersPass.php index 2675d7f..0ea8c8b 100644 --- a/src/DependencyInjection/Compiler/RegisterProvidersPass.php +++ b/src/DependencyInjection/Compiler/RegisterProvidersPass.php @@ -6,7 +6,6 @@ use InvalidArgumentException; use Setono\SyliusPickupPointPlugin\Provider\CachedProvider; -use Setono\SyliusPickupPointPlugin\Provider\LocalProvider; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -22,7 +21,6 @@ public function process(ContainerBuilder $container): void $registry = $container->getDefinition('setono_sylius_pickup_point.registry.provider'); $cacheEnabled = $container->getParameter('setono_sylius_pickup_point.cache.enabled') === true; - $localEnabled = $container->getParameter('setono_sylius_pickup_point.local') === true; $typeToLabelMap = []; foreach ($container->findTaggedServiceIds('setono_sylius_pickup_point.provider') as $id => $tagged) { @@ -45,18 +43,6 @@ public function process(ContainerBuilder $container): void $container->setDefinition($id, $cachedDefinition); } - if ($localEnabled) { - $decoratedId = $id; - $id .= '.local'; // overwrite the id - $cachedDefinition = new Definition(LocalProvider::class, [ - new Reference($id . '.inner'), - new Reference('setono_sylius_pickup_point.repository.pickup_point'), - ]); - $cachedDefinition->setDecoratedService($decoratedId, null, 512); - - $container->setDefinition($id, $cachedDefinition); - } - $registry->addMethodCall('register', [$attributes['code'], new Reference($id)]); } } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index e6cbedf..4e69913 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -7,13 +7,7 @@ use Setono\DAOBundle\SetonoDAOBundle; use Setono\GlsWebserviceBundle\SetonoGlsWebserviceBundle; use Setono\PostNordBundle\SetonoPostNordBundle; -use Setono\SyliusPickupPointPlugin\Doctrine\ORM\PickupPointRepository; -use Setono\SyliusPickupPointPlugin\Model\PickupPoint; -use Sylius\Bundle\ResourceBundle\Controller\ResourceController; -use Sylius\Bundle\ResourceBundle\Form\Type\DefaultResourceType; use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; -use Sylius\Component\Resource\Factory\Factory; -use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; @@ -40,11 +34,6 @@ public function getConfigTreeBuilder(): TreeBuilder ->end() ->end() ->end() - ->booleanNode('local') - ->defaultValue(true) - ->info('Whether to use the local database when timeouts occur in third party HTTP calls. Remember to run the setono-sylius-pickup-point:load-pickup-points command periodically to populate the local database with pickup points') - ->example(true) - ->end() ->arrayNode('providers') ->addDefaultsIfNotSet() ->children() @@ -72,31 +61,6 @@ public function getConfigTreeBuilder(): TreeBuilder ->end() ; - $this->addResourcesSection($rootNode); - return $treeBuilder; } - - private function addResourcesSection(ArrayNodeDefinition $node): void - { - /** @psalm-suppress MixedMethodCall,PossiblyUndefinedMethod,PossiblyNullReference */ - $node - ->children() - ->arrayNode('resources') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('pickup_point') - ->addDefaultsIfNotSet() - ->children() - ->variableNode('options')->end() - ->arrayNode('classes') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('model')->defaultValue(PickupPoint::class)->cannotBeEmpty()->end() - ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() - ->scalarNode('repository')->defaultValue(PickupPointRepository::class)->cannotBeEmpty()->end() - ->scalarNode('form')->defaultValue(DefaultResourceType::class)->end() - ->scalarNode('factory')->defaultValue(Factory::class)->end() - ; - } } diff --git a/src/DependencyInjection/SetonoSyliusPickupPointExtension.php b/src/DependencyInjection/SetonoSyliusPickupPointExtension.php index bff3c93..d791e9b 100644 --- a/src/DependencyInjection/SetonoSyliusPickupPointExtension.php +++ b/src/DependencyInjection/SetonoSyliusPickupPointExtension.php @@ -19,9 +19,6 @@ public function load(array $configs, ContainerBuilder $container): void /** @psalm-suppress PossiblyNullArgument */ $config = $this->processConfiguration($this->getConfiguration([], $container), $configs); $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - $container->setParameter('setono_sylius_pickup_point.local', $config['local']); - - $this->registerResources('setono_sylius_pickup_point', $config['driver'], $config['resources'], $container); $loader->load('services.xml'); diff --git a/src/Doctrine/ORM/PickupPointRepository.php b/src/Doctrine/ORM/PickupPointRepository.php deleted file mode 100644 index e210c6e..0000000 --- a/src/Doctrine/ORM/PickupPointRepository.php +++ /dev/null @@ -1,61 +0,0 @@ -createQueryBuilder('o') - ->andWhere('o.code.id = :codeId') - ->andWhere('o.code.provider = :codeProvider') - ->andWhere('o.code.country = :codeCountry') - ->setParameters([ - 'codeId' => $code->getIdPart(), - 'codeProvider' => $code->getProviderPart(), - 'codeCountry' => $code->getCountryPart(), - ]) - ->getQuery() - ->getOneOrNullResult() - ; - } - - public function findByOrder(OrderInterface $order, string $provider): array - { - $shippingAddress = $order->getShippingAddress(); - if (null === $shippingAddress) { - return []; - } - - $countryCode = $shippingAddress->getCountryCode(); - if (null === $countryCode) { - return []; - } - - $postalCode = $shippingAddress->getPostcode(); - if (null === $postalCode) { - return []; - } - - return $this->createQueryBuilder('o') - ->andWhere('o.code.provider = :provider') - ->andWhere('o.code.country = :country') - ->andWhere('o.zipCode = :postalCode') - ->setParameters([ - 'provider' => $provider, - 'country' => $countryCode, - 'postalCode' => $postalCode, - ]) - ->getQuery() - ->getResult() - ; - } -} diff --git a/src/Factory/PickupPointFactory.php b/src/Factory/PickupPointFactory.php new file mode 100644 index 0000000..725c0c8 --- /dev/null +++ b/src/Factory/PickupPointFactory.php @@ -0,0 +1,16 @@ +getCode(); - } - - Assert::string($provider); - - $this->provider = $provider; - } - - public function getProvider(): string - { - return $this->provider; - } -} diff --git a/src/Message/Handler/LoadPickupPointsHandler.php b/src/Message/Handler/LoadPickupPointsHandler.php deleted file mode 100644 index e260293..0000000 --- a/src/Message/Handler/LoadPickupPointsHandler.php +++ /dev/null @@ -1,76 +0,0 @@ -providerRegistry = $providerRegistry; - $this->pickupPointRepository = $pickupPointRepository; - $this->pickupPointManager = $pickupPointManager; - } - - public function __invoke(LoadPickupPoints $message): void - { - /** @var ProviderInterface $provider */ - $provider = $this->providerRegistry->get($message->getProvider()); - - $pickupPoints = $provider->findAllPickupPoints(); - - $i = 1; - - foreach ($pickupPoints as $pickupPoint) { - $pickupPointCode = $pickupPoint->getCode(); - Assert::notNull($pickupPointCode); - - $localPickupPoint = $this->pickupPointRepository->findOneByCode($pickupPointCode); - - // if it's found, we will update the properties, else we will just persist this object - if (null === $localPickupPoint) { - $this->pickupPointManager->persist($pickupPoint); - } else { - $localPickupPoint->setName($pickupPoint->getName()); - $localPickupPoint->setAddress($pickupPoint->getAddress()); - $localPickupPoint->setZipCode($pickupPoint->getZipCode()); - $localPickupPoint->setCity($pickupPoint->getCity()); - $localPickupPoint->setCountry($pickupPoint->getCountry()); - $localPickupPoint->setLatitude($pickupPoint->getLatitude()); - $localPickupPoint->setLongitude($pickupPoint->getLongitude()); - } - - if ($i % 50 === 0) { - $this->flush(); - } - - ++$i; - } - - $this->flush(); - } - - private function flush(): void - { - $this->pickupPointManager->flush(); - $this->pickupPointManager->clear(); - } -} diff --git a/src/Provider/DAOProvider.php b/src/Provider/DAOProvider.php index 767d51b..fe2594f 100644 --- a/src/Provider/DAOProvider.php +++ b/src/Provider/DAOProvider.php @@ -8,19 +8,18 @@ use Psr\Http\Client\NetworkExceptionInterface; use Setono\DAO\Client\ClientInterface; use Setono\SyliusPickupPointPlugin\Exception\TimeoutException; +use Setono\SyliusPickupPointPlugin\Factory\PickupPointFactoryInterface; use Setono\SyliusPickupPointPlugin\Model\PickupPointCode; use Setono\SyliusPickupPointPlugin\Model\PickupPointInterface; use Sylius\Component\Core\Model\OrderInterface; -use Sylius\Component\Resource\Factory\FactoryInterface; -use Webmozart\Assert\Assert; final class DAOProvider extends Provider { private ClientInterface $client; - private FactoryInterface $pickupPointFactory; + private PickupPointFactoryInterface $pickupPointFactory; - public function __construct(ClientInterface $client, FactoryInterface $pickupPointFactory) + public function __construct(ClientInterface $client, PickupPointFactoryInterface $pickupPointFactory) { $this->client = $client; $this->pickupPointFactory = $pickupPointFactory; @@ -101,11 +100,8 @@ private function populatePickupPoint(array $servicePoint): PickupPointInterface { $countryCode = 'DK'; // DAO only operates in Denmark - /** @var PickupPointInterface|object $pickupPoint */ $pickupPoint = $this->pickupPointFactory->createNew(); - Assert::isInstanceOf($pickupPoint, PickupPointInterface::class); - $pickupPoint->setCode(new PickupPointCode($servicePoint['shopId'], $this->getCode(), $countryCode)); $pickupPoint->setName($servicePoint['navn']); $pickupPoint->setAddress($servicePoint['adresse']); diff --git a/src/Provider/FakerProvider.php b/src/Provider/FakerProvider.php index 8c7e469..afa937d 100644 --- a/src/Provider/FakerProvider.php +++ b/src/Provider/FakerProvider.php @@ -6,20 +6,20 @@ use Faker\Factory; use Faker\Generator; +use Setono\SyliusPickupPointPlugin\Factory\PickupPointFactoryInterface; use Setono\SyliusPickupPointPlugin\Model\PickupPoint; use Setono\SyliusPickupPointPlugin\Model\PickupPointCode; use Setono\SyliusPickupPointPlugin\Model\PickupPointInterface; use Sylius\Component\Core\Model\OrderInterface; -use Sylius\Component\Resource\Factory\FactoryInterface; use Webmozart\Assert\Assert; final class FakerProvider extends Provider { private Generator $faker; - private FactoryInterface $pickupPointFactory; + private PickupPointFactoryInterface $pickupPointFactory; - public function __construct(FactoryInterface $pickupPointFactory) + public function __construct(PickupPointFactoryInterface $pickupPointFactory) { $this->faker = Factory::create(); $this->pickupPointFactory = $pickupPointFactory; @@ -69,11 +69,8 @@ private function createFakePickupPoint(string $index, ?string $countryCode = nul $countryCode = $this->faker->countryCode; } - /** @var PickupPointInterface|object $pickupPoint */ $pickupPoint = $this->pickupPointFactory->createNew(); - Assert::isInstanceOf($pickupPoint, PickupPointInterface::class); - $pickupPoint->setCode(new PickupPointCode($index, $this->getCode(), $countryCode)); $pickupPoint->setName("Post office #$index"); $pickupPoint->setAddress($this->faker->streetAddress); diff --git a/src/Provider/GlsProvider.php b/src/Provider/GlsProvider.php index 9f4f4df..a72ccc0 100644 --- a/src/Provider/GlsProvider.php +++ b/src/Provider/GlsProvider.php @@ -11,23 +11,22 @@ use Setono\GLS\Webservice\Exception\ParcelShopNotFoundException; use Setono\GLS\Webservice\Model\ParcelShop; use Setono\SyliusPickupPointPlugin\Exception\TimeoutException; +use Setono\SyliusPickupPointPlugin\Factory\PickupPointFactoryInterface; use Setono\SyliusPickupPointPlugin\Model\PickupPointCode; use Setono\SyliusPickupPointPlugin\Model\PickupPointInterface; use Sylius\Component\Core\Model\OrderInterface; -use Sylius\Component\Resource\Factory\FactoryInterface; -use Webmozart\Assert\Assert; final class GlsProvider extends Provider { private ClientInterface $client; - private FactoryInterface $pickupPointFactory; + private PickupPointFactoryInterface $pickupPointFactory; private array $countryCodes; public function __construct( ClientInterface $client, - FactoryInterface $pickupPointFactory, + PickupPointFactoryInterface $pickupPointFactory, array $countryCodes = ['DK', 'SE'] ) { $this->client = $client; @@ -110,11 +109,8 @@ public function getName(): string private function transform(ParcelShop $parcelShop): PickupPointInterface { - /** @var PickupPointInterface|object $pickupPoint */ $pickupPoint = $this->pickupPointFactory->createNew(); - Assert::isInstanceOf($pickupPoint, PickupPointInterface::class); - $pickupPoint->setCode(new PickupPointCode($parcelShop->getNumber(), $this->getCode(), $parcelShop->getCountryCode())); $pickupPoint->setName($parcelShop->getCompanyName()); $pickupPoint->setAddress($parcelShop->getStreetName()); diff --git a/src/Provider/LocalProvider.php b/src/Provider/LocalProvider.php deleted file mode 100644 index b6a2e4e..0000000 --- a/src/Provider/LocalProvider.php +++ /dev/null @@ -1,57 +0,0 @@ -decoratedProvider = $decoratedProvider; - $this->pickupPointRepository = $pickupPointRepository; - } - - public function findPickupPoints(OrderInterface $order): iterable - { - try { - return $this->decoratedProvider->findPickupPoints($order); - } catch (TimeoutException $e) { - return $this->pickupPointRepository->findByOrder($order, $this->decoratedProvider->getCode()); - } - } - - public function findPickupPoint(PickupPointCode $code): ?PickupPointInterface - { - try { - return $this->decoratedProvider->findPickupPoint($code); - } catch (TimeoutException $e) { - return $this->pickupPointRepository->findOneByCode($code); - } - } - - public function findAllPickupPoints(): iterable - { - yield from $this->decoratedProvider->findAllPickupPoints(); - } - - public function getCode(): string - { - return $this->decoratedProvider->getCode(); - } - - public function getName(): string - { - return $this->decoratedProvider->getName(); - } -} diff --git a/src/Provider/PostNordProvider.php b/src/Provider/PostNordProvider.php index e7a0979..99c32f7 100644 --- a/src/Provider/PostNordProvider.php +++ b/src/Provider/PostNordProvider.php @@ -8,11 +8,10 @@ use Psr\Http\Client\NetworkExceptionInterface; use Setono\PostNord\Client\ClientInterface; use Setono\SyliusPickupPointPlugin\Exception\TimeoutException; +use Setono\SyliusPickupPointPlugin\Factory\PickupPointFactoryInterface; use Setono\SyliusPickupPointPlugin\Model\PickupPointCode; use Setono\SyliusPickupPointPlugin\Model\PickupPointInterface; use Sylius\Component\Core\Model\OrderInterface; -use Sylius\Component\Resource\Factory\FactoryInterface; -use Webmozart\Assert\Assert; /** * @see https://developer.postnord.com/api/docs/location @@ -21,9 +20,9 @@ final class PostNordProvider extends Provider { private ClientInterface $client; - private FactoryInterface $pickupPointFactory; + private PickupPointFactoryInterface $pickupPointFactory; - public function __construct(ClientInterface $client, FactoryInterface $pickupPointFactory) + public function __construct(ClientInterface $client, PickupPointFactoryInterface $pickupPointFactory) { $this->client = $client; $this->pickupPointFactory = $pickupPointFactory; @@ -142,11 +141,8 @@ private function transform(array $servicePoint): PickupPointInterface $longitude = (float) $servicePoint['coordinates'][0]['easting']; } - /** @var PickupPointInterface|object $pickupPoint */ $pickupPoint = $this->pickupPointFactory->createNew(); - Assert::isInstanceOf($pickupPoint, PickupPointInterface::class); - $pickupPoint->setCode($id); $pickupPoint->setName($servicePoint['name']); $pickupPoint->setAddress($address); diff --git a/src/Repository/PickupPointRepositoryInterface.php b/src/Repository/PickupPointRepositoryInterface.php deleted file mode 100644 index dbafce7..0000000 --- a/src/Repository/PickupPointRepositoryInterface.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ - public function findByOrder(OrderInterface $order, string $provider): array; -} diff --git a/src/Resources/config/doctrine/model/PickupPoint.orm.xml b/src/Resources/config/doctrine/model/PickupPoint.orm.xml deleted file mode 100644 index 5e9d65d..0000000 --- a/src/Resources/config/doctrine/model/PickupPoint.orm.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/src/Resources/config/doctrine/model/PickupPointCode.orm.xml b/src/Resources/config/doctrine/model/PickupPointCode.orm.xml deleted file mode 100644 index c6b2341..0000000 --- a/src/Resources/config/doctrine/model/PickupPointCode.orm.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 8b2f6e0..48c0336 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -4,12 +4,11 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + - diff --git a/src/Resources/config/services/command.xml b/src/Resources/config/services/command.xml deleted file mode 100644 index 58bebef..0000000 --- a/src/Resources/config/services/command.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - diff --git a/src/Resources/config/services/factory.xml b/src/Resources/config/services/factory.xml new file mode 100644 index 0000000..a82eae8 --- /dev/null +++ b/src/Resources/config/services/factory.xml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/src/Resources/config/services/message.xml b/src/Resources/config/services/message.xml deleted file mode 100644 index ed0c3ef..0000000 --- a/src/Resources/config/services/message.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - diff --git a/tests/Application/config/packages/setono_sylius_pickup_point.yaml b/tests/Application/config/packages/setono_sylius_pickup_point.yaml index 0265651..2806ce0 100644 --- a/tests/Application/config/packages/setono_sylius_pickup_point.yaml +++ b/tests/Application/config/packages/setono_sylius_pickup_point.yaml @@ -12,7 +12,6 @@ setono_sylius_pickup_point: cache: enabled: true pool: setono_sylius_pickup_point.provider_cache_pool - local: true providers: faker: true gls: true diff --git a/tests/DependencyInjection/SetonoSyliusPickupPointExtensionTest.php b/tests/DependencyInjection/SetonoSyliusPickupPointExtensionTest.php index 3dbe566..2cec51b 100644 --- a/tests/DependencyInjection/SetonoSyliusPickupPointExtensionTest.php +++ b/tests/DependencyInjection/SetonoSyliusPickupPointExtensionTest.php @@ -38,7 +38,6 @@ public function after_loading_the_correct_parameters_has_been_set(): void { $this->load(); - $this->assertContainerBuilderHasParameter('setono_sylius_pickup_point.local', true); $this->assertContainerBuilderHasParameter('setono_sylius_pickup_point.cache.enabled', false); } } diff --git a/tests/Provider/LocalProviderTest.php b/tests/Provider/LocalProviderTest.php deleted file mode 100644 index 645b2c5..0000000 --- a/tests/Provider/LocalProviderTest.php +++ /dev/null @@ -1,123 +0,0 @@ -getProvider(); - self::assertSame('faker', $provider->getCode()); - } - - /** - * @test - */ - public function it_gets_name_from_decorated_provider(): void - { - $provider = $this->getProvider(); - self::assertSame('Faker', $provider->getName()); - } - - /** - * @test - */ - public function it_uses_local_provider_if_decorated_timeouts(): void - { - $order = $this->prophesize(OrderInterface::class); - - $pickupPoint = new PickupPoint(); - $pickupPoint->setCode(new PickupPointCode('123', 'gls', 'DK')); - $pickupPoint->setName('Service Point'); - $pickupPoint->setAddress('Street 123'); - $pickupPoint->setZipCode('1235A'); - $pickupPoint->setCity('Great City'); - $pickupPoint->setCountry('DK'); - - $repository = $this->prophesize(PickupPointRepositoryInterface::class); - $repository->findByOrder($order, 'timeout_provider')->willReturn([$pickupPoint]); - - $provider = $this->getProvider(true, $repository->reveal()); - - $pickupPoints = $provider->findPickupPoints($order->reveal()); - - self::assertNotEmpty($pickupPoints); - self::assertSame($pickupPoint, self::getFirstElementOfIterable($pickupPoints)); - } - - private function getProvider(bool $timeout = false, PickupPointRepositoryInterface $pickupPointRepository = null): LocalProvider - { - $pickupPointFactory = new Factory(PickupPoint::class); - - $provider = new FakerProvider($pickupPointFactory); - if ($timeout) { - $provider = new class() implements ProviderInterface { - public function __toString(): string - { - return $this->getName(); - } - - public function getCode(): string - { - return 'timeout_provider'; - } - - public function getName(): string - { - return 'Timeout provider'; - } - - public function findPickupPoints(OrderInterface $order): iterable - { - throw new TimeoutException(); - } - - public function findPickupPoint(PickupPointCode $code): ?PickupPointInterface - { - throw new TimeoutException(); - } - - public function findAllPickupPoints(): iterable - { - throw new TimeoutException(); - } - }; - } - - if (null === $pickupPointRepository) { - $repository = $this->prophesize(PickupPointRepositoryInterface::class); - $pickupPointRepository = $repository->reveal(); - } - - return new LocalProvider($provider, $pickupPointRepository); - } - - private static function getFirstElementOfIterable(iterable $list) - { - foreach ($list as $elm) { - return $elm; - } - - throw new \InvalidArgumentException('No elements in $list'); - } -}