Test case for the flash message seems to work

This commit is contained in:
Dave Smith-Hayes 2024-11-25 22:08:28 -05:00
parent 7b12f10989
commit b4bc66d288
4 changed files with 14 additions and 8 deletions

View File

@ -6,7 +6,6 @@ use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig; use Slim\Views\Twig;
use Slim\Routing\RouteContext; use Slim\Routing\RouteContext;
use Odan\Session\SessionInterface;
abstract class Controller abstract class Controller
{ {

View File

@ -17,6 +17,7 @@ class Middlewares
{ {
/** /**
* @param App $app The Slim application * @param App $app The Slim application
* @return void
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws LoaderError * @throws LoaderError

View File

@ -1,17 +1,17 @@
{% for message in flash.get('success') %} {% for message in flash.get('success') %}
<div class="flash success"> <div class="flash success" role="alert">
{{ message }} {{ message }}
</div> </div>
{% endfor %} {% endfor %}
{% for message in flash.get('notice') %} {% for message in flash.get('notice') %}
<div class="flash notice"> <div class="flash notice" role="alert">
{{ message }} {{ message }}
</div> </div>
{% endfor %} {% endfor %}
{% for message in flash.get('error') %} {% for message in flash.get('error') %}
<div class="flash error"> <div class="flash error" role="alert">
{{ message }} {{ message }}
</div> </div>
{% endfor %} {% endfor %}

View File

@ -115,7 +115,7 @@ class ControllerTest extends TestCase
public function handle(): Response public function handle(): Response
{ {
$this->session->getFlash()->add("error", "Error message"); $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); $response = $app->handle($request);
$flash = $app->getContainer()->get(SessionInterface::class)->getFlash(); $flash = $app->getContainer()->get(SessionInterface::class)->getFlash();
$errorMessages = $flash->get('error');
$this->assertEquals('Error message', $errorMessages[0]); $body = $response->getBody();
$this->assertEquals(1, count($errorMessages)); $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));
} }
} }