slovocast/app/tests/Controller/User/RegisterUserActionTest.php

70 lines
2.2 KiB
PHP

<?php
namespace Slovocast\Tests\Controller\User;
use Slovocast\Tests\TestCase;
use Slovocast\Domain\Repository\UserRepositoryInterface;
use Slovocast\Domain\Entity\User;
class RegisterUserActionTest extends TestCase
{
protected function getUser(): User
{
return User::fromArray([
'email' => 'dave@slovocast.com',
'name' => 'Dave SH',
'password' => 'hashed_password'
]);
}
public function testSuccessfulRegistration(): void
{
$user = $this->getUser();
$prophecy = $this->getProphet()
->prophesize(UserRepositoryInterface::class);
$prophecy->save($user)->willReturn(true);
$app = $this->getAppInstance();
/** @var \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(200, $response->getStatusCode());
}
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());
}
}