Skip to content

Commit

Permalink
lets see if it passes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drcat committed Mar 23, 2017
1 parent 359c494 commit 40e7d3b
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Entities/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use IteratorAggregate;
use Rebilly\Entities\Coupons\Coupon;
use Rebilly\Entities\Coupons\Redemption;
use Rebilly\Entities\Shipping\ShippingZone;
use Rebilly\Rest\Collection;

/**
Expand Down
161 changes: 161 additions & 0 deletions src/Entities/Shipping/Rate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php
/**
* This file is part of the PHP Rebilly API package.
*
* (c) 2016 Rebilly SRL
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace Rebilly\Entities\Shipping;

use DomainException;
use Rebilly\Rest\Resource;

/**
* Class Rate.
*/
class Rate extends Resource
{
/*
* @var string
*/
private $name;

/*
* @var float
*/
private $minOrderSubtotal;

/*
* @var float
*/
private $maxOrderSubtotal;

/*
* @var float
*/
private $price;

/*
* @var string
*/
private $currency;

const MSG_REQUIRED_NAME = 'Name can not be blank.';
const MSG_REQUIRED_PRICE = 'Price can not be blank.';
const MSG_REQUIRED_CURRENCY = 'Currency can not be blank.';

/**
* {@inheritdoc}
*/
public function __construct(array $data = [])
{
parent::__construct($data);
}

/**
* @param array $data
*
* @return Rate
*/
public static function createFromData(array $data)
{
if (!isset($data['name'])) {
throw new DomainException(self::MSG_REQUIRED_NAME);
}

if (!isset($data['price'])) {
throw new DomainException(self::MSG_REQUIRED_NAME);
}

if (!isset($data['currency'])) {
throw new DomainException(self::MSG_REQUIRED_CURRENCY);
}

$rate = new Rate($data);

return $rate;
}

/**
* @return mixed
*/
public function getName()
{
return $this->name;
}

/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
}

/**
* @return mixed
*/
public function getMinOrderSubtotal()
{
return $this->minOrderSubtotal;
}

/**
* @param mixed $minOrderSubtotal
*/
public function setMinOrderSubtotal($minOrderSubtotal)
{
$this->minOrderSubtotal = $minOrderSubtotal;
}

/**
* @return mixed
*/
public function getMaxOrderSubtotal()
{
return $this->maxOrderSubtotal;
}

/**
* @param mixed $maxOrderSubtotal
*/
public function setMaxOrderSubtotal($maxOrderSubtotal)
{
$this->maxOrderSubtotal = $maxOrderSubtotal;
}

/**
* @return mixed
*/
public function getPrice()
{
return $this->price;
}

/**
* @param mixed $price
*/
public function setPrice($price)
{
$this->price = $price;
}

/**
* @return mixed
*/
public function getCurrency()
{
return $this->currency;
}

/**
* @param mixed $currency
*/
public function setCurrency($currency)
{
$this->currency = $currency;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
* file that was distributed with this source code.
*/

namespace Rebilly\Entities;
namespace Rebilly\Entities\Shipping;

use DomainException;
use Rebilly\Rest\Entity;

/**
Expand All @@ -29,6 +30,8 @@
*/
final class ShippingZone extends Entity
{
const MSG_RATES_WRONG = "Rates must be an array of Rate resource";

/**
* @return string
*/
Expand Down Expand Up @@ -64,6 +67,8 @@ public function getCountries()
}

/**
* @param []string $value
*
* @return $this
*/
public function setCountries($value)
Expand All @@ -80,10 +85,16 @@ public function getRates()
}

/**
* @param []Rate $value
*
* @return $this
*/
public function setRates($value)
{
if (!is_array($value)) {
throw new DomainException(self::MSG_RATES_WRONG);
}

return $this->setAttribute('rates', $value);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Services/ShippingZoneService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use ArrayObject;
use JsonSerializable;
use Rebilly\Entities\ShippingZone;
use Rebilly\Entities\Shipping\ShippingZone;
use Rebilly\Http\Exception\NotFoundException;
use Rebilly\Http\Exception\UnprocessableEntityException;
use Rebilly\Paginator;
Expand Down
25 changes: 24 additions & 1 deletion tests/Api/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,8 @@ public function provideEntityClasses()
[Entities\Coupons\Coupon::class],
[Entities\Coupons\Redemption::class],
[Entities\ValuesList::class],
[Entities\Shipping\ShippingZone::class],
[Entities\Shipping\Rate::class],
];
}

Expand Down Expand Up @@ -948,7 +950,7 @@ public function provideServiceClasses()
[
'shippingZones',
Services\ShippingZoneService::class,
Entities\ShippingZone::class,
Entities\Shipping\ShippingZone::class,
],
];
}
Expand Down Expand Up @@ -1283,6 +1285,27 @@ private function getFakeValue($attribute, $class)
$faker->word,
$faker->numberBetween(1, 100),
];
case 'minOrderSubtotal':
return $faker->numberBetween(5, 7);
case 'maxOrderSubtotal':
return $faker->numberBetween(8, 10);
case 'price':
return $faker->numberBetween(2, 3);
case 'countries':
return ['US'];
case 'isDefault':
return false;
case 'rates':
return [
Entities\Shipping\Rate::createFromData([
'name' => 'test',
'minOrderSubtotal'=> 4,
'maxOrderSubtotal'=> 10,
'price'=> 5,
'default' => false,
'currency'=> 'USD',
]),
];
case 'cancelCategory':
return $faker->randomElement(Entities\SubscriptionCancel::cancelCategories());
case 'canceledBy':
Expand Down

0 comments on commit 40e7d3b

Please sign in to comment.