Test creating a new user.

This commit is contained in:
Dave Smith-Hayes 2024-05-29 22:56:19 -04:00
parent 5aa3d215ab
commit ec3af79323
4 changed files with 40 additions and 5 deletions

View File

@ -2,7 +2,7 @@
namespace Slovocast\Domain\Repository; namespace Slovocast\Domain\Repository;
use Slovocast\Domain\Model\User; use Slovocast\Domain\Entity\User;
interface UserRepositoryInterface interface UserRepositoryInterface
{ {

View File

@ -1,6 +1,6 @@
{% extends 'layouts/skeleton' %} {% extends 'layouts/skeleton.twig' %}
{% block "content" %} {% block content %}
<div> <div>
<form action="/users/register" method="post"> <form action="/users/register" method="post">
<div> <div>

View File

@ -3,12 +3,43 @@
namespace Slovocast\Tests\Controller\User; namespace Slovocast\Tests\Controller\User;
use Slovocast\Tests\TestCase; use Slovocast\Tests\TestCase;
use Slovocast\Domain\Repository\UserRepositoryInterface;
use Slovocast\Domain\Entity\User;
class RegisterUserActionTest extends TestCase 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 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 public function testFailingRegistration(): void

View File

@ -3,7 +3,7 @@
namespace Slovocast\Tests; namespace Slovocast\Tests;
use PHPUnit\Framework\TestCase as PHPUnit_TestCase; use PHPUnit\Framework\TestCase as PHPUnit_TestCase;
use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophet;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\App; use Slim\App;
use Slim\Psr7\Factory\StreamFactory; use Slim\Psr7\Factory\StreamFactory;
@ -18,7 +18,6 @@ use Slovocast\Bootstrap;
*/ */
class TestCase extends PHPUnit_TestCase class TestCase extends PHPUnit_TestCase
{ {
use ProphecyTrait;
/** /**
* Generate an instance of the Application * Generate an instance of the Application
*/ */
@ -59,4 +58,9 @@ class TestCase extends PHPUnit_TestCase
$stream $stream
); );
} }
public function getProphet(): Prophet
{
return new Prophet();
}
} }