You are here

private function AddressValidationTest::createMockedAvataxLib in Drupal Commerce Connector for AvaTax 8

Creates a mocked AvataxLib.

Parameters

string $fixture: The response body fixture.

Return value

\Drupal\commerce_avatax\AvataxLib The mock.

2 calls to AddressValidationTest::createMockedAvataxLib()
AddressValidationTest::testResolveAddress in tests/src/Kernel/AddressValidationTest.php
@covers \Drupal\commerce_avatax\AvataxLib::resolveAddress @dataProvider addressesData
AddressValidationTest::testvalidateAddress in tests/src/Kernel/AddressValidationTest.php
@covers \Drupal\commerce_avatax\AvataxLib::validateAddress @dataProvider addressesData

File

tests/src/Kernel/AddressValidationTest.php, line 191

Class

AddressValidationTest
Tests address resolving and validation.

Namespace

Drupal\Tests\commerce_avatax\Kernel

Code

private function createMockedAvataxLib(string $fixture) : AvataxLib {
  $client_factory = $this
    ->prophesize(ClientFactory::class);
  $mocked_response = $this
    ->prophesize(ResponseInterface::class);
  $mocked_body = $this
    ->prophesize(StreamInterface::class);
  $mocked_body
    ->getContents()
    ->willReturn(file_get_contents($fixture));
  $mocked_response
    ->getBody()
    ->willReturn($mocked_body
    ->reveal());
  $mocked_client = $this
    ->prophesize(ClientInterface::class);
  $mocked_client
    ->request('POST', 'api/v2/addresses/resolve', Argument::any())
    ->willReturn($mocked_response
    ->reveal())
    ->shouldBeCalledOnce();
  $client_factory
    ->createInstance(Argument::type('array'))
    ->willReturn($mocked_client
    ->reveal());
  return new AvataxLib($this->container
    ->get('plugin.manager.commerce_adjustment_type'), $this->container
    ->get('commerce_avatax.chain_tax_code_resolver'), $client_factory
    ->reveal(), $this->container
    ->get('config.factory'), $this->container
    ->get('event_dispatcher'), $this->container
    ->get('logger.channel.commerce_avatax'), $this->container
    ->get('module_handler'), $this->container
    ->get('cache.commerce_avatax'));
}