Fix the warnings on the test case.

This commit is contained in:
Dave Smith-Hayes 2024-06-02 21:26:10 -04:00
parent ec3af79323
commit c5feb240c3
4 changed files with 29 additions and 9 deletions

View File

@ -30,6 +30,6 @@
} }
}, },
"scripts": { "scripts": {
"test": "./vendor/bin/phpunit tests" "test": "./vendor/bin/phpunit tests --display-warnings"
} }
} }

View File

@ -29,12 +29,12 @@ class RegisterUserAction extends Controller
'password' => $requestData['password'], 'password' => $requestData['password'],
]); ]);
try { $result = $this->userRepository->save($user);
$this->userRepository->save($user);
if ($result) {
return $this->render('user/success.twig'); return $this->render('user/success.twig');
} catch (\Exception $e) { } else {
$response = $this->render('user/register.twig'); return $this->render('user/register.twig')->withStatus(400);
return $response->withStatus(400);
} }
} }

View File

@ -55,15 +55,15 @@ class User
{ {
$user = new self($props['email'], $props['password'], $props['name']); $user = new self($props['email'], $props['password'], $props['name']);
if ($props['id']) { if (array_key_exists('id', $props)) {
$user->setId($props['id']); $user->setId($props['id']);
} }
if ($props['createdAt']) { if (array_key_exists('createdAt', $props)) {
$user->setCreatedAt($props['createdAt']); $user->setCreatedAt($props['createdAt']);
} }
if ($props['updatedAt']) { if (array_key_exists('updatedAt', $props)) {
$user->setUpdatedAt($props['updatedAt']); $user->setUpdatedAt($props['updatedAt']);
} }

View File

@ -44,6 +44,26 @@ class RegisterUserActionTest extends TestCase
public function testFailingRegistration(): void public function testFailingRegistration(): void
{ {
$user = $this->getUser();
$prophecy = $this->getProphet()
->prophesize(UserRepositoryInterface::class);
$prophecy->save($user)->willReturn(false);
$app = $this->getAppInstance();
/** @var $container \DI\Container */
$container = $app->getContainer();
$container->set(UserRepositoryInterface::class, $prophecy->reveal());
$request = $this->createRequest('POST', '/users/register')
->withParsedBody([
'email' => 'dave@slovocast.com',
'name' => 'Dave SH',
'password' => 'hashed_password',
'checked_password' => 'hashed_password'
]);
$response = $app->handle($request);
$this->assertEquals(400, $response->getStatusCode());
} }
} }