Skip to content

Commit

Permalink
Fixing the customer birthday
Browse files Browse the repository at this point in the history
  • Loading branch information
mamazu committed Sep 21, 2019
1 parent 23f4a77 commit f010636
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
17 changes: 16 additions & 1 deletion spec/Command/Customer/UpdateCustomerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace spec\Sylius\ShopApiPlugin\Command\Customer;

use DateTimeImmutable;
use PhpSpec\ObjectBehavior;

final class UpdateCustomerSpec extends ObjectBehavior
Expand Down Expand Up @@ -43,7 +44,21 @@ function it_has_gender(): void

function it_has_birthday(): void
{
$this->birthday()->shouldReturn('2017-11-01');
$this->birthday()->shouldHaveType(DateTimeImmutable::class);
}

function it_has_no_birthday_if_not_provided(): void
{
$this->beConstructedWith('Sherlock',
'Holmes',
'sherlock@holmes.com',
null,
'm',
'091231512512',
true
);

$this->birthday()->shouldReturn(null);
}

function it_has_phone_number(): void
Expand Down
8 changes: 6 additions & 2 deletions src/Command/Customer/UpdateCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ public function email(): string
return $this->email;
}

public function birthday(): ?string
public function birthday(): ?\DateTimeImmutable
{
return $this->birthday;
if ($this->birthday === null) {
return null;
}

return new \DateTimeImmutable($this->birthday);
}

public function gender(): ?string
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/Customer/UpdateCustomerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __invoke(UpdateCustomer $command): void
$customer->setLastName($command->lastName());
$customer->setEmail($command->email());
$customer->setGender($command->gender());
$customer->setBirthday(new \DateTimeImmutable($command->birthday()));
$customer->setBirthday($command->birthday());
$customer->setPhoneNumber($command->phoneNumber());
$customer->setSubscribedToNewsletter($command->subscribedToNewsletter());

Expand Down
3 changes: 1 addition & 2 deletions src/Request/Customer/UpdateCustomerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Sylius\ShopApiPlugin\Request\Customer;

use DateTimeInterface;
use Sylius\ShopApiPlugin\Command\CommandInterface;
use Sylius\ShopApiPlugin\Command\Customer\UpdateCustomer;
use Sylius\ShopApiPlugin\Request\RequestInterface;
Expand All @@ -21,7 +20,7 @@ class UpdateCustomerRequest implements RequestInterface
/** @var string|null */
protected $email;

/** @var DateTimeInterface|null */
/** @var string|null */
protected $birthday;

/** @var string */
Expand Down

0 comments on commit f010636

Please sign in to comment.