| @@ -3,45 +3,14 @@ | ||
| 3 | 3 | declare( strict_types=1 ); |
| 4 | 4 | |
| 5 | 5 | namespace Tests\Module\Shipping; |
| 6 | 6 | |
| 7 | -use Packetery\Module\Carrier\CarDeliveryConfig; | |
| 8 | -use Packetery\Module\Carrier\CarrierOptionsFactory; | |
| 9 | -use Packetery\Module\Carrier\EntityRepository; | |
| 10 | -use Packetery\Module\ContextResolver; | |
| 11 | 7 | use Packetery\Module\Shipping\BaseShippingMethod; |
| 12 | 8 | use Packetery\Module\Shipping\ShippingProvider; |
| 13 | 9 | use Packetery\Module\ShippingMethod; |
| 14 | -use Packetery\Module\ShippingZoneRepository; | |
| 15 | -use PHPUnit\Framework\MockObject\MockObject; | |
| 16 | 10 | use PHPUnit\Framework\TestCase; |
| 17 | -use ReflectionClass; | |
| 18 | 11 | |
| 19 | 12 | class ShippingProviderTest extends TestCase { |
| 20 | - | |
| 21 | - private ContextResolver&MockObject $contextResolver; | |
| 22 | - private ShippingZoneRepository&MockObject $shippingZoneRepository; | |
| 23 | - | |
| 24 | - private function createShippingProvider(): ShippingProvider { | |
| 25 | - $this->contextResolver = $this->createMock( ContextResolver::class ); | |
| 26 | - $this->shippingZoneRepository = $this->createMock( ShippingZoneRepository::class ); | |
| 27 | - | |
| 28 | - return new ShippingProvider( | |
| 29 | - $this->createMock( CarDeliveryConfig::class ), | |
| 30 | - $this->contextResolver, | |
| 31 | - $this->shippingZoneRepository, | |
| 32 | - $this->createMock( EntityRepository::class ), | |
| 33 | - $this->createMock( CarrierOptionsFactory::class ) | |
| 34 | - ); | |
| 35 | - } | |
| 36 | - | |
| 37 | - public function tearDown(): void { | |
| 38 | - $shippingProviderReflection = new ReflectionClass( ShippingProvider::class ); | |
| 39 | - $property = $shippingProviderReflection->getProperty( 'sortedMethodsCache' ); | |
| 40 | - $property->setAccessible( true ); | |
| 41 | - $property->setValue( [] ); | |
| 42 | - } | |
| 43 | - | |
| 44 | 13 | /** |
| 45 | 14 | * @return array |
| 46 | 15 | */ |
| 47 | 16 | public static function shippingMethodsProvider(): array { |
| @@ -77,34 +46,6 @@ | ||
| 77 | 46 | * @dataProvider shippingMethodsProvider |
| 78 | 47 | */ |
| 79 | 48 | public function testIsPacketaMethod( $methodId, $isPacketaMethod ): void { |
| 80 | 49 | self::assertEquals( $isPacketaMethod, ShippingProvider::isPacketaMethod( $methodId ) ); |
| 81 | - } | |
| 82 | - | |
| 83 | - public function testGetSortedCachedMethodsFillsCache(): void { | |
| 84 | - $shippingProvider = $this->createShippingProvider(); | |
| 85 | - | |
| 86 | - $dummyZoneId = 123; | |
| 87 | - $this->contextResolver->expects( $this->once() )->method( 'getShippingZoneId' )->willReturn( $dummyZoneId ); | |
| 88 | - $this->shippingZoneRepository->expects( $this->once() )->method( 'getCountryCodesForShippingZone' )->willReturn( [] ); | |
| 89 | - | |
| 90 | - $shippingProvider->getSortedCachedMethods( [] ); | |
| 91 | - } | |
| 92 | - | |
| 93 | - public function testGetSortedCachedMethodsGetsFromCache(): void { | |
| 94 | - $shippingProvider = $this->createShippingProvider(); | |
| 95 | - | |
| 96 | - $originalMethods = []; | |
| 97 | - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize | |
| 98 | - $cacheKey = crc32( serialize( $originalMethods ) ); | |
| 99 | - | |
| 100 | - $shippingProviderReflection = new ReflectionClass( ShippingProvider::class ); | |
| 101 | - $property = $shippingProviderReflection->getProperty( 'sortedMethodsCache' ); | |
| 102 | - $property->setAccessible( true ); | |
| 103 | - $property->setValue( [ $cacheKey => [ 'dummyMethodId' => 'dummyMethodClass' ] ] ); | |
| 104 | - | |
| 105 | - $this->contextResolver->expects( $this->never() )->method( 'getShippingZoneId' ); | |
| 106 | - $this->shippingZoneRepository->expects( $this->never() )->method( 'getCountryCodesForShippingZone' ); | |
| 107 | - | |
| 108 | - $shippingProvider->getSortedCachedMethods( $originalMethods ); | |
| 109 | 50 | } |
| 110 | 51 | } |