Skip to content

Commit

Permalink
[TASK] Remove prophecy by mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
eliashaeussler committed Nov 24, 2023
1 parent 133b770 commit 5f5da18
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 254 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/docker-compose.yml export-ignore
/packaging_exclude.php export-ignore
/phpstan.neon export-ignore
/phpstan-baseline.neon export-ignore
/phpunit.xml export-ignore
/rector.php export-ignore
/renovate.json export-ignore
Expand Down
23 changes: 10 additions & 13 deletions Tests/Unit/Cache/HandlebarsCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@

use Fr\Typo3Handlebars\Cache\HandlebarsCache;
use Fr\Typo3Handlebars\Tests\Unit\HandlebarsCacheTrait;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use PHPUnit\Framework\MockObject\MockObject;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

Expand All @@ -40,12 +38,11 @@
class HandlebarsCacheTest extends UnitTestCase
{
use HandlebarsCacheTrait;
use ProphecyTrait;

/**
* @var ObjectProphecy|FrontendInterface
* @var FrontendInterface&MockObject
*/
protected $cacheProphecy;
protected $cacheMock;

/**
* @var HandlebarsCache
Expand All @@ -57,15 +54,15 @@ protected function setUp(): void
parent::setUp();

$cache = $this->getCache();
$this->cacheProphecy = $this->prophesize(FrontendInterface::class);
$this->cacheProphecy->get(Argument::type('string'))->will(function (array $parameters) use ($cache) {
$cachedTemplate = $cache->get($parameters[0]);
return $cachedTemplate;

$this->cacheMock = $this->createMock(FrontendInterface::class);
$this->cacheMock->method('get')->willReturnCallback(function (string $entryIdentifier) use ($cache) {
return $cache->get($entryIdentifier);
});
$this->cacheProphecy->set(Argument::type('string'), Argument::type('string'))->will(function (array $parameters) use ($cache) {
$cache->set($parameters[0], $parameters[1]);
$this->cacheMock->method('set')->willReturnCallback(function (string $entryIdentifier, $data) use ($cache) {
$cache->set($entryIdentifier, $data);
});
$this->subject = new HandlebarsCache($this->cacheProphecy->reveal());
$this->subject = new HandlebarsCache($this->cacheMock);
}

/**
Expand Down
9 changes: 3 additions & 6 deletions Tests/Unit/Compatibility/View/HandlebarsViewResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use Fr\Typo3Handlebars\Tests\Unit\Fixtures\Classes\DataProcessing\DummyProcessor;
use Fr\Typo3Handlebars\Tests\Unit\Fixtures\Classes\DummyConfigurationManager;
use Fr\Typo3Handlebars\Tests\Unit\Fixtures\Classes\DummyView;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\DependencyInjection\Container;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Extbase\Object\ObjectManager;
Expand All @@ -43,8 +42,6 @@
*/
class HandlebarsViewResolverTest extends UnitTestCase
{
use ProphecyTrait;

/**
* @var DummyProcessor
*/
Expand All @@ -65,9 +62,9 @@ protected function setUp(): void
// Handle different constructor arguments between TYPO3 11.4+ and lower
$typo3Version = new Typo3Version();
if ($typo3Version->getMajorVersion() < 11) {
$objectManagerProphecy = $this->prophesize(ObjectManager::class);
$objectManagerProphecy->get('foo')->willReturn(new DummyView());
$firstConstructorArgument = $objectManagerProphecy->reveal();
$objectManagerMock = $this->createMock(ObjectManager::class);
$objectManagerMock->method('get')->with('foo')->willReturn(new DummyView());
$firstConstructorArgument = $objectManagerMock;
} else {
$container = new Container();
$container->set('foo', new DummyView());
Expand Down
16 changes: 7 additions & 9 deletions Tests/Unit/DataProcessing/SimpleProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
use Fr\Typo3Handlebars\Renderer\Helper\VarDumpHelper;
use Fr\Typo3Handlebars\Tests\Unit\HandlebarsCacheTrait;
use Fr\Typo3Handlebars\Tests\Unit\HandlebarsTemplateResolverTrait;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\Test\TestLogger;
use Symfony\Component\EventDispatcher\EventDispatcher;
use TYPO3\CMS\Core\Http\ServerRequest;
Expand All @@ -48,12 +47,11 @@ class SimpleProcessorTest extends UnitTestCase
{
use HandlebarsCacheTrait;
use HandlebarsTemplateResolverTrait;
use ProphecyTrait;

/**
* @var ObjectProphecy|ContentObjectRenderer
* @var ContentObjectRenderer&MockObject
*/
protected $contentObjectRendererProphecy;
protected $contentObjectRendererMock;

/**
* @var TestLogger
Expand All @@ -74,15 +72,15 @@ protected function setUp(): void
{
parent::setUp();

$this->contentObjectRendererProphecy = $this->prophesize(ContentObjectRenderer::class);
$this->contentObjectRendererMock = $this->createMock(ContentObjectRenderer::class);
$this->logger = new TestLogger();
$this->renderer = new HandlebarsRenderer($this->getCache(), new EventDispatcher(), $this->getTemplateResolver());
$this->subject = new SimpleProcessor($this->renderer);
$this->subject->cObj = $this->contentObjectRendererProphecy->reveal();
$this->subject->cObj = $this->contentObjectRendererMock;
$this->subject->setLogger($this->logger);

$GLOBALS['TYPO3_REQUEST'] = new ServerRequest();
$GLOBALS['TSFE'] = $this->prophesize(TypoScriptFrontendController::class)->reveal();
$GLOBALS['TSFE'] = $this->createMock(TypoScriptFrontendController::class);
}

/**
Expand Down Expand Up @@ -115,7 +113,7 @@ public function processReturnsRenderedTemplate(): void
'title' => 'foo',
'comment' => 'baz',
];
$this->contentObjectRendererProphecy->data = $data;
$this->contentObjectRendererMock->data = $data;

$configuration = [
'userFunc.' => [
Expand Down
5 changes: 1 addition & 4 deletions Tests/Unit/Event/AfterRenderingEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

use Fr\Typo3Handlebars\Event\AfterRenderingEvent;
use Fr\Typo3Handlebars\Renderer\HandlebarsRenderer;
use Prophecy\PhpUnit\ProphecyTrait;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

/**
Expand All @@ -36,8 +35,6 @@
*/
class AfterRenderingEventTest extends UnitTestCase
{
use ProphecyTrait;

/**
* @var AfterRenderingEvent
*/
Expand All @@ -46,7 +43,7 @@ class AfterRenderingEventTest extends UnitTestCase
protected function setUp(): void
{
parent::setUp();
$this->subject = new AfterRenderingEvent('foo', 'baz', $this->prophesize(HandlebarsRenderer::class)->reveal());
$this->subject = new AfterRenderingEvent('foo', 'baz', $this->createMock(HandlebarsRenderer::class));
}

/**
Expand Down
5 changes: 1 addition & 4 deletions Tests/Unit/Event/BeforeRenderingEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

use Fr\Typo3Handlebars\Event\BeforeRenderingEvent;
use Fr\Typo3Handlebars\Renderer\HandlebarsRenderer;
use Prophecy\PhpUnit\ProphecyTrait;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

/**
Expand All @@ -36,8 +35,6 @@
*/
class BeforeRenderingEventTest extends UnitTestCase
{
use ProphecyTrait;

/**
* @var BeforeRenderingEvent
*/
Expand All @@ -46,7 +43,7 @@ class BeforeRenderingEventTest extends UnitTestCase
protected function setUp(): void
{
parent::setUp();
$this->subject = new BeforeRenderingEvent('foo', ['foo' => 'baz'], $this->prophesize(HandlebarsRenderer::class)->reveal());
$this->subject = new BeforeRenderingEvent('foo', ['foo' => 'baz'], $this->createMock(HandlebarsRenderer::class));
}

/**
Expand Down
18 changes: 8 additions & 10 deletions Tests/Unit/Renderer/HandlebarsRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
use Fr\Typo3Handlebars\Tests\Unit\Fixtures\Classes\Renderer\Template\DummyTemplateResolver;
use Fr\Typo3Handlebars\Tests\Unit\HandlebarsCacheTrait;
use Fr\Typo3Handlebars\Tests\Unit\HandlebarsTemplateResolverTrait;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\Test\TestLogger;
use Symfony\Component\EventDispatcher\EventDispatcher;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
Expand All @@ -49,7 +48,6 @@ class HandlebarsRendererTest extends UnitTestCase
{
use HandlebarsCacheTrait;
use HandlebarsTemplateResolverTrait;
use ProphecyTrait;

/**
* @var TestLogger
Expand All @@ -62,18 +60,18 @@ class HandlebarsRendererTest extends UnitTestCase
protected $subject;

/**
* @var ObjectProphecy|TypoScriptFrontendController
* @var TypoScriptFrontendController&MockObject
*/
protected $tsfeProphecy;
protected $tsfeMock;

protected function setUp(): void
{
parent::setUp();

$this->renewSubject();
$this->tsfeProphecy = $this->prophesize(TypoScriptFrontendController::class);
$this->tsfeMock = $this->createMock(TypoScriptFrontendController::class);

$GLOBALS['TSFE'] = $this->tsfeProphecy->reveal();
$GLOBALS['TSFE'] = $this->tsfeMock;
}

/**
Expand Down Expand Up @@ -188,12 +186,12 @@ public function renderLogsCriticalErrorIfTemplateCompilationFails(): void
public function renderDoesNotStoreRenderedTemplateInCacheIfDebugModeIsEnabled(): void
{
// Test with TypoScript config.debug = 1
$this->tsfeProphecy->config = ['config' => ['debug' => '1']];
$this->tsfeMock->config = ['config' => ['debug' => '1']];
$this->renewSubject()->render('DummyTemplate');
$this->assertCacheIsEmptyForTemplate('DummyTemplate.hbs');

// Test with TYPO3_CONF_VARS
$this->tsfeProphecy->config = [];
$this->tsfeMock->config = [];
$GLOBALS['TYPO3_CONF_VARS']['FE']['debug'] = 1;
$this->renewSubject()->render('DummyTemplate');
$this->assertCacheIsEmptyForTemplate('DummyTemplate.hbs');
Expand All @@ -204,7 +202,7 @@ public function renderDoesNotStoreRenderedTemplateInCacheIfDebugModeIsEnabled():
*/
public function renderDoesNotStoreRenderedTemplateInCacheIfCachingIsDisabled(): void
{
$this->tsfeProphecy->no_cache = true;
$this->tsfeMock->no_cache = true;
$this->subject->render('DummyTemplate');
$this->assertCacheIsEmptyForTemplate('DummyTemplate.hbs');
}
Expand Down
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
"armin/editorconfig-cli": "^1.5",
"ergebnis/composer-normalize": "^2.15",
"helmich/typo3-typoscript-lint": "^2.5 || ^3.0",
"jangregor/phpstan-prophecy": "^1.0",
"mikey179/vfsstream": "^1.6.7",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-phpunit": "^1.1",
"phpunit/phpunit": "^9.5",
Expand Down
Loading

0 comments on commit 5f5da18

Please sign in to comment.