Browse Source

Fixed composer to work with packagist. Fixed risky tests.

pull/21/head 1.0.1
Jamie Isaacs 2 years ago
parent
commit
8a4a7ebbdf
  1. 6
      .idea/runConfigurations/All_Unit_Tests.xml
  2. 2
      composer.json
  3. 20
      src/RateAdapter.php
  4. 14
      tests/PackageDimensionsValidationTrait.php
  5. 15
      tests/RateAdapterTest.php
  6. 4
      tests/ValidatorTest.php

6
.idea/runConfigurations/All_Unit_Tests.xml

@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="All Unit Tests" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
<TestRunner class="pdt256\Shipping\PackageDimensionsValidationTrait" configuration_file="$PROJECT_DIR$/phpunit.xml" directory="$PROJECT_DIR$" file="$PROJECT_DIR$/tests/PackageDimensionsValidationTrait.php" scope="XML" use_alternative_configuration_file="true" />
<method v="2" />
</configuration>
</component>

2
composer.json

@ -11,7 +11,7 @@
],
"extra": {
"branch-alias": {
"dev-master": "1.0.0"
"dev-master": "1.0.x-dev"
}
},
"require-dev": {

20
src/RateAdapter.php

@ -1,8 +1,6 @@
<?php
namespace pdt256\Shipping;
use Exception;
abstract class RateAdapter
{
protected $isProduction;
@ -18,20 +16,25 @@ abstract class RateAdapter
/**
* Make sure all necessary fields are set
* @return self
*/
abstract protected function validate();
/**
* Prepare XML
* @return self
*/
abstract protected function prepare();
/**
* Curl Request
* @return self
*/
abstract protected function execute();
/**
* Convert to shipping rates array
* @return self
*/
abstract protected function process();
@ -71,17 +74,20 @@ abstract class RateAdapter
return $this->shipment;
}
public function setIsProduction($isProduction)
public function setIsProduction($isProduction): void
{
$this->isProduction = $isProduction;
}
public function getIsProduction()
public function getIsProduction(): bool
{
return $this->isProduction;
}
public function getRates()
/**
* @return Quote[]
*/
public function getRates(): array
{
$this
->validate()
@ -93,9 +99,9 @@ abstract class RateAdapter
return array_values($this->rates);
}
protected function sortByCost()
protected function sortByCost(): void
{
uasort($this->rates, function ($a, $b) {
uasort($this->rates, static function (Quote $a, Quote $b) {
return ($a->getCost() > $b->getCost());
});
}

14
tests/PackageDimensionsTest.php → tests/PackageDimensionsValidationTrait.php

@ -108,12 +108,15 @@ class PackageDimensionsValidationTrait extends TestCase
->addPackage($package);
$adapter->setShipment($shipment);
$adapter->getRates();
$this->assertEquals($shipment, $adapter->getShipment());
}
public function testNormalUSPS()
{
$this->validatePackage($this->getNormalPackage(), $this->getUSPSAdapter());
}
/**
* @expectedException \LogicException
*/
@ -121,6 +124,7 @@ class PackageDimensionsValidationTrait extends TestCase
{
$this->validatePackage($this->getNoHeightPackage(), $this->getUSPSAdapter());
}
/**
* @expectedException \LogicException
*/
@ -128,6 +132,7 @@ class PackageDimensionsValidationTrait extends TestCase
{
$this->validatePackage($this->getNoLengthPackage(), $this->getUSPSAdapter());
}
/**
* @expectedException \LogicException
*/
@ -135,6 +140,7 @@ class PackageDimensionsValidationTrait extends TestCase
{
$this->validatePackage($this->getNoWidthPackage(), $this->getUSPSAdapter());
}
/**
* @expectedException \LogicException
*/
@ -148,6 +154,7 @@ class PackageDimensionsValidationTrait extends TestCase
{
$this->validatePackage($this->getNormalPackage(), $this->getUPSAdapter());
}
/**
* @expectedException \LogicException
*/
@ -155,6 +162,7 @@ class PackageDimensionsValidationTrait extends TestCase
{
$this->validatePackage($this->getNoHeightPackage(), $this->getUPSAdapter());
}
/**
* @expectedException \LogicException
*/
@ -162,6 +170,7 @@ class PackageDimensionsValidationTrait extends TestCase
{
$this->validatePackage($this->getNoLengthPackage(), $this->getUPSAdapter());
}
/**
* @expectedException \LogicException
*/
@ -169,6 +178,7 @@ class PackageDimensionsValidationTrait extends TestCase
{
$this->validatePackage($this->getNoWidthPackage(), $this->getUPSAdapter());
}
/**
* @expectedException \LogicException
*/
@ -182,6 +192,7 @@ class PackageDimensionsValidationTrait extends TestCase
{
$this->validatePackage($this->getNormalPackage(), $this->getFedexAdapter());
}
/**
* @expectedException \LogicException
*/
@ -189,6 +200,7 @@ class PackageDimensionsValidationTrait extends TestCase
{
$this->validatePackage($this->getNoHeightPackage(), $this->getFedexAdapter());
}
/**
* @expectedException \LogicException
*/
@ -196,6 +208,7 @@ class PackageDimensionsValidationTrait extends TestCase
{
$this->validatePackage($this->getNoLengthPackage(), $this->getFedexAdapter());
}
/**
* @expectedException \LogicException
*/
@ -203,6 +216,7 @@ class PackageDimensionsValidationTrait extends TestCase
{
$this->validatePackage($this->getNoWidthPackage(), $this->getFedexAdapter());
}
/**
* @expectedException \LogicException
*/

15
tests/RateAdapterTest.php

@ -1,15 +0,0 @@
<?php
namespace pdt256\Shipping;
use PHPUnit\Framework\TestCase;
class RateAdapterTest extends TestCase
{
public function testCreate()
{
/* @var RateAdapter $mock */
$mock = $this->getMockForAbstractClass('pdt256\Shipping\RateAdapter');
$mockRequestAdapter = $this->getMockForAbstractClass('pdt256\Shipping\RateRequest\Adapter');
$mock->setRequestAdapter($mockRequestAdapter);
}
}

4
tests/ValidatorTest.php

@ -2,6 +2,7 @@
namespace pdt256\Shipping;
use PHPUnit\Framework\TestCase;
use stdClass;
class ValidatorTest extends TestCase
{
@ -17,8 +18,9 @@ class ValidatorTest extends TestCase
{
Validator::checkIfNull('XXX', 'notNullValue');
Validator::checkIfNull([], 'notNullValue');
Validator::checkIfNull(new \stdClass(), 'notNullValue');
Validator::checkIfNull(new stdClass(), 'notNullValue');
Validator::checkIfNull(function () {
}, 'notNullValue');
$this->assertTrue(true);
}
}
Loading…
Cancel
Save