Skip to content

Commit

Permalink
First listener tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Nov 13, 2024
1 parent 6928b5c commit 5beaa2b
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Tests/Unit/Cache/Listener/AbstractListenerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace SFC\Staticfilecache\Tests\Unit\Cache\Listener;

use Psr\Http\Message\ServerRequestInterface;
use SFC\Staticfilecache\Event\CacheRuleEvent;
use SFC\Staticfilecache\Tests\Unit\AbstractTest;

abstract class AbstractListenerTest extends AbstractTest
{

protected function emptyCacheRuleEvent(): CacheRuleEvent
{
return new CacheRuleEvent(
$this->getMockBuilder(ServerRequestInterface::class)->getMock(),
[],
false
);
}

}
37 changes: 37 additions & 0 deletions Tests/Unit/Cache/Listener/CachingAllowedListenerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace SFC\Staticfilecache\Tests\Unit\Cache\Listener;

use Psr\Http\Message\ServerRequestInterface;
use SFC\Staticfilecache\Cache\Listener\CachingAllowedListener;
use SFC\Staticfilecache\Event\CacheRuleEvent;
use TYPO3\CMS\Core\Information\Typo3Version;

class CachingAllowedListenerTest extends AbstractListenerTest
{

public function testNoExplanation(): void
{
$version = $this->getMockBuilder(Typo3Version::class)->disableOriginalConstructor()->getMock();
$version->method('getMajorVersion')->willReturn(12);

$listener = new CachingAllowedListener($version);

$event = $this->emptyCacheRuleEvent();
$listener($event);

self::assertEquals([], $event->getExplanation());
self::assertEquals(false, $event->isSkipProcessing());

}
protected function emptyCacheRuleEvent(): CacheRuleEvent
{
return new CacheRuleEvent(
$this->getMockBuilder(ServerRequestInterface::class)->getMock(),
[],
false
);
}
}
43 changes: 43 additions & 0 deletions Tests/Unit/Cache/Listener/EnableListenerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace SFC\Staticfilecache\Tests\Unit\Cache\Listener;

use SFC\Staticfilecache\Cache\Listener\EnableListener;
use SFC\Staticfilecache\Service\ConfigurationService;

class EnableListenerTest extends AbstractListenerTest
{

public function testNoExplanation(): void
{
$configurationService = $this->getMockBuilder(ConfigurationService::class)->disableOriginalConstructor()->getMock();
$configurationService->method('isBool')->willReturn(false);

$listener = new EnableListener($configurationService);

$event = $this->emptyCacheRuleEvent();
$listener($event);

self::assertEquals([], $event->getExplanation());
self::assertEquals(false, $event->isSkipProcessing());

}


public function testAddExplanation(): void
{
$configurationService = $this->getMockBuilder(ConfigurationService::class)->disableOriginalConstructor()->getMock();
$configurationService->method('isBool')->willReturn(true);

$listener = new EnableListener($configurationService);

$event = $this->emptyCacheRuleEvent();
$listener($event);

self::assertNotEquals([], $event->getExplanation());
self::assertEquals(false, $event->isSkipProcessing());

}
}
2 changes: 1 addition & 1 deletion Tests/UnitTests.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<testsuite name="staticfilecache tests">
<directory>Unit/</directory>
<exclude>Unit/AbstractTest.php</exclude>
<exclude>Unit/Cache/Rule/AbstractRuleTest.php</exclude>
<exclude>Unit/Service/HttpPush/AbstractHttpPushTest.php</exclude>
<exclude>Unit/Cache/Listener/AbstractListenerTest.php</exclude>
</testsuite>
</testsuites>
<source>
Expand Down

0 comments on commit 5beaa2b

Please sign in to comment.