Skip to content

Add Plan Service#4

Merged
killianherbunot merged 1 commit intomasterfrom
add_plan_service
Oct 24, 2016
Merged

Add Plan Service#4
killianherbunot merged 1 commit intomasterfrom
add_plan_service

Conversation

@killianherbunot
Copy link
Contributor

No description provided.

@killianherbunot killianherbunot force-pushed the add_plan_service branch 3 times, most recently from 789f6b6 to faa20e0 Compare October 20, 2016 10:14
*
* @return integer
*/
public function recuperate($personId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to 'findAllByPersonId'

/**
* @param integer $personId
*
* @return integer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Plan[]

/**
* {@inheritdoc}
*/
public function pickUp($personId)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getPlans

*
* @return integer
*/
public function pickUp($personId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getPlans

/**
* @param $personId
*
* @return integer

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Plan[]

$jsonResult = $this->apiClient->get(self::RESOURCE_NAME.'/'.$personId.'/plans');
$result = json_decode($jsonResult, true);

return $result;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build array of Plan object and put the data inside and then return the array of plan

{
/**
* @var int
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as before (ApiClientMock)

/**
* {@inheritdoc}
*/
public function recuperate($planId)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the signature attribute is personId

public function get($resource)
{
self::$resource = $resource;
self::$config = [];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@coveralls
Copy link

coveralls commented Oct 21, 2016

Coverage Status

Coverage decreased (-0.4%) to 99.58% when pulling 2580406 on add_plan_service into 0663633 on master.

private $plan;

/**
* @return PlanBuilder

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inheritdoc

}

/**
* @return Plan

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inheritdoc

/**
* {@inheritdoc}
*/
public function withCreatedAt(\DateTime $createdAt)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= null

/**
* {@inheritdoc}
*/
public function withStartDate(\DateTime $startDate)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= null

public function jsonSerialize()
{
return [
[

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return just this array

{
self::$id = null;
self::$response = null;
self::$params = null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= empty array


public function __construct()
{
self::$plans = new PlanStub1();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

*/
class PlanStub1 extends PlanImpl
{
const ID = 1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alphabetic order

*/
public static $params;

public function __construct()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are a problem somewhere because you compare an array of plan with a single plan. This test shouldn't be green

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in the set up

@killianherbunot killianherbunot force-pushed the add_plan_service branch 2 times, most recently from c4a1e78 to d33e41e Compare October 24, 2016 12:37
public function withStartDate(\DateTime $startDate = null);

/**
* @param $type

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type hint is missing everywhere

*/
private $apiClient;

/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer interface instead of implementation

public static $plans;

public function __construct()
public function __construct(array $plan = [])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plans because you need several plan

* @param Plan[] $expected
* @param Plan[] $actual
*/
protected function assertPlan($expected, $actual)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()]]));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[PlanStub1::ID => new PlanStub1()]


$count = count($plans);
for ($i = 0; $i < $count; ++$i) {
$this->assertPlan(PlanGatewayMock::$plans[$i], $plans[$i]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()]));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()]

@coveralls
Copy link

coveralls commented Oct 24, 2016

Coverage Status

Coverage decreased (-0.4%) to 99.578% when pulling 81c127f on add_plan_service into 0663633 on master.

{
$plans = [];
foreach ($result['plans'] as $plan) {
$plans[] = $planBuilder

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now you planBuilder is a class property so you can call it directly here and don't have to call in method

@coveralls
Copy link

coveralls commented Oct 24, 2016

Coverage Status

Coverage decreased (-0.4%) to 99.578% when pulling 469d688 on add_plan_service into 0663633 on master.

@coveralls
Copy link

coveralls commented Oct 24, 2016

Coverage Status

Coverage decreased (-0.4%) to 99.578% when pulling fb9dbd9 on add_plan_service into 0663633 on master.

@killianherbunot killianherbunot merged commit f14418b into master Oct 24, 2016
@killianherbunot killianherbunot deleted the add_plan_service branch October 26, 2016 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants