You are here

class FedExRequestTest in Commerce FedEx 8

Test Class for the Fedex Shipping Plugin.

@coversDefaultClass \Drupal\commerce_fedex\FedExRequest @group commerce_fedex

Hierarchy

Expanded class hierarchy of FedExRequestTest

File

tests/src/Unit/FedExRequestTest.php, line 11

Namespace

Drupal\Tests\commerce_fedex\Unit
View source
class FedExRequestTest extends FedExUnitTestBase {
  const RATE_SERVICE_SERVICE_ID = 'crs';
  const RATE_SERVICE_MAJOR_VERSION = 20;

  /**
   * A FedExRequest object to test.
   *
   * @var \Drupal\commerce_fedex\FedExRequest
   */
  protected $request;

  /**
   * A sample configuration to use.
   *
   * @var array
   */
  protected $configuration;

  /**
   * @covers ::getRateRequest
   */
  public function testRateRequest() {
    $rate_request = $this->request
      ->getRateRequest($this->configuration);
    $this
      ->assertInstanceOf("\\NicholasCreativeMedia\\FedExPHP\\Structs\\RateRequest", $rate_request);
    $client_detail = $rate_request
      ->getClientDetail();
    $this
      ->assertInstanceOf("\\NicholasCreativeMedia\\FedExPHP\\Structs\\ClientDetail", $client_detail);
    $this
      ->assertEquals('1234567', $client_detail
      ->getAccountNumber());
    $this
      ->assertEquals('9876543', $client_detail
      ->getMeterNumber());
    $web_authentication_detail = $rate_request
      ->getWebAuthenticationDetail();
    $this
      ->assertInstanceOf("\\NicholasCreativeMedia\\FedExPHP\\Structs\\WebAuthenticationDetail", $web_authentication_detail);
    $user_credential = $web_authentication_detail
      ->getUserCredential();
    $this
      ->assertInstanceOf("\\NicholasCreativeMedia\\FedExPHP\\Structs\\WebAuthenticationCredential", $user_credential);
    $this
      ->assertEquals('testkey', $user_credential
      ->getKey());
    $this
      ->assertEquals('testpass', $user_credential
      ->getPassword());
  }

  /**
   * @covers ::getRateService
   */
  public function testRateService() {
    $rate_service = $this->request
      ->getRateService($this->configuration);
    $this
      ->assertInstanceOf("\\NicholasCreativeMedia\\FedExPHP\\Services\\RateService", $rate_service);

    /** @var \NicholasCreativeMedia\FedExPHP\Structs\VersionId $version */
    $version = $rate_service->version;
    $this
      ->assertInstanceOf("\\NicholasCreativeMedia\\FedExPHP\\Structs\\VersionId", $version);
    $this
      ->assertEquals(static::RATE_SERVICE_SERVICE_ID, $version
      ->getServiceId());
    $this
      ->assertEquals(static::RATE_SERVICE_MAJOR_VERSION, $version
      ->getMajor());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FedExRequestTest::$configuration protected property A sample configuration to use.
FedExRequestTest::$request protected property A FedExRequest object to test.
FedExRequestTest::RATE_SERVICE_MAJOR_VERSION constant
FedExRequestTest::RATE_SERVICE_SERVICE_ID constant
FedExRequestTest::testRateRequest public function @covers ::getRateRequest
FedExRequestTest::testRateService public function @covers ::getRateService
FedExUnitTestBase::setUp protected function Overrides UnitTestCase::setUp
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.