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() { LoggerInterface::class => function() {
$logger = new Logger("default"); $logger = new Logger("default");
$logger->pushHandler(new StreamHandler('php://stdout', Level::Warning)); $logger->pushHandler(new StreamHandler('php://stdout', Level::Info));
return $logger; return $logger;
}, },
@ -132,7 +132,11 @@ class Bootstrap
return $container->get(SessionInterface::class)->getFlash(); return $container->get(SessionInterface::class)->getFlash();
}, },
SessionMiddleware::class => function (ContainerInterface $container) { 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; namespace Slovocast\Middleware;
use Odan\Session\SessionManagerInterface; use Odan\Session\SessionManagerInterface;
use Odan\Session\SessionInterface;
use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler; use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Log\LoggerInterface;
/** /**
* Start a session on every single request, regardless. There may be a reason * 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 class SessionMiddleware implements MiddlewareInterface
{ {
public function __construct( public function __construct(
private SessionManagerInterface $sessionManager private SessionManagerInterface $sessionManager,
private SessionInterface $session,
private LoggerInterface $logger
) { } ) { }
public function process(Request $request, RequestHandler $handler): Response public function process(Request $request, RequestHandler $handler): Response

View File

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

View File

@ -128,7 +128,8 @@ class ControllerTest extends TestCase
$body = $response->getBody(); $body = $response->getBody();
$body->read($body->getSize()); $body->read($body->getSize());
// the flash class is in the body for this test case // 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'); //$errorMessages = $flash->get('error');
//$this->assertNotEmpty($errorMessages); //$this->assertNotEmpty($errorMessages);

View File

@ -114,7 +114,7 @@ class RegisterUserActionTest extends TestCase
$user = $this->getUser(); $user = $this->getUser();
$app = $this->getAppInstance(); $app = $this->getAppInstance();
/** @var $container \DI\Cotnainer */ /** @var $container \DI\Container */
$container = $app->getContainer(); $container = $app->getContainer();
$userRepository = $this->prophesize(UserRepositoryInterface::class); $userRepository = $this->prophesize(UserRepositoryInterface::class);