Skip to content

Commit

Permalink
Fixed composer to work with packagist. Fixed risky tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Isaacs committed Dec 12, 2019
1 parent 8d1cd60 commit 8a4a7eb
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 24 deletions.
6 changes: 6 additions & 0 deletions .idea/runConfigurations/All_Unit_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"extra": {
"branch-alias": {
"dev-master": "1.0.0"
"dev-master": "1.0.x-dev"
}
},
"require-dev": {
Expand Down
20 changes: 13 additions & 7 deletions src/RateAdapter.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace pdt256\Shipping;

use Exception;

abstract class RateAdapter
{
protected $isProduction;
Expand All @@ -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();

Expand Down Expand Up @@ -71,17 +74,20 @@ public function getShipment()
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()
Expand All @@ -93,9 +99,9 @@ public function getRates()
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());
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,33 +108,39 @@ protected function validatePackage(Package $package, RateAdapter $adapter)
->addPackage($package);
$adapter->setShipment($shipment);
$adapter->getRates();

$this->assertEquals($shipment, $adapter->getShipment());
}

public function testNormalUSPS()
{
$this->validatePackage($this->getNormalPackage(), $this->getUSPSAdapter());
}

/**
* @expectedException \LogicException
*/
public function testNoHeightPackageUSPS()
{
$this->validatePackage($this->getNoHeightPackage(), $this->getUSPSAdapter());
}

/**
* @expectedException \LogicException
*/
public function testNoLengthPackageUSPS()
{
$this->validatePackage($this->getNoLengthPackage(), $this->getUSPSAdapter());
}

/**
* @expectedException \LogicException
*/
public function testNoWidthPackageUSPS()
{
$this->validatePackage($this->getNoWidthPackage(), $this->getUSPSAdapter());
}

/**
* @expectedException \LogicException
*/
Expand All @@ -148,27 +154,31 @@ public function testNormalUPS()
{
$this->validatePackage($this->getNormalPackage(), $this->getUPSAdapter());
}

/**
* @expectedException \LogicException
*/
public function testNoHeightPackageUPS()
{
$this->validatePackage($this->getNoHeightPackage(), $this->getUPSAdapter());
}

/**
* @expectedException \LogicException
*/
public function testNoLengthPackageUPS()
{
$this->validatePackage($this->getNoLengthPackage(), $this->getUPSAdapter());
}

/**
* @expectedException \LogicException
*/
public function testNoWidthPackageUPS()
{
$this->validatePackage($this->getNoWidthPackage(), $this->getUPSAdapter());
}

/**
* @expectedException \LogicException
*/
Expand All @@ -182,27 +192,31 @@ public function testNormalFedex()
{
$this->validatePackage($this->getNormalPackage(), $this->getFedexAdapter());
}

/**
* @expectedException \LogicException
*/
public function testNoHeightPackageFedex()
{
$this->validatePackage($this->getNoHeightPackage(), $this->getFedexAdapter());
}

/**
* @expectedException \LogicException
*/
public function testNoLengthPackageFedex()
{
$this->validatePackage($this->getNoLengthPackage(), $this->getFedexAdapter());
}

/**
* @expectedException \LogicException
*/
public function testNoWidthPackageFedex()
{
$this->validatePackage($this->getNoWidthPackage(), $this->getFedexAdapter());
}

/**
* @expectedException \LogicException
*/
Expand Down
15 changes: 0 additions & 15 deletions tests/RateAdapterTest.php

This file was deleted.

4 changes: 3 additions & 1 deletion tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace pdt256\Shipping;

use PHPUnit\Framework\TestCase;
use stdClass;

class ValidatorTest extends TestCase
{
Expand All @@ -17,8 +18,9 @@ public function testNotNull()
{
Validator::checkIfNull('XXX', 'notNullValue');
Validator::checkIfNull([], 'notNullValue');
Validator::checkIfNull(new \stdClass(), 'notNullValue');
Validator::checkIfNull(new stdClass(), 'notNullValue');
Validator::checkIfNull(function () {
}, 'notNullValue');
$this->assertTrue(true);
}
}

0 comments on commit 8a4a7eb

Please sign in to comment.