Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Update generated tests to phpunit 9 #441

Merged
merged 1 commit into from Aug 17, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,7 +24,7 @@ class BasicTest extends FunctionalTestCase
*
* @test
*/
public function dummy()
public function dummy(): void
{
$this->assertTrue(true);
}
Expand Down
Expand Up @@ -3,6 +3,9 @@ declare(strict_types=1);

namespace {extension.namespaceName}\Tests\Unit\Controller;

use PHPUnit\Framework\MockObject\MockObject;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;

/**
Expand All @@ -13,20 +16,20 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
class {controllerName}Test extends UnitTestCase
{
/**
* @var \{domainObject.controllerClassName}
* @var \{domainObject.controllerClassName}|MockObject|AccessibleObjectInterface
*/
protected $subject;

protected function setUp()
protected function setUp(): void
{
parent::setUp();
$this->subject = $this->getMockBuilder(\{domainObject.controllerClassName}::class)
->setMethods(['redirect', 'forward', 'addFlashMessage'])
$this->subject = $this->getMockBuilder($this->buildAccessibleProxy(\{domainObject.controllerClassName}::class))
->onlyMethods(['redirect', 'forward', 'addFlashMessage'])
->disableOriginalConstructor()
->getMock();
}

protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
}
Expand All @@ -36,35 +39,35 @@ class {controllerName}Test extends UnitTestCase
/**
* @test
*/
public function listActionFetchesAll{domainObject.name -> k:pluralize()}FromRepositoryAndAssignsThemToView()
public function listActionFetchesAll{domainObject.name -> k:pluralize()}FromRepositoryAndAssignsThemToView(): void
{
$all{domainObject.name -> k:pluralize()} = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class)
->disableOriginalConstructor()
->getMock();

${domainObject.name -> k:format.lowercaseFirst()}Repository = $this->getMockBuilder(\{domainObject.qualifiedDomainRepositoryClassName}::class)
->setMethods(['findAll'])
->onlyMethods(['findAll'])
->disableOriginalConstructor()
->getMock();
${domainObject.name -> k:format.lowercaseFirst()}Repository->expects(self::once())->method('findAll')->will(self::returnValue($all{domainObject.name -> k:pluralize()}));
$this->inject($this->subject, '{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository);
$this->subject->_set('{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository);

$view = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class)->getMock();
$view = $this->getMockBuilder(ViewInterface::class)->getMock();
$view->expects(self::once())->method('assign')->with('{domainObject.name -> k:pluralize() -> k:format.lowercaseFirst()}', $all{domainObject.name -> k:pluralize()});
$this->inject($this->subject, 'view', $view);
$this->subject->_set('view', $view);

$this->subject->listAction();
}</f:if><f:if condition="{k:matchString(match:'show', in:action.name)}">

/**
* @test
*/
public function showActionAssignsTheGiven{domainObject.name}ToView()
public function showActionAssignsTheGiven{domainObject.name}ToView(): void
{
${domainObject.name -> k:format.lowercaseFirst()} = new {domainObject.fullQualifiedClassName}();

$view = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class)->getMock();
$this->inject($this->subject, 'view', $view);
$view = $this->getMockBuilder(ViewInterface::class)->getMock();
$this->subject->_set('view', $view);
$view->expects(self::once())->method('assign')->with('{domainObject.name -> k:format.lowercaseFirst()}', ${domainObject.name -> k:format.lowercaseFirst()});

$this->subject->showAction(${domainObject.name -> k:format.lowercaseFirst()});
Expand All @@ -73,30 +76,30 @@ class {controllerName}Test extends UnitTestCase
/**
* @test
*/
public function createActionAddsTheGiven{domainObject.name}To{domainObject.name}Repository()
public function createActionAddsTheGiven{domainObject.name}To{domainObject.name}Repository(): void
{
${domainObject.name -> k:format.lowercaseFirst()} = new {domainObject.fullQualifiedClassName}();

${domainObject.name -> k:format.lowercaseFirst()}Repository = $this->getMockBuilder(\{domainObject.qualifiedDomainRepositoryClassName}::class)
->setMethods(['add'])
->onlyMethods(['add'])
->disableOriginalConstructor()
->getMock();

${domainObject.name -> k:format.lowercaseFirst()}Repository->expects(self::once())->method('add')->with(${domainObject.name -> k:format.lowercaseFirst()});
$this->inject($this->subject, '{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository);
$this->subject->_set('{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository);

$this->subject->createAction(${domainObject.name -> k:format.lowercaseFirst()});
}</f:if><f:if condition="{k:matchString(match:'edit', in:action.name)}">

/**
* @test
*/
public function editActionAssignsTheGiven{domainObject.name}ToView()
public function editActionAssignsTheGiven{domainObject.name}ToView(): void
{
${domainObject.name -> k:format.lowercaseFirst()} = new {domainObject.fullQualifiedClassName}();

$view = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class)->getMock();
$this->inject($this->subject, 'view', $view);
$view = $this->getMockBuilder(ViewInterface::class)->getMock();
$this->subject->_set('view', $view);
$view->expects(self::once())->method('assign')->with('{domainObject.name -> k:format.lowercaseFirst()}', ${domainObject.name -> k:format.lowercaseFirst()});

$this->subject->editAction(${domainObject.name -> k:format.lowercaseFirst()});
Expand All @@ -106,42 +109,42 @@ class {controllerName}Test extends UnitTestCase
/**
* @test
*/
public function updateActionUpdatesTheGiven{domainObject.name}In{domainObject.name}Repository()
public function updateActionUpdatesTheGiven{domainObject.name}In{domainObject.name}Repository(): void
{
${domainObject.name -> k:format.lowercaseFirst()} = new {domainObject.fullQualifiedClassName}();

${domainObject.name -> k:format.lowercaseFirst()}Repository = $this->getMockBuilder(\{domainObject.qualifiedDomainRepositoryClassName}::class)
->setMethods(['update'])
->onlyMethods(['update'])
->disableOriginalConstructor()
->getMock();

${domainObject.name -> k:format.lowercaseFirst()}Repository->expects(self::once())->method('update')->with(${domainObject.name -> k:format.lowercaseFirst()});
$this->inject($this->subject, '{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository);
$this->subject->_set('{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository);

$this->subject->updateAction(${domainObject.name -> k:format.lowercaseFirst()});
}</f:if><f:if condition="{k:matchString(match:'delete', in:action.name)}">

/**
* @test
*/
public function deleteActionRemovesTheGiven{domainObject.name}From{domainObject.name}Repository()
public function deleteActionRemovesTheGiven{domainObject.name}From{domainObject.name}Repository(): void
{
${domainObject.name -> k:format.lowercaseFirst()} = new {domainObject.fullQualifiedClassName}();

${domainObject.name -> k:format.lowercaseFirst()}Repository = $this->getMockBuilder(\{domainObject.qualifiedDomainRepositoryClassName}::class)
->setMethods(['remove'])
->onlyMethods(['remove'])
->disableOriginalConstructor()
->getMock();

${domainObject.name -> k:format.lowercaseFirst()}Repository->expects(self::once())->method('remove')->with(${domainObject.name -> k:format.lowercaseFirst()});
$this->inject($this->subject, '{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository);
$this->subject->_set('{domainObject.name -> k:format.lowercaseFirst()}Repository', ${domainObject.name -> k:format.lowercaseFirst()}Repository);

$this->subject->deleteAction(${domainObject.name -> k:format.lowercaseFirst()});
}</f:if></f:for><f:if condition="{domainObject.actions}"><f:then></f:then><f:else>
/**
* @test
*/
public function dummyTestToNotLeaveThisFileEmpty()
public function dummyTestToNotLeaveThisFileEmpty(): void
{
self::markTestIncomplete();
}</f:else></f:if>
Expand Down