Skip to content

Commit

Permalink
Add TYPO3 v11 and PHP 8.x compatibility (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSiepmann authored Jan 4, 2023
1 parent f1d9466 commit 0332017
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 102 deletions.
65 changes: 29 additions & 36 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
coverage: none
tools: composer:v2

- name: Validate composer.json
run: composer validate

Expand All @@ -16,38 +22,22 @@ jobs:
php-version:
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "${{ matrix.php-version }}"

- name: PHP lint
run: "find *.php Classes Tests -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l"

check-dependencies:
runs-on: ubuntu-latest
needs: [check-composer]
steps:
- uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "7.3"

- name: Keep composer at 1.x
run: sudo composer selfupdate --1

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest --no-plugins

- name: Missing composer requirements
run: ./vendor/bin/composer-require-checker check

xml-linting:
runs-on: ubuntu-latest
needs: [check-composer]
Expand All @@ -57,14 +47,13 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "7.3"
php-version: "8.2"
coverage: none
tools: composer:v2

- name: Install xmllint
run: sudo apt-get install libxml2-utils

- name: Keep composer at 1.x
run: sudo composer selfupdate --1

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

Expand All @@ -80,18 +69,16 @@ jobs:
coding-guideline:
runs-on: ubuntu-latest
needs:
- check-dependencies
- xml-linting
steps:
- uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "7.3"

- name: Keep composer at 1.x
run: sudo composer selfupdate --1
coverage: none
tools: composer:v2
php-version: "8.2"

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
Expand All @@ -102,24 +89,30 @@ jobs:
tests:
runs-on: ubuntu-latest
needs:
- check-dependencies
- xml-linting
strategy:
matrix:
php-version:
- 7.3
- 7.4
include:
- php-version: '7.3'
typo3-version: '^10.4'
- php-version: '7.4'
typo3-version: '^10.4'
- php-version: '7.4'
typo3-version: '^11.5'
- php-version: '8.1'
typo3-version: '^11.5'
- php-version: '8.2'
typo3-version: '^11.5'
steps:
- uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
coverage: none
tools: composer:v2
php-version: "${{ matrix.php-version }}"

- name: Keep composer at 1.x
run: sudo composer selfupdate --1

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

Expand Down
2 changes: 2 additions & 0 deletions Documentation/Changelog/1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Nothing
Features
--------

* Add compatibility for TYPO3 v11 and PHP 8.0, 8.1, 8.2.

* Add context to foreign data factory.
The factory can optionally implement the ``WerkraumMedia\Calendar\Domain\Model\ContextSpecificFactory`` interface.
That way it will receive a bit of context to react on the current situation.
Expand Down
12 changes: 10 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ TYPO3 Extension: calendar

Provides:

* Data (classes) for Month, Week and Day.
* Data (classes) for Year, Month, Week and Day.

* Controller with action to view Month, Week and Day.
* Controller with action to view Year, Month, Week and Day.

Each day can have foreign data created by a factory.
That way extensions or TYPO3 instances can add further data to each day.

Alter Variables
---------------

The controller also has an event to alter assigned variables for each action.

Check out ``Tests/Fixtures/calendar_example/`` as an example on how to provide
necessary custom setup.

Configuration
-------------

Expand Down
23 changes: 12 additions & 11 deletions Tests/Unit/Domain/Model/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
namespace WerkraumMedia\Calendar\Tests\Unit\Domain\Model;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use WerkraumMedia\Calendar\Domain\Model\Context;

Expand All @@ -33,15 +32,17 @@
*/
class ContextTest extends TestCase
{
use ProphecyTrait;

/**
* @test
*/
public function canNotBeCreatedViaNew(): void
{
$this->expectError();
$this->expectErrorMessage('Call to private WerkraumMedia\Calendar\Domain\Model\Context::__construct() from context \'WerkraumMedia\Calendar\Tests\Unit\Domain\Model\ContextTest\'');
if (version_compare(PHP_VERSION, '8.0', '>=')) {
$this->expectErrorMessage('Call to private WerkraumMedia\Calendar\Domain\Model\Context::__construct() from scope WerkraumMedia\Calendar\Tests\Unit\Domain\Model\ContextTest');
} else {
$this->expectErrorMessage('Call to private WerkraumMedia\Calendar\Domain\Model\Context::__construct() from context \'WerkraumMedia\Calendar\Tests\Unit\Domain\Model\ContextTest\'');
}
$subject = new Context();
}

Expand All @@ -50,8 +51,8 @@ public function canNotBeCreatedViaNew(): void
*/
public function canBeCreatedFromContentObjectRenderer(): void
{
$contentObjectRenderer = $this->prophesize(ContentObjectRenderer::class);
$subject = Context::createFromContentObjectRenderer($contentObjectRenderer->reveal());
$contentObjectRenderer = $this->createStub(ContentObjectRenderer::class);
$subject = Context::createFromContentObjectRenderer($contentObjectRenderer);

self::assertInstanceOf(Context::class, $subject);
}
Expand All @@ -61,9 +62,9 @@ public function canBeCreatedFromContentObjectRenderer(): void
*/
public function providesTableNameInheritedFromContentObjectRenderer(): void
{
$contentObjectRenderer = $this->prophesize(ContentObjectRenderer::class);
$contentObjectRenderer->getCurrentTable()->willReturn('tx_calendar_example_table');
$subject = Context::createFromContentObjectRenderer($contentObjectRenderer->reveal());
$contentObjectRenderer = $this->createStub(ContentObjectRenderer::class);
$contentObjectRenderer->method('getCurrentTable')->willReturn('tx_calendar_example_table');
$subject = Context::createFromContentObjectRenderer($contentObjectRenderer);

self::assertSame('tx_calendar_example_table', $subject->getTableName());
}
Expand All @@ -73,12 +74,12 @@ public function providesTableNameInheritedFromContentObjectRenderer(): void
*/
public function providesDatabaseRowInheritedFromContentObjectRenderer(): void
{
$contentObjectRenderer = $this->prophesize(ContentObjectRenderer::class);
$contentObjectRenderer = $this->createStub(ContentObjectRenderer::class);
$contentObjectRenderer->data = [
'uid' => 10,
'pid' => 1,
];
$subject = Context::createFromContentObjectRenderer($contentObjectRenderer->reveal());
$subject = Context::createFromContentObjectRenderer($contentObjectRenderer);

self::assertSame([
'uid' => 10,
Expand Down
19 changes: 8 additions & 11 deletions Tests/Unit/Domain/Model/DayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*/

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use WerkraumMedia\Calendar\Domain\Model\Day;
Expand All @@ -38,7 +36,6 @@
*/
class DayTest extends TestCase
{
use ProphecyTrait;
use ForcePropertyTrait;

public function tearDown(): void
Expand Down Expand Up @@ -127,11 +124,11 @@ public function isNotActiveIfForeignDataIsNotActive(): void
{
$subject = new Day(new \DateTime('2020-10-19'));

$foreignData = $this->prophesize(IsDayActive::class);
$foreignData->isActive(Argument::any())->willReturn(false);
$foreignData = $this->createStub(IsDayActive::class);
$foreignData->method('isActive')->willReturn(false);

$this->forceProperty($subject, 'initialized', true);
$this->forceProperty($subject, 'foreignData', $foreignData->reveal());
$this->forceProperty($subject, 'foreignData', $foreignData);

self::assertFalse($subject->isActive());
}
Expand All @@ -143,13 +140,13 @@ public function initializesForeignDataViaFactory(): void
{
$subject = new Day(new \DateTime('2020-10-19'));

$foreignData = $this->prophesize(IsDayActive::class);
$foreignData->isActive(Argument::any())->willReturn(true);
$foreignData = $this->createStub(IsDayActive::class);
$foreignData->method('isActive')->willReturn(true);

$factory = $this->prophesize(ForeignDataFactory::class);
$factory->getData($subject)->willReturn($foreignData->reveal());
$factory = $this->createStub(ForeignDataFactory::class);
$factory->method('getData')->willReturn($foreignData);

GeneralUtility::addInstance(ForeignDataFactory::class, $factory->reveal());
GeneralUtility::addInstance(ForeignDataFactory::class, $factory);

self::assertTrue($subject->isActive());
}
Expand Down
18 changes: 8 additions & 10 deletions Tests/Unit/Domain/Model/MonthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use WerkraumMedia\Calendar\Domain\Model\Month;
use WerkraumMedia\Calendar\Domain\Model\Week;
use WerkraumMedia\Calendar\Tests\ForcePropertyTrait;
Expand All @@ -33,7 +32,6 @@
*/
class MonthTest extends TestCase
{
use ProphecyTrait;
use ForcePropertyTrait;

/**
Expand Down Expand Up @@ -194,9 +192,9 @@ public function returnsNotActiveIfAllWeeksAreInactive(): void
{
$subject = new Month(02, 2018);

$week = $this->prophesize(Week::class);
$week->isActive()->willReturn(false);
$weeks = [$week->reveal()];
$week = $this->createStub(Week::class);
$week->method('isActive')->willReturn(false);
$weeks = [$week];
$this->forceProperty($subject, 'weeks', $weeks);

self::assertFalse($subject->isActive());
Expand All @@ -209,11 +207,11 @@ public function returnsActiveIfASingleWeekIsActive(): void
{
$subject = new Month(02, 2018);

$week = $this->prophesize(Week::class);
$week->isActive()->willReturn(true);
$week2 = $this->prophesize(Week::class);
$week2->isActive()->willReturn(false);
$weeks = [$week->reveal(), $week2->reveal()];
$week = $this->createStub(Week::class);
$week->method('isActive')->willReturn(true);
$week2 = $this->createStub(Week::class);
$week2->method('isActive')->willReturn(false);
$weeks = [$week, $week2];
$this->forceProperty($subject, 'weeks', $weeks);

self::assertTrue($subject->isActive());
Expand Down
7 changes: 2 additions & 5 deletions Tests/Unit/Domain/Model/NullDataFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use WerkraumMedia\Calendar\Domain\Model\Day;
use WerkraumMedia\Calendar\Domain\Model\NullDataFactory;

Expand All @@ -31,15 +30,13 @@
*/
class NullDataFactoryTest extends TestCase
{
use ProphecyTrait;

/**
* @test
*/
public function returnsNull(): void
{
$subject = new NullDataFactory();
$day = $this->prophesize(Day::class);
self::assertNull($subject->getData($day->reveal()));
$day = $this->createStub(Day::class);
self::assertNull($subject->getData($day));
}
}
Loading

0 comments on commit 0332017

Please sign in to comment.