Commit d711596b authored by Anja Leichsenring's avatar Anja Leichsenring
Browse files

[TASK] Prepare TYPO3 tests to use phpunit v9

Remove usage of $mock->at() matcher and some other
deprecated matchers.

Following matchers are deprecated in phpunit v9:

* at()
* assertRegExp()
* assertFileNotExists()

Those were replaced with their respective replacements.

Resolves: #92461
Releases: master, 10.4
Change-Id: Id8373659160c219c2caff8bcbe0bdb9b0da16436
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65971


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
parent 4a4e435a
<?php
declare(strict_types=1);
namespace TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeElements;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Backend\Form\NodeInterface;
class BarElement implements NodeInterface
{
public function __construct(NodeFactory $nodeFactory, array $data)
{
}
public function render()
{
// TODO: Implement render() method.
}
}
<?php
declare(strict_types=1);
namespace TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeElements;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Backend\Form\NodeInterface;
class FooElement implements NodeInterface
{
public function __construct(NodeFactory $nodeFactory, array $data)
{
}
public function render()
{
// TODO: Implement render() method.
}
}
<?php
declare(strict_types=1);
namespace TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeResolvers;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Backend\Form\NodeResolverInterface;
use TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeElements\BarElement;
class BarResolver implements NodeResolverInterface
{
public function __construct(NodeFactory $nodeFactory, array $data)
{
}
public function resolve()
{
return BarElement::class;
}
}
<?php
declare(strict_types=1);
namespace TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeResolvers;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Backend\Form\NodeResolverInterface;
use TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeElements\FooElement;
class FooResolver implements NodeResolverInterface
{
public function __construct(NodeFactory $nodeFactory, array $data)
{
}
public function resolve()
{
return FooElement::class;
}
}
<?php
declare(strict_types=1);
namespace TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeResolvers;
class InvalidNodeResolverClass
{
}
......@@ -239,21 +239,17 @@ class DatabaseLanguageRowsTest extends UnitTestCase
'text' => 'default language text',
'sys_language_uid' => 0,
];
$this->subject->expects(self::at(0))
->method('getRecordWorkspaceOverlay')
->with('tt_content', 23)
->willReturn($defaultLanguageRow);
/** @var TranslationConfigurationProvider|ObjectProphecy $translationProphecy */
$translationProphecy = $this->prophesize(TranslationConfigurationProvider::class);
GeneralUtility::addInstance(TranslationConfigurationProvider::class, $translationProphecy->reveal());
$translationProphecy->translationInfo('tt_content', 23, 3)->shouldBeCalled()->willReturn($translationResult);
// This is the real check: The "additional overlay" should be fetched
$this->subject->expects(self::at(1))
// The second call is the real check: The "additional overlay" should be fetched
$this->subject->expects(self::exactly(2))
->method('getRecordWorkspaceOverlay')
->with('tt_content', 43)
->willReturn($recordWsolResult);
->withConsecutive(['tt_content', 23], ['tt_content', 43])
->willReturnOnConsecutiveCalls($defaultLanguageRow, $recordWsolResult);
$expected = $input;
$expected['defaultLanguageRow'] = $defaultLanguageRow;
......@@ -334,10 +330,6 @@ class DatabaseLanguageRowsTest extends UnitTestCase
'text' => 'default language text',
'sys_language_uid' => 0,
];
$this->subject->expects(self::at(0))
->method('getRecordWorkspaceOverlay')
->with('tt_content', 23)
->willReturn($defaultLanguageRow);
/** @var TranslationConfigurationProvider|ObjectProphecy $translationProphecy */
$translationProphecy = $this->prophesize(TranslationConfigurationProvider::class);
......@@ -345,11 +337,11 @@ class DatabaseLanguageRowsTest extends UnitTestCase
$translationProphecy->translationInfo('tt_content', 23, 3)->shouldBeCalled()->willReturn($translationResult);
$translationProphecy->translationInfo('tt_content', 23, 2)->shouldNotBeCalled();
// This is the real check: The "additional overlay" should be fetched
$this->subject->expects(self::at(1))
// The second call is the real check: The "additional overlay" should be fetched
$this->subject->expects(self::exactly(2))
->method('getRecordWorkspaceOverlay')
->with('tt_content', 43)
->willReturn($recordWsolResult);
->withConsecutive(['tt_content', 23], ['tt_content', 43])
->willReturnOnConsecutiveCalls($defaultLanguageRow, $recordWsolResult);
$expected = $input;
$expected['defaultLanguageRow'] = $defaultLanguageRow;
......@@ -421,14 +413,10 @@ class DatabaseLanguageRowsTest extends UnitTestCase
'text' => 'default language text',
'sys_language_uid' => 0,
];
$this->subject->expects(self::at(0))
->method('getRecordWorkspaceOverlay')
->with('tt_content', 23)
->willReturn($defaultLanguageRow);
$this->subject->expects(self::at(1))
$this->subject->expects(self::exactly(2))
->method('getRecordWorkspaceOverlay')
->with('tt_content', 24)
->willReturn($sourceLanguageRow);
->withConsecutive(['tt_content', 23], ['tt_content', 24])
->willReturn($defaultLanguageRow, $sourceLanguageRow);
$expected = $input;
$expected['defaultLanguageRow'] = $defaultLanguageRow;
......
......@@ -50,15 +50,10 @@ class DatabaseParentPageRowTest extends UnitTestCase
'pid' => 321
];
$this->subject->expects(self::at(0))
$this->subject->expects(self::exactly(2))
->method('getDatabaseRow')
->with($input['tableName'], 10)
->willReturn(['pid' => 123]);
$this->subject->expects(self::at(1))
->method('getDatabaseRow')
->with('pages', 123)
->willReturn($parentPageRow);
->withConsecutive([$input['tableName'], 10], ['pages', 123])
->willReturnOnConsecutiveCalls(['pid' => 123], $parentPageRow);
$result = $this->subject->addData($input);
......@@ -83,15 +78,10 @@ class DatabaseParentPageRowTest extends UnitTestCase
'uid' => 123,
'pid' => 321
];
$this->subject->expects(self::at(0))
$this->subject->expects(self::exactly(2))
->method('getDatabaseRow')
->with($input['tableName'], 10)
->willReturn($neighborRow);
$this->subject->expects(self::at(1))
->method('getDatabaseRow')
->with('pages', 321)
->willReturn($parentPageRow);
->withConsecutive([$input['tableName'], 10], ['pages', 321])
->willReturnOnConsecutiveCalls($neighborRow, $parentPageRow);
$result = $this->subject->addData($input);
......
......@@ -73,8 +73,8 @@ class TcaCheckboxItemsTest extends UnitTestCase
'type' => 'check',
'items' => [
0 => [
'foo', //@todo a followup patch should refactor towards 'label' => 'foo'
'bar', //@todo a followup patch should remove this numeric key altogether
'foo', // @todo a followup patch should refactor towards 'label' => 'foo'
'bar', // @todo a followup patch should remove this numeric key altogether
'invertStateDisplay' => false
],
],
......
......@@ -21,7 +21,11 @@ use TYPO3\CMS\Backend\Form\Element\UnknownElement;
use TYPO3\CMS\Backend\Form\Exception;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Backend\Form\NodeInterface;
use TYPO3\CMS\Backend\Form\NodeResolverInterface;
use TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeElements\BarElement;
use TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeElements\FooElement;
use TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeResolvers\BarResolver;
use TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeResolvers\FooResolver;
use TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeResolvers\InvalidNodeResolverClass;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
......@@ -343,16 +347,12 @@ class NodeFactoryTest extends UnitTestCase
[
'nodeName' => 'foo',
'priority' => 20,
'class' => \stdClass::class,
'class' => FooElement::class,
],
];
$mockNode = $this->createMock(NodeInterface::class);
/** @var NodeFactory|\PHPUnit\Framework\MockObject\MockObject $mockSubject */
$mockSubject = $this->getMockBuilder(NodeFactory::class)
->setMethods(['instantiate'])
->getMock();
$mockSubject->expects(self::once())->method('instantiate')->with('stdClass')->willReturn($mockNode);
$mockSubject->create($data);
$subject = new NodeFactory();
self::assertInstanceOf(FooElement::class, ($subject->create($data)));
}
/**
......@@ -365,21 +365,16 @@ class NodeFactoryTest extends UnitTestCase
1433089467 => [
'nodeName' => 'foo',
'priority' => 20,
'class' => 'foo1Class',
'class' => FooElement::class,
],
1433089468 => [
'nodeName' => 'foo',
'priority' => 30,
'class' => 'foo2Class',
'class' => BarElement::class,
],
];
$mockNode = $this->createMock(NodeInterface::class);
/** @var NodeFactory|\PHPUnit\Framework\MockObject\MockObject $mockSubject */
$mockSubject = $this->getMockBuilder(NodeFactory::class)
->setMethods(['instantiate'])
->getMock();
$mockSubject->expects(self::once())->method('instantiate')->with('foo2Class')->willReturn($mockNode);
$mockSubject->create($data);
$subject = new NodeFactory();
self::assertInstanceOf(BarElement::class, ($subject->create($data)));
}
/**
......@@ -392,21 +387,16 @@ class NodeFactoryTest extends UnitTestCase
1433089469 => [
'nodeName' => 'foo',
'priority' => 30,
'class' => 'foo2Class',
'class' => FooElement::class,
],
1433089470 => [
'nodeName' => 'foo',
'priority' => 20,
'class' => 'foo1Class',
'class' => BarElement::class,
],
];
$mockNode = $this->createMock(NodeInterface::class);
/** @var NodeFactory|\PHPUnit\Framework\MockObject\MockObject $mockSubject */
$mockSubject = $this->getMockBuilder(NodeFactory::class)
->setMethods(['instantiate'])
->getMock();
$mockSubject->expects(self::once())->method('instantiate')->with('foo2Class')->willReturn($mockNode);
$mockSubject->create($data);
$subject = new NodeFactory();
self::assertInstanceOf(FooElement::class, ($subject->create($data)));
}
/**
......@@ -421,17 +411,11 @@ class NodeFactoryTest extends UnitTestCase
1433156887 => [
'nodeName' => 'foo',
'priority' => 10,
'class' => 'fooClass',
'class' => InvalidNodeResolverClass::class,
],
];
$mockResolver = $this->getMockBuilder(\stdClass::class)->getMock();
/** @var NodeFactory|\PHPUnit\Framework\MockObject\MockObject $mockSubject */
$mockSubject = $this->getMockBuilder(NodeFactory::class)
->setMethods(['instantiate'])
->getMock();
$mockSubject->expects(self::at(0))->method('instantiate')->willReturn($mockResolver);
$mockSubject->create($data);
$subject = new NodeFactory();
$subject->create($data);
}
/**
......@@ -444,7 +428,7 @@ class NodeFactoryTest extends UnitTestCase
[
'nodeName' => 'foo',
'priority' => 20,
'class' => \stdClass::class,
'class' => FooElement::class,
],
];
$mockNode = $this->createMock(NodeInterface::class);
......@@ -453,25 +437,16 @@ class NodeFactoryTest extends UnitTestCase
1433156887 => [
'nodeName' => 'foo',
'priority' => 10,
'class' => 'foo1Class',
'class' => FooResolver::class,
],
1433156888 => [
'nodeName' => 'foo',
'priority' => 30,
'class' => 'foo2Class',
'class' => BarResolver::class,
],
];
$mockResolver1 = $this->createMock(NodeResolverInterface::class);
$mockResolver2 = $this->createMock(NodeResolverInterface::class);
/** @var NodeFactory|\PHPUnit\Framework\MockObject\MockObject $mockSubject */
$mockSubject = $this->getMockBuilder(NodeFactory::class)
->setMethods(['instantiate'])
->getMock();
$mockSubject->expects(self::at(0))->method('instantiate')->with('foo2Class')->willReturn($mockResolver2);
$mockSubject->expects(self::at(1))->method('instantiate')->with('foo1Class')->willReturn($mockResolver1);
$mockSubject->expects(self::at(2))->method('instantiate')->willReturn($mockNode);
$mockSubject->create($data);
$subject = new NodeFactory();
self::assertInstanceOf(BarElement::class, ($subject->create($data)));
}
/**
......@@ -484,34 +459,24 @@ class NodeFactoryTest extends UnitTestCase
[
'nodeName' => 'foo',
'priority' => 20,
'class' => \stdClass::class,
'class' => FooElement::class,
],
];
$mockNode = $this->createMock(NodeInterface::class);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
1433156887 => [
'nodeName' => 'foo',
'priority' => 30,
'class' => 'foo1Class',
'class' => BarResolver::class,
],
1433156888 => [
'nodeName' => 'foo',
'priority' => 10,
'class' => 'foo2Class',
'class' => FooResolver::class,
],
];
$mockResolver1 = $this->createMock(NodeResolverInterface::class);
$mockResolver2 = $this->createMock(NodeResolverInterface::class);
/** @var NodeFactory|\PHPUnit\Framework\MockObject\MockObject $mockSubject */
$mockSubject = $this->getMockBuilder(NodeFactory::class)
->setMethods(['instantiate'])
->getMock();
$mockSubject->expects(self::at(0))->method('instantiate')->with('foo1Class')->willReturn($mockResolver1);
$mockSubject->expects(self::at(1))->method('instantiate')->with('foo2Class')->willReturn($mockResolver2);
$mockSubject->expects(self::at(2))->method('instantiate')->willReturn($mockNode);
$mockSubject->create($data);
$subject = new NodeFactory();
self::assertInstanceOf(BarElement::class, ($subject->create($data)));
}
/**
......@@ -524,66 +489,18 @@ class NodeFactoryTest extends UnitTestCase
[
'nodeName' => 'foo',
'priority' => 20,
'class' => \stdClass::class,
],
];
$mockNode = $this->createMock(NodeInterface::class);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
1433156887 => [
'nodeName' => 'foo',
'priority' => 30,
'class' => 'foo1Class',
],
];
$mockResolver1 = $this->createMock(NodeResolverInterface::class);
$mockResolver1->expects(self::once())->method('resolve')->willReturn('fooNodeClass');
/** @var NodeFactory|\PHPUnit\Framework\MockObject\MockObject $mockSubject */
$mockSubject = $this->getMockBuilder(NodeFactory::class)
->setMethods(['instantiate'])
->getMock();
$mockSubject->expects(self::at(0))->method('instantiate')->willReturn($mockResolver1);
$mockSubject->expects(self::at(1))->method('instantiate')->with('fooNodeClass')->willReturn($mockNode);
$mockSubject->create($data);
}
/**
* @test
*/
public function createDoesNotCallSecondResolverWithLowerPriorityIfFirstResolverReturnedClassName()
{
$data = ['renderType' => 'foo'];
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
[
'nodeName' => 'foo',
'priority' => 20,
'class' => \stdClass::class,
'class' => FooElement::class,
],
];
$mockNode = $this->createMock(NodeInterface::class);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
1433156887 => [
'nodeName' => 'foo',
'priority' => 30,
'class' => 'foo1Class',
],
1433156888 => [
'nodeName' => 'foo',
'priority' => 10,
'class' => 'foo2Class',
'class' => BarResolver::class,
],
];
$mockResolver1 = $this->createMock(NodeResolverInterface::class);
$mockResolver1->expects(self::once())->method('resolve')->willReturn('fooNodeClass');
/** @var NodeFactory|\PHPUnit\Framework\MockObject\MockObject $mockSubject */
$mockSubject = $this->getMockBuilder(NodeFactory::class)
->setMethods(['instantiate'])
->getMock();
$mockSubject->expects(self::at(0))->method('instantiate')->with('foo1Class')->willReturn($mockResolver1);
$mockSubject->expects(self::at(1))->method('instantiate')->with('fooNodeClass')->willReturn($mockNode);
$mockSubject->create($data);
$subject = new NodeFactory();
self::assertInstanceOf(BarElement::class, ($subject->create($data)));
}
}
......@@ -558,7 +558,7 @@ class RedisBackendTest extends FunctionalTestCase
public function getThrowsExceptionIfIdentifierIsNotAString()
{
$this->expectException(\InvalidArgumentException::class);
//@todo Add exception code with redis extension
// @todo Add exception code with redis extension
$subject = $this->setUpSubject();
$subject->get([]);
......
......@@ -496,7 +496,12 @@ class FileBackendTest extends UnitTestCase
self::assertFileExists($pathAndFilename);
$backend->remove($entryIdentifier);
self::assertFileNotExists($pathAndFilename);
// @todo remove condition and else branch as soon as phpunit v8 goes out of support
if (method_exists($this, 'assertFileDoesNotExist')) {
self::assertFileDoesNotExist($pathAndFilename);
} else {
self::assertFileNotExists($pathAndFilename);
}
}
public function invalidEntryIdentifiers(): array
......@@ -849,8 +854,14 @@ class FileBackendTest extends UnitTestCase
$backend->flush();
self::assertFileNotExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest1');
self::assertFileNotExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest2');
// @todo remove condition and else branch as soon as phpunit v8 goes out of support
if (method_exists($this, 'assertFileDoesNotExist')) {
self::assertFileDoesNotExist('vfs://Foo/cache/data/UnitTestCache/BackendFileTest1');
self::assertFileDoesNotExist('vfs://Foo/cache/data/UnitTestCache/BackendFileTest2');
} else {
self::assertFileNotExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest1');
self::assertFileNotExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest2');
}
}
/**
......@@ -888,9 +899,7 @@ class FileBackendTest extends UnitTestCase
'bar',
'baz'
]);
$backend->expects(self::at(1))->method('remove')->with('foo');
$backend->expects(self::at(2))->method('remove')->with('bar');
$backend->expects(self::at(3))->method('remove')->with('baz');
$backend->expects(self::exactly(3))->method('remove')->withConsecutive(['foo'], ['bar'], ['baz']);
$backend->flushByTag('UnitTestTag%special');
}
......@@ -923,7 +932,14 @@ class FileBackendTest extends UnitTestCase
self::assertFileExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest2');
$backend->collectGarbage();
self::assertFileNotExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest1');
// @todo remove condition and else branch as soon as phpunit v8 goes out of support
if (method_exists($this, 'assertFileDoesNotExist')) {
self::assertFileDoesNotExist('vfs://Foo/cache/data/UnitTestCache/BackendFileTest1');
} else {
self::assertFileNotExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest1');
}
self::assertFileExists('vfs://Foo/cache/data/UnitTestCache/BackendFileTest2');
}
......
......@@ -34,7 +34,7 @@ class WincacheBackendTest extends UnitTestCase
public function setThrowsExceptionIfNoFrontEndHasBeenSet()
{
$this->expectException(Exception::class);
//@todo Add exception code with wincache extension
// @todo Add exception code with wincache extension
$backend = new WincacheBackend('Testing');
$data = 'Some data';
......
......@@ -90,10 +90,12 @@ betterthanbefore: 2
// Accessible mock to $subject since getFileContents calls GeneralUtility methods
$subject = $this->getAccessibleMock(YamlFileLoader::class, ['getFileContents', 'getStreamlinedFileName']);
$subject->expects(self::at(0))->method('getStreamlinedFileName')->with($fileName)->willReturn($fileName);
$subject->expects(self::at(1))->method('getFileContents')->with($fileName)->willReturn($fileContents);
$subject->expects(self::at(2))->method('getStreamlinedFileName')->with($importFileName, $fileName)->willReturn($importFileName);
$subject->expects(self::at(3))->method('getFileContents')->with($importFileName)->willReturn($importFileContents);
$subject->expects(self::exactly(2))->method('getStreamlinedFileName')
->withConsecutive([$fileName], [$importFileName, $fileName])
->willReturn($fileName, $importFileName);
$subject->expects(self::exactly(2))->method('getFileContents')
->withConsecutive([$fileName], [$importFileName])
->willReturn($fileContents, $importFileContents);
$output = $subject->load($fileName);
self::assertSame($expected, $output);
}
......
......@@ -506,10 +506,10 @@ class SlugHelperTest extends UnitTestCase
$options