Test creating a new user.
This commit is contained in:
parent
5aa3d215ab
commit
ec3af79323
@ -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
|
||||||
{
|
{
|
||||||
|
@ -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>
|
||||||
|
@ -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
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user