public function USPSRateRequestTest::testSingleRate in Commerce USPS 8
Tests returning a single rate response.
See https://www.drupal.org/project/commerce_usps/issues/3064571
File
- tests/
src/ Unit/ USPSRateRequestTest.php, line 121
Class
- USPSRateRequestTest
- Class USPSRateRequestTest.
Namespace
Drupal\Tests\commerce_usps\UnitCode
public function testSingleRate() {
$this
->setConfig([
'services' => [
9,
],
]);
$config = $this
->getConfig();
$shipment = $this
->mockShipment([], [
'length' => 30,
'width' => 20,
'height' => 20,
]);
$shipping_method = $this
->prophesize(ShippingMethodInterface::class);
$shipping_method
->id()
->willReturn('123456789');
// Fetch rates from the USPS api.
$rates = $this->rateRequest
->getRates($shipment, $shipping_method
->reveal());
// Make sure the same number of rates requested
// is returned.
$this
->assertEquals(count($config['services']), count($rates));
/** @var \Drupal\commerce_shipping\ShippingRate $rate */
foreach ($rates as $rate) {
$this
->assertInstanceOf(ShippingRate::class, $rate);
$this
->assertNotEmpty($rate
->getAmount()
->getNumber());
}
}