Conversation
789f6b6 to
faa20e0
Compare
src/Gateways/PlanGateway.php
Outdated
| * | ||
| * @return integer | ||
| */ | ||
| public function recuperate($personId); |
src/Gateways/PlanGateway.php
Outdated
| /** | ||
| * @param integer $personId | ||
| * | ||
| * @return integer |
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function pickUp($personId) |
src/Services/PlanService.php
Outdated
| * | ||
| * @return integer | ||
| */ | ||
| public function pickUp($personId); |
src/Services/PlanService.php
Outdated
| /** | ||
| * @param $personId | ||
| * | ||
| * @return integer |
src/Repository/PlanRepository.php
Outdated
| $jsonResult = $this->apiClient->get(self::RESOURCE_NAME.'/'.$personId.'/plans'); | ||
| $result = json_decode($jsonResult, true); | ||
|
|
||
| return $result; |
There was a problem hiding this comment.
build array of Plan object and put the data inside and then return the array of plan
| { | ||
| /** | ||
| * @var int | ||
| */ |
There was a problem hiding this comment.
the default value in a mock must be null because you should manage what id should be in the unit test
then you should put self::$id = null inside the controller so that each test construct separatly the mock and reset id to null
| /** | ||
| * @var int | ||
| */ | ||
| public static $id = 1222; |
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function recuperate($planId) |
There was a problem hiding this comment.
I think the signature attribute is personId
| public function get($resource) | ||
| { | ||
| self::$resource = $resource; | ||
| self::$config = []; |
There was a problem hiding this comment.
it does not make any sense, because the config will be an empty array for each test so the test of this attribute is useless
src/Models/Impl/PlanBuilderImpl.php
Outdated
| private $plan; | ||
|
|
||
| /** | ||
| * @return PlanBuilder |
src/Models/Impl/PlanBuilderImpl.php
Outdated
| } | ||
|
|
||
| /** | ||
| * @return Plan |
src/Models/Impl/PlanBuilderImpl.php
Outdated
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function withCreatedAt(\DateTime $createdAt) |
src/Models/Impl/PlanBuilderImpl.php
Outdated
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function withStartDate(\DateTime $startDate) |
src/Models/Impl/PlanImpl.php
Outdated
| public function jsonSerialize() | ||
| { | ||
| return [ | ||
| [ |
| { | ||
| self::$id = null; | ||
| self::$response = null; | ||
| self::$params = null; |
|
|
||
| public function __construct() | ||
| { | ||
| self::$plans = new PlanStub1(); |
There was a problem hiding this comment.
let the possibility to the users of the library to create their own stub. so ask an array of plan in the constructor signature :
/**
* param Plan[] $plans
*/
public function __construct(array $plans = [])
{
self::$plans = $plans;
}
tests/Doubles/Models/PlanStub1.php
Outdated
| */ | ||
| class PlanStub1 extends PlanImpl | ||
| { | ||
| const ID = 1; |
| */ | ||
| public static $params; | ||
|
|
||
| public function __construct() |
There was a problem hiding this comment.
need it to initialize the static attribute with a default value (null or empty array)
| public function getPlans_ReturnId() | ||
| { | ||
| $plan = $this->service->getPlans(PersonStub1::ID); | ||
| $this->assertPlan(PlanGatewayMock::$plans, $plan); |
There was a problem hiding this comment.
there are a problem somewhere because you compare an array of plan with a single plan. This test shouldn't be green
There was a problem hiding this comment.
done in the set up
c4a1e78 to
d33e41e
Compare
src/Models/PlanBuilder.php
Outdated
| public function withStartDate(\DateTime $startDate = null); | ||
|
|
||
| /** | ||
| * @param $type |
| */ | ||
| private $apiClient; | ||
|
|
||
| /** |
There was a problem hiding this comment.
prefer interface instead of implementation
| public static $plans; | ||
|
|
||
| public function __construct() | ||
| public function __construct(array $plan = []) |
| * @param Plan[] $expected | ||
| * @param Plan[] $actual | ||
| */ | ||
| protected function assertPlan($expected, $actual) |
There was a problem hiding this comment.
not at all it was good, it was where you used it you need to change the ways
| { | ||
| $this->service = new PlanServiceImpl(); | ||
| $this->service->setPlanGateway(new PlanGatewayMock()); | ||
| $this->service->setPlanGateway(new PlanGatewayMock([[new PlanStub1()]])); |
|
|
||
| $count = count($plans); | ||
| for ($i = 0; $i < $count; ++$i) { | ||
| $this->assertPlan(PlanGatewayMock::$plans[$i], $plans[$i]); |
There was a problem hiding this comment.
cf: GetUsersTest L43
$i = 0;
foreach ($plans as $plan) {
$planStub = '\path\to\PlanStub'.++$i;
$this->assertPlan(new $planStub(), $plan);
}| { | ||
| $this->service = new PlanServiceImpl(); | ||
| $this->service->setPlanGateway(new PlanGatewayMock([[new PlanStub1()]])); | ||
| $this->service->setPlanGateway(new PlanGatewayMock([new PlanStub1()])); |
There was a problem hiding this comment.
you need to force the array key to handle it because api or database will never start with a key = 0
[planStub1::Id => new PlanStub1()]
src/Repository/PlanRepository.php
Outdated
| { | ||
| $plans = []; | ||
| foreach ($result['plans'] as $plan) { | ||
| $plans[] = $planBuilder |
There was a problem hiding this comment.
now you planBuilder is a class property so you can call it directly here and don't have to call in method
469d688 to
fb9dbd9
Compare
No description provided.