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": {
"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'],
]);
try {
$this->userRepository->save($user);
$result = $this->userRepository->save($user);
if ($result) {
return $this->render('user/success.twig');
} catch (\Exception $e) {
$response = $this->render('user/register.twig');
return $response->withStatus(400);
} else {
return $this->render('user/register.twig')->withStatus(400);
}
}

View File

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

View File

@ -44,6 +44,26 @@ class RegisterUserActionTest extends TestCase
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());
}
}