Skip to content

Commit

Permalink
Moved Integration test to their own directory
Browse files Browse the repository at this point in the history
Renamed the Abstract Integration class
Refactored existing test
currently one test is failing for LogoutHandlerTest
Signed-off-by: Joey Smith <[email protected]>

Signed-off-by: Joey Smith <[email protected]>
  • Loading branch information
tyrsson committed Aug 28, 2023
1 parent 3242eb5 commit 3f8795a
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

declare(strict_types=1);

namespace PageManagerTest\Storage;
namespace PageManagerTest\Storage\Integration;

use Laminas\Db\Adapter\AdapterInterface;
use PageManager\Storage\PageRepository;
use PageManager\Storage\PageRepositoryFactory;
use Test\AbtractIntegrationTestCase;
use Test\Integration\AbstractTestCase;

final class PageRepositoryFactoryTest extends AbtractIntegrationTestCase
final class PageRepositoryFactoryTest extends AbstractTestCase
{
protected function setUp(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace PageManagerTest\Storage;
namespace PageManagerTest\Storage\Integration;

use PageManager\Storage\PageEntity;
use PageManager\Storage\PageRepository;
use Test\AbtractIntegrationTestCase;
use Test\Integration\AbstractTestCase;

final class PageRepositoryTest extends AbtractIntegrationTestCase
final class PageRepositoryTest extends AbstractTestCase
{
protected function setUp(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

declare(strict_types=1);

namespace PageManagerTest\Storage;
namespace PageManagerTest\Storage\Integration;

use PageManager\Storage\SavePageCommandHandler;
use PageManager\Storage\SavePageCommandHandlerFactory as Factory;
use Test\AbtractIntegrationTestCase;
use Test\Integration\AbstractTestCase;

final class SavePageCommandHandlerFactoryTest extends AbtractIntegrationTestCase
final class SavePageCommandHandlerFactoryTest extends AbstractTestCase
{
protected function setUp(): void
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<?php

/**
* Test Type: Integration
* todo: needs mocked componets as this test is kinda dirty
*/

declare(strict_types=1);

namespace PageManagerTest\Storage;
namespace PageManagerTest\Storage\Integration;

use League\Tactician\CommandBus;
use PageManager\Storage\PageEntity;
use PageManager\Storage\SavePageCommand;
use Test\AbtractIntegrationTestCase;
use Test\Integration\AbstractTestCase;

final class SavePageCommandHandlerTest extends AbtractIntegrationTestCase
final class SavePageCommandHandlerTest extends AbstractTestCase
{
/** @var CommandBus */
protected $commandBus;
Expand Down
25 changes: 0 additions & 25 deletions test/Test/AbtractIntegrationTestCase.php

This file was deleted.

44 changes: 44 additions & 0 deletions test/Test/Integration/AbstractTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Test\Integration;

use Mezzio\Application;
use Mezzio\MiddlewareFactory;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;

abstract class AbstractTestCase extends TestCase
{
/** @var Application $app */
protected $app;
/** @var ContainerInterface */
protected $container;

protected function setUp(): void
{
parent::setUp();
$this->initContainer();
// $this->initApp();
// $this->initPipeline();
}

protected function initContainer(): void
{
$this->container = require __DIR__ . '/../../../config/container.php';
}

protected function initApp(): void
{
/** @var Application */
$this->app = $this->container->get(Application::class);
}

protected function initPipeline(): void
{
/** @var MiddlewareFactory */
$factory = $this->container->get(MiddlewareFactory::class);
(require __DIR__ . '/../../../config/pipeline.php')($this->app, $factory, $this->container);
}
}
10 changes: 0 additions & 10 deletions test/UserManagerTest/Handler/LogoutHandlerTest.php

This file was deleted.

45 changes: 45 additions & 0 deletions test/UserManagerTest/Integration/LogoutHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace UserManagerTest\Integration;

use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequest;
use Laminas\Diactoros\Uri;
use Mezzio\Authentication\UserInterface;
use PHPUnit\Framework\MockObject\MockObject;
use Test\Integration\AbstractTestCase;

/**
*
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
final class LogoutHandlerTest extends AbstractTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->initApp();
$this->initPipeline();
}

public function testUserIsLoggedOut(): void
{
$sessionData = [
'username' => 'jsmith',
'roles' => [
'Administrator',
],
];
$_SESSION[UserInterface::class] = $sessionData;
$uri = new Uri('/logout');
$request = new ServerRequest([], [], $uri);
$request->withAttribute(UserInterface::class, $sessionData);
/** @var Response */
$response = $this->app->handle($request);
$this->assertEquals(302, $response->getStatusCode());
$this->assertEquals('/user/login', $response->getHeaderLine('Location'));
}
}

0 comments on commit 3f8795a

Please sign in to comment.