createMock(VersionDeterminer::class); $versionDeterminerMock->method('execute') ->willReturn('60'); $configBuilderMock = $this->getMockBuilder(ConfigBuilder::class) ->setMethods(['setScopeType','setScopeCode', 'build']) ->disableOriginalConstructor() ->getMock(); $configBuilderMock->method('setScopeType') ->willReturnSelf(); $configBuilderMock->method('setScopeCode') ->willReturnSelf(); $configBuilderMock->method('build') ->willReturn($this->createMock(ConfigurationInterface::class)); $realMapperFactory = new \Vertex\Mapper\MapperFactory(); $mapperFactory = $this->getObject( MapperFactoryProxy::class, [ 'versionDeterminer' => $versionDeterminerMock, 'configBuilder' => $configBuilderMock, 'factory' => $realMapperFactory, ] ); $this->quoteMock = $this->createMock(QuoteInterface::class); $this->taxRegistryMock = $this->createMock(TaxRegistry::class); $this->taxQuoteRequest = $this->getObject( TaxQuoteRequest::class, [ 'quote' => $this->quoteMock, 'cacheKeyGenerator' => $this->getObject( CacheKeyGenerator::class, ['mapperFactory' => $mapperFactory] ), 'taxRegistry' => $this->taxRegistryMock, 'mapperFactory' => $mapperFactory ] ); } /** * Test cached tax response handling. * * @covers \Vertex\Tax\Model\TaxQuote\TaxQuoteRequest::taxQuote() */ public function testTaxQuoteRequestCachedResponse() { $request = new Request(); $response = new Response(); $this->quoteMock->expects($this->once()) ->method('request') ->willReturn($response); $rawResponse = new \stdClass(); $rawResponse->QuotationResponse = new \stdClass(); $this->taxRegistryMock->expects($this->exactly(2)) ->method('lookup') ->willReturnOnConsecutiveCalls(null, $rawResponse); // Vertex sendApiRequest should be called once, testing uncached $result = $this->taxQuoteRequest->taxQuote($request); $this->assertEquals($response, $result); // It should not be called again, testing cached $result = $this->taxQuoteRequest->taxQuote($request); $this->assertInstanceOf(ResponseInterface::class, $result); } }