Skip to content

Commit

Permalink
bugfix: adjust test
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanowak committed Jan 11, 2024
1 parent 1cf2ab4 commit 3b493ed
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
Empty file added Tests/Functional/.gitkeep
Empty file.
46 changes: 41 additions & 5 deletions Tests/Unit/Middleware/AjaxRequestMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,56 @@
use AssertionError;
use Exception;
use Netlogix\Nxajax\Middleware\AjaxRequestMiddleware;
use Netlogix\Nxtestingframework\Tests\Unit\ContainerAwareUnitTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Psr\Container\ContainerInterface;
use Psr\Http\Server\RequestHandlerInterface;
use RuntimeException;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

class AjaxRequestMiddlewareTest extends ContainerAwareUnitTestCase
class AjaxRequestMiddlewareTest extends UnitTestCase implements ContainerInterface
{
protected bool $resetSingletonInstances = true;
private array $instances = [];

public function setUp(): void
{
parent::setUp();
$this->instances = [];
GeneralUtility::setContainer($this);
}

public function tearDown(): void
{
$this->instances = [];
parent::tearDown();
}

public function getContainer(): ContainerInterface
{
return $this;
}

public function get(string $id)
{
return $this->instances[$id];
}

public function has(string $id): bool
{
return array_key_exists($id, $this->instances);
}

public function set(string $id, $instance): void
{
$this->instances[$id] = $instance;
}

public static function getPluginRenderingResults(): array
{
Expand Down Expand Up @@ -122,7 +158,8 @@ public function process_should_throw_assertion_error_when_no_typo_script_fronten

#[Test]
public function process_should_throw_runtime_exception_when_typo_script_frontend_controller_is_not_loaded_properly(
): void {
): void
{
$pageId = 1;

$typoScriptFrontendController = $this->getTypoScriptFrontendController($pageId);
Expand Down Expand Up @@ -214,8 +251,7 @@ public function process_should_return_plugin_rendering_result_or_fail_with_expec
->method('cObjGetSingle')
->willReturnCallback(fn () => $renderingResults[$matcher->numberOfInvocations() - 1]);

$this->getContainer()
->set(ContentObjectRenderer::class, $contentObjectRenderer);
$this->getContainer()->set(ContentObjectRenderer::class, $contentObjectRenderer);
}

$subject = new AjaxRequestMiddleware();
Expand Down

0 comments on commit 3b493ed

Please sign in to comment.