Test case for the flash message seems to work
This commit is contained in:
parent
7b12f10989
commit
b4bc66d288
@ -6,7 +6,6 @@ use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Slim\Views\Twig;
|
||||
use Slim\Routing\RouteContext;
|
||||
use Odan\Session\SessionInterface;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
|
@ -17,6 +17,7 @@ class Middlewares
|
||||
{
|
||||
/**
|
||||
* @param App $app The Slim application
|
||||
* @return void
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws LoaderError
|
||||
|
@ -1,17 +1,17 @@
|
||||
{% for message in flash.get('success') %}
|
||||
<div class="flash success">
|
||||
<div class="flash success" role="alert">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{% for message in flash.get('notice') %}
|
||||
<div class="flash notice">
|
||||
<div class="flash notice" role="alert">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{% for message in flash.get('error') %}
|
||||
<div class="flash error">
|
||||
<div class="flash error" role="alert">
|
||||
{{ message }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
@ -115,7 +115,7 @@ class ControllerTest extends TestCase
|
||||
public function handle(): Response
|
||||
{
|
||||
$this->session->getFlash()->add("error", "Error message");
|
||||
return $this->response;
|
||||
return $this->render('home.twig');
|
||||
}
|
||||
};
|
||||
|
||||
@ -124,8 +124,14 @@ class ControllerTest extends TestCase
|
||||
|
||||
$response = $app->handle($request);
|
||||
$flash = $app->getContainer()->get(SessionInterface::class)->getFlash();
|
||||
$errorMessages = $flash->get('error');
|
||||
$this->assertEquals('Error message', $errorMessages[0]);
|
||||
$this->assertEquals(1, count($errorMessages));
|
||||
|
||||
$body = $response->getBody();
|
||||
$body->read($body->getSize());
|
||||
$this->assertTrue((bool) preg_match('/class\=\"flash/', $body));
|
||||
|
||||
//$errorMessages = $flash->get('error');
|
||||
//$this->assertNotEmpty($errorMessages);
|
||||
//$this->assertEquals('Error message', $errorMessages[0]);
|
||||
//$this->assertEquals(1, count($errorMessages));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user