diff --git a/app/src/Bootstrap.php b/app/src/Bootstrap.php index 8093884..8215e6e 100644 --- a/app/src/Bootstrap.php +++ b/app/src/Bootstrap.php @@ -114,7 +114,7 @@ class Bootstrap */ LoggerInterface::class => function() { $logger = new Logger("default"); - $logger->pushHandler(new StreamHandler('php://stdout', Level::Warning)); + $logger->pushHandler(new StreamHandler('php://stdout', Level::Info)); return $logger; }, @@ -132,7 +132,11 @@ class Bootstrap return $container->get(SessionInterface::class)->getFlash(); }, SessionMiddleware::class => function (ContainerInterface $container) { - return new SessionMiddleware($container->get(SessionInterface::class)); + return new SessionMiddleware( + $container->get(SessionManagerInterface::class), + $container->get(SessionInterface::class), + $container->get(LoggerInterface::class) + ); }, /** diff --git a/app/src/Middleware/SessionMiddleware.php b/app/src/Middleware/SessionMiddleware.php index 2f37e71..2bc1966 100644 --- a/app/src/Middleware/SessionMiddleware.php +++ b/app/src/Middleware/SessionMiddleware.php @@ -3,10 +3,12 @@ namespace Slovocast\Middleware; use Odan\Session\SessionManagerInterface; +use Odan\Session\SessionInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface as RequestHandler; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ResponseInterface as Response; +use Psr\Log\LoggerInterface; /** * Start a session on every single request, regardless. There may be a reason @@ -15,7 +17,9 @@ use Psr\Http\Message\ResponseInterface as Response; class SessionMiddleware implements MiddlewareInterface { public function __construct( - private SessionManagerInterface $sessionManager + private SessionManagerInterface $sessionManager, + private SessionInterface $session, + private LoggerInterface $logger ) { } public function process(Request $request, RequestHandler $handler): Response @@ -23,7 +27,7 @@ class SessionMiddleware implements MiddlewareInterface if (!$this->sessionManager->isStarted()) { $this->sessionManager->start(); } - + return $handler->handle($request); } } diff --git a/app/src/Middlewares.php b/app/src/Middlewares.php index 282923c..c8f1094 100644 --- a/app/src/Middlewares.php +++ b/app/src/Middlewares.php @@ -27,9 +27,7 @@ class Middlewares /** @var ContainerInterface $container */ $container = $app->getContainer(); - /** - * @var Configuration $config - */ + /** @var Configuration $config */ $config = $container->get('config'); /** diff --git a/app/tests/Controller/ControllerTest.php b/app/tests/Controller/ControllerTest.php index 5bdec76..af18adb 100644 --- a/app/tests/Controller/ControllerTest.php +++ b/app/tests/Controller/ControllerTest.php @@ -128,7 +128,8 @@ class ControllerTest extends TestCase $body = $response->getBody(); $body->read($body->getSize()); // the flash class is in the body for this test case - $this->assertTrue((bool) preg_match('/class\=\"flash/', $body)); + $this->assertTrue(str_contains($body, "flash")); + $this->assertTrue(str_contains($body, "Error message")); //$errorMessages = $flash->get('error'); //$this->assertNotEmpty($errorMessages); diff --git a/app/tests/Controller/User/RegisterUserActionTest.php b/app/tests/Controller/User/RegisterUserActionTest.php index d4b0df1..d7cba17 100644 --- a/app/tests/Controller/User/RegisterUserActionTest.php +++ b/app/tests/Controller/User/RegisterUserActionTest.php @@ -114,7 +114,7 @@ class RegisterUserActionTest extends TestCase $user = $this->getUser(); $app = $this->getAppInstance(); - /** @var $container \DI\Cotnainer */ + /** @var $container \DI\Container */ $container = $app->getContainer(); $userRepository = $this->prophesize(UserRepositoryInterface::class);