Fixed composer to work with packagist. Fixed risky tests.

pull/21/head 1.0.1
Jamie Isaacs 4 years ago
parent 8d1cd60d1a
commit 8a4a7ebbdf

@ -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>

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

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

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

@ -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);
}
}

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

Loading…
Cancel
Save