Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,44 @@ jobs:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
TYPO3: ['11' , '12', '13']
TYPO3: ['13', '14']

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
tools: composer:v2

- name: Validate composer.json and composer.lock
run: composer validate
- name: Validate composer.json
run: composer validate --no-check-lock

- name: Cache dependencies
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.composer/cache
key: dependencies-composer-${{ hashFiles('composer.json') }}
key: dependencies-composer-${{ matrix.TYPO3 }}-${{ hashFiles('composer.json') }}

- name: Install composer dependencies TYPO3 14
if: matrix.TYPO3 == '14'
run: |
composer require typo3/cms-core:^14.0 typo3/cms-frontend:^14.0 --no-progress --no-interaction -W

- name: Install composer dependencies TYPO3 13
if: matrix.TYPO3 == '13'
run: |
composer install --no-progress --no-interaction
composer require typo3/cms-core:^13.4 typo3/cms-frontend:^13.4 --no-progress --no-interaction -W

- name: Unit Tests
run: ./vendor/bin/phpunit -c Build/phpunit/UnitTests.xml

- name: Install composer dependencies TYPO3 12
if: matrix.TYPO3 == '12'
run: |
composer require typo3/cms-core:^12.4 --no-progress --no-interaction --dev -W
- name: Install composer dependencies TYPO3 11
if: matrix.TYPO3 == '11'
run: |
composer require typo3/cms-core:^11.5 --no-progress --no-interaction --dev -W
- name: Phpstan
run: ./vendor/bin/phpstan analyze -c phpstan.neon

- name: Phpcsfix
run: ./vendor/bin/php-cs-fixer fix --config=php-cs-fixer.php --dry-run --stop-on-violation --using-cache=no
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/public/
/vendor/
/.php-cs-fixer.cache
/Build/phpunit/.phpunit.cache/
24 changes: 24 additions & 0 deletions Build/phpunit/UnitTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.5/phpunit.xsd"
bootstrap="UnitTestsBootstrap.php"
cacheDirectory=".phpunit.cache"
colors="true"
failOnWarning="true"
failOnDeprecation="true"
failOnNotice="true"
failOnRisky="true"
beStrictAboutTestsThatDoNotTestAnything="true"
>
<testsuites>
<testsuite name="Unit tests">
<directory>../../Tests/Unit/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>../../src/</directory>
</include>
</source>
</phpunit>
17 changes: 17 additions & 0 deletions Build/phpunit/UnitTestsBootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

/*
* This file is part of TYPO3 CMS-based extension "JustInCase" by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

$autoloader = dirname(__DIR__, 2) . '/vendor/autoload.php';
if (!file_exists($autoloader)) {
die('Please run "composer install" before running the unit tests.' . PHP_EOL);
}
require $autoloader;
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ both URLs would work for the users.

Use it via `composer req b13/justincase` or install the Extension `justincase` from the TYPO3 Extension Repository.

_justincase_ requires TYPO3 v9.5.0 or later.
_justincase_ requires TYPO3 v13.4 or later (v13.4 and v14 are supported).

For TYPO3 v11.5 and v12.4, use the 2.x release line.

## Configuration

Expand Down
48 changes: 48 additions & 0 deletions Tests/Unit/Middleware/BeforeMiddlewareIsAppliedEventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace B13\JustInCase\Tests\Unit\Middleware;

/*
* This file is part of TYPO3 CMS-based extension "JustInCase" by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

use B13\JustInCase\Middleware\BeforeMiddlewareIsAppliedEvent;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use TYPO3\CMS\Core\Http\ServerRequest;

final class BeforeMiddlewareIsAppliedEventTest extends TestCase
{
#[Test]
public function middlewareIsAppliedByDefault(): void
{
$event = new BeforeMiddlewareIsAppliedEvent(new ServerRequest('https://example.com/Foo'));

self::assertTrue($event->shouldBeApplied());
}

#[Test]
public function doNotApplyPreventsMiddlewareFromBeingApplied(): void
{
$event = new BeforeMiddlewareIsAppliedEvent(new ServerRequest('https://example.com/Foo'));

$event->doNotApply();

self::assertFalse($event->shouldBeApplied());
}

#[Test]
public function serverRequestIsExposedToListeners(): void
{
$request = new ServerRequest('https://example.com/Foo');
$event = new BeforeMiddlewareIsAppliedEvent($request);

self::assertSame($request, $event->getServerRequest());
}
}
76 changes: 76 additions & 0 deletions Tests/Unit/Middleware/Fixtures/RoutableSite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types=1);

namespace B13\JustInCase\Tests\Unit\Middleware\Fixtures;

/*
* This file is part of TYPO3 CMS-based extension "JustInCase" by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UriInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Routing\RouteNotFoundException;
use TYPO3\CMS\Core\Routing\RouteResultInterface;
use TYPO3\CMS\Core\Routing\RouterInterface;
use TYPO3\CMS\Core\Routing\SiteRouteResult;
use TYPO3\CMS\Core\Site\Entity\Site;

/**
* A Site whose router only matches an explicit list of paths.
*
* Site::getRouter() builds a PageRouter via GeneralUtility::makeInstance and needs
* a database, so it is replaced here to keep these tests pure unit tests.
*/
final class RoutableSite extends Site
{
/**
* @param string[] $matchingPaths paths the router resolves; everything else throws
*/
public function __construct(
string $identifier,
int $rootPageId,
array $configuration,
private readonly array $matchingPaths = []
) {
parent::__construct($identifier, $rootPageId, $configuration);
}

public function getRouter(?Context $context = null): RouterInterface
{
return new class($this, $this->matchingPaths) implements RouterInterface {
/**
* @param string[] $matchingPaths
*/
public function __construct(
private readonly Site $site,
private readonly array $matchingPaths
) {
}

public function matchRequest(
ServerRequestInterface $request,
?RouteResultInterface $previousResult = null
): RouteResultInterface {
if (!in_array($request->getUri()->getPath(), $this->matchingPaths, true)) {
throw new RouteNotFoundException('No route found', 1579000000);
}
return new SiteRouteResult($request->getUri(), $this->site, null);
}

public function generateUri(
$route,
array $parameters = [],
string $fragment = '',
string $type = self::ABSOLUTE_URL
): UriInterface {
throw new \BadMethodCallException('Not needed in these tests', 1579000001);
}
};
}
}
Loading
Loading