Rewrite the test, which works, yet doesn't work when running the actual site?

This commit is contained in:
Dave Smith-Hayes 2024-11-29 14:50:27 -05:00
parent d782bd9081
commit b9b62c2d5c
5 changed files with 16 additions and 9 deletions

View File

@ -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)
);
},
/**

View File

@ -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);
}
}

View File

@ -27,9 +27,7 @@ class Middlewares
/** @var ContainerInterface $container */
$container = $app->getContainer();
/**
* @var Configuration $config
*/
/** @var Configuration $config */
$config = $container->get('config');
/**

View File

@ -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);

View File

@ -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);