-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace EsteIt\ShippingCalculator\Tests\CalculatorHandler\Dhl; | ||
|
||
use EsteIt\ShippingCalculator\CalculatorHandler\Dhl\ZoneCalculator; | ||
|
||
/** | ||
* @group unit | ||
*/ | ||
class ZoneCalculatorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected $fixtures; | ||
/** | ||
* @var ZoneCalculator | ||
*/ | ||
protected $zoneCalculator; | ||
|
||
public function setUp() | ||
{ | ||
$this->fixtures = null; | ||
|
||
$zoneCalculator = new ZoneCalculator([ | ||
'name' => 1, | ||
'overweight_rate_factor' => 10, | ||
'weight_prices' => [ | ||
['weight' => 1, 'price' => 31.3], | ||
['weight' => 2, 'price' => 34.90], | ||
['weight' => 3, 'price' => 38.45], | ||
['weight' => 4, 'price' => 42.00], | ||
['weight' => 5, 'price' => 45.55], | ||
['weight' => 6, 'price' => 48.84], | ||
['weight' => 7, 'price' => 52.15], | ||
['weight' => 8, 'price' => 55.44], | ||
['weight' => 9, 'price' => 58.73], | ||
['weight' => 10,'price' => 62.03] | ||
], | ||
]); | ||
|
||
$this->zoneCalculator = $zoneCalculator; | ||
} | ||
|
||
/** | ||
* @dataProvider provideCalculate | ||
*/ | ||
public function testCalculate($weight, $expectedPrice) | ||
{ | ||
$this->assertEquals($expectedPrice, $this->zoneCalculator->calculate($weight)); | ||
} | ||
|
||
/** | ||
* @dataProvider provideCalculateException | ||
*/ | ||
public function testGetPriceException($exceptionClass, $exceptionMessage, $weight) | ||
{ | ||
$this->setExpectedException($exceptionClass, $exceptionMessage); | ||
|
||
$zoneCalculator = new ZoneCalculator([ | ||
'name' => 1, | ||
'weight_prices' => [], | ||
]); | ||
$zoneCalculator->calculate($weight); | ||
} | ||
|
||
public function provideCalculate() | ||
{ | ||
return [ | ||
[0.5, 31.3], | ||
[4, 42.00], | ||
[4.5, 45.55], | ||
[10, 62.03], | ||
[20, 200], | ||
[20.5, 210], | ||
]; | ||
} | ||
|
||
public function provideCalculateException() | ||
{ | ||
return [ | ||
[ | ||
'EsteIt\ShippingCalculator\Exception\InvalidWeightException', | ||
'Weight should be a scalar value.', | ||
array(), | ||
], | ||
[ | ||
'EsteIt\ShippingCalculator\Exception\InvalidWeightException', | ||
'Can not calculate shipping for this weight.', | ||
100, | ||
], | ||
[ | ||
'EsteIt\ShippingCalculator\Exception\InvalidWeightException', | ||
'Weight should be greater than zero.', | ||
-10, | ||
], | ||
]; | ||
} | ||
} |