Skip to content

Commit

Permalink
Improve testing on TYPO3 12
Browse files Browse the repository at this point in the history
  • Loading branch information
garbast committed May 29, 2023
1 parent b9d3177 commit fac590b
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 69 deletions.
4 changes: 2 additions & 2 deletions Build/Scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ runFunctionalTests () {
./runTests.sh -p ${PHP_VERSION} -s composerValidate || exit 1 ; \
EXIT_CODE_VALIDATE=$?

# ./runTests.sh -p ${PHP_VERSION} -d sqlite -s functional Tests/Functional || exit 1 ; \
# EXIT_CODE_FUNCTIONAL=$?
./runTests.sh -p ${PHP_VERSION} -d sqlite -s functional Tests/Functional || exit 1 ; \
EXIT_CODE_FUNCTIONAL=$?

./runTests.sh -p ${PHP_VERSION} -d sqlite -s unit Tests/Unit || exit 1 ; \
EXIT_CODE_FUNCTIONAL=$?
Expand Down
12 changes: 4 additions & 8 deletions Tests/Functional/AbstractTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function createRecord(string $tableName, array $insertArray): string
return $connection->lastInsertId($tableName);
}

public function loginFrontEndUser(int $frontEndUserUid)
public function loginFrontEndUser(int $frontEndUserUid): void
{
if ($frontEndUserUid === 0) {
throw new \InvalidArgumentException('The user ID must be > 0.', 1334439475);
Expand All @@ -176,7 +176,7 @@ public function loginFrontEndUser(int $frontEndUserUid)
$context->setAspect('frontend.user', $userAspect);
}

public function createEmptyFrontendUser()
public function createEmptyFrontendUser(): void
{
$this->frontendUser = GeneralUtility::makeInstance(FrontendUserAuthentication::class);

Expand All @@ -192,16 +192,12 @@ public function createEmptyFrontendUser()
public function getPrivateMethod($object, $methodName): \ReflectionMethod
{
$classReflection = new \ReflectionClass($object);
$methodReflection = $classReflection->getMethod($methodName);
$methodReflection->setAccessible(true);
return $methodReflection;
return $classReflection->getMethod($methodName);
}

public function getPrivateProperty($object, $propertyName): \ReflectionProperty
{
$classReflection = new \ReflectionClass($object);
$propertyReflection = $classReflection->getProperty($propertyName);
$propertyReflection->setAccessible(true);
return $propertyReflection;
return $classReflection->getProperty($propertyName);
}
}
16 changes: 8 additions & 8 deletions Tests/Functional/Controller/FeuserCreateControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
use Evoweb\SfRegister\Tests\Functional\AbstractTestBase;
use Evoweb\SfRegister\Tests\Functional\Mock\FeuserCreateController;
use Evoweb\SfRegister\Validation\Validator\UserValidator;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\Arguments;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Reflection\ReflectionService;
use TYPO3\CMS\Extbase\Validation\ValidatorResolver;
Expand All @@ -39,10 +41,8 @@ public function setUp(): void
$this->request = $this->initializeTypoScriptFrontendController();
}

/**
* @test
*/
public function isUserValidatorSet()
#[Test]
public function isUserValidatorSet(): void
{
$this->typoScriptFrontendController->tmpl->setup['plugin.']['tx_sfregister.']['settings.'] = [
'fields' => [
Expand Down Expand Up @@ -89,9 +89,9 @@ public function isUserValidatorSet()

/** @var Request $request */
$request = $this->getAccessibleMock(Request::class);
$request->setArgument('action', 'preview');
$request->setArgument('controller', 'FeuserCreate');
$request->setArgument('user', [
$request = $request->withArgument('action', 'preview');
$request = $request->withArgument('controller', 'FeuserCreate');
$request = $request->withArgument('user', [
'gender' => 1,
'title' => 'none',
'firstName' => '',
Expand All @@ -116,7 +116,7 @@ public function isUserValidatorSet()
$subject->call('initializeActionMethodArguments');
$subject->call('initializeActionMethodValidators');

/** @var \TYPO3\CMS\Extbase\Mvc\Controller\Arguments $arguments */
/** @var Arguments $arguments */
$arguments = $subject->get('arguments');
$validator = $arguments->getArgument('user')->getValidator();

Expand Down
19 changes: 7 additions & 12 deletions Tests/Functional/Controller/FeuserPasswordControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Evoweb\SfRegister\Services\File;
use Evoweb\SfRegister\Services\Session;
use Evoweb\SfRegister\Tests\Functional\AbstractTestBase;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\NullLogger;
use TYPO3\CMS\Core\Context\Context;
Expand All @@ -40,10 +41,8 @@ public function setUp(): void
$this->importCSVDataSet(__DIR__ . '/../Fixtures/fe_users.csv');
}

/**
* @test
*/
public function userIsLoggedInReturnsFalseIfNotLoggedIn()
#[Test]
public function userIsLoggedInReturnsFalseIfNotLoggedIn(): void
{
$this->createEmptyFrontendUser();
$this->request = $this->initializeTypoScriptFrontendController();
Expand Down Expand Up @@ -82,10 +81,8 @@ public function userIsLoggedInReturnsFalseIfNotLoggedIn()
self::assertFalse($method->invoke($subject));
}

/**
* @test
*/
public function userIsLoggedInReturnsTrueIfLoggedIn()
#[Test]
public function userIsLoggedInReturnsTrueIfLoggedIn(): void
{
$this->createAndLoginFrontEndUser('2', [
'password' => 'testOld',
Expand Down Expand Up @@ -127,10 +124,8 @@ public function userIsLoggedInReturnsTrueIfLoggedIn()
self::assertTrue($method->invoke($subject));
}

/**
* @test
*/
public function saveActionFetchUserObjectIfLoggedInSetsThePasswordAndCallsUpdateOnUserRepository()
#[Test]
public function saveActionFetchUserObjectIfLoggedInSetsThePasswordAndCallsUpdateOnUserRepository(): void
{
if (!defined('PASSWORD_ARGON2I')) {
self::markTestSkipped('Due to missing Argon2 in travisci.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Evoweb\SfRegister\Domain\Model\FrontendUser;
use Evoweb\SfRegister\Domain\Repository\FrontendUserRepository;
use Evoweb\SfRegister\Tests\Functional\AbstractTestBase;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class FrontendUserRepositoryTest extends AbstractTestBase
Expand All @@ -35,12 +36,11 @@ public function setUp(): void
public function tearDown(): void
{
unset($this->subject);
parent::tearDown();
}

/**
* @test
*/
public function findByUid()
#[Test]
public function findByUid(): void
{
/** @var FrontendUser $user */
$user = $this->subject->findByUid(1);
Expand Down
7 changes: 5 additions & 2 deletions Tests/Functional/Mock/FeuserCreateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Evoweb\SfRegister\Tests\Functional\Mock;

class FeuserCreateController extends \Evoweb\SfRegister\Controller\FeuserCreateController
use Evoweb\SfRegister\Controller\FeuserCreateController as BaseFeuserCreateController;
use Evoweb\SfRegister\Tests\Functional\SettableCallable;

class FeuserCreateController extends BaseFeuserCreateController
{
use \Evoweb\SfRegister\Tests\Functional\SettableCallable;
use SettableCallable;
}
11 changes: 3 additions & 8 deletions Tests/Functional/SettableCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@

trait SettableCallable
{
/**
* @param string $name
*
* @return mixed
*/
public function get(string $name)
public function get(string $name): mixed
{
return $this->{$name};
}

public function set(string $name, $value)
public function set(string $name, mixed $value): void
{
$this->{$name} = $value;
}

public function call(string $name)
public function call(string $name): void
{
$this->{$name}();
}
Expand Down
22 changes: 9 additions & 13 deletions Tests/Functional/Validation/Validator/BadWordValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Evoweb\SfRegister\Tests\Functional\AbstractTestBase;
use Evoweb\SfRegister\Validation\Validator\BadWordValidator;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -52,25 +53,22 @@ public function setUp(): void
public function tearDown(): void
{
unset($this->subject);
parent::tearDown();
}

/**
* @test
*/
public function settingsContainsValidTyposcriptSettings()
#[Test]
public function settingsContainsValidTyposcriptSettings(): void
{
self::assertArrayHasKey(
'badWordList',
$this->subject->_get('settings')
);
}

/**
* @test
*/
public function isValidReturnsFalseForWordOnBadwordlist()
#[Test]
public function isValidReturnsFalseForWordOnBadwordlist(): void
{
$controller = $this->request->getAttribute('frontend.controller', null);
$controller = $this->request->getAttribute('frontend.controller');
$words = GeneralUtility::trimExplode(
',',
$controller->tmpl->setup['plugin.']['tx_sfregister.']['settings.']['badWordList']
Expand All @@ -81,10 +79,8 @@ public function isValidReturnsFalseForWordOnBadwordlist()
self::assertTrue($this->subject->validate(current($words))->hasErrors());
}

/**
* @test
*/
public function isValidReturnsTrueForGoodPassword()
#[Test]
public function isValidReturnsTrueForGoodPassword(): void
{
self::assertFalse($this->subject->validate('4dw$koL')->hasErrors());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Evoweb\SfRegister\Domain\Repository\FrontendUserRepository;
use Evoweb\SfRegister\Tests\Functional\AbstractTestBase;
use Evoweb\SfRegister\Validation\Validator\EqualCurrentPasswordValidator;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -34,10 +35,8 @@ public function setUp(): void
$this->request = $this->initializeTypoScriptFrontendController();
}

/**
* @test
*/
public function settingsContainsValidTyposcriptSettings()
#[Test]
public function settingsContainsValidTyposcriptSettings(): void
{
$typoScriptSetup = $this->request->getAttribute('frontend.typoscript')->getSetupArray();
self::assertArrayHasKey(
Expand All @@ -46,10 +45,8 @@ public function settingsContainsValidTyposcriptSettings()
);
}

/**
* @test
*/
public function isUserLoggedInReturnsFalseIfNotLoggedIn()
#[Test]
public function isUserLoggedInReturnsFalseIfNotLoggedIn(): void
{
/** @var Context $context */
$context = GeneralUtility::makeInstance(Context::class);
Expand All @@ -66,10 +63,8 @@ public function isUserLoggedInReturnsFalseIfNotLoggedIn()
self::assertFalse($method->invoke($subject));
}

/**
* @test
*/
public function isUserLoggedInReturnsTrueIfLoggedIn()
#[Test]
public function isUserLoggedInReturnsTrueIfLoggedIn(): void
{
$this->createAndLoginFrontEndUser('2', [
'password' => 'testOld',
Expand Down
1 change: 1 addition & 0 deletions Tests/Unit/Domain/Model/PasswordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function setUp(): void
public function tearDown(): void
{
unset($this->subject);
parent::tearDown();
}

#[Test]
Expand Down
1 change: 1 addition & 0 deletions Tests/Unit/Validation/Validator/IsTrueValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function setUp(): void
public function tearDown(): void
{
unset($this->subject);
parent::tearDown();
}

#[Test]
Expand Down

0 comments on commit fac590b

Please sign in to comment.