Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -14,14 +14,8 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
abstract class AbstractMockFactory
|
||||
{
|
||||
/**
|
||||
* @var TestCase
|
||||
*/
|
||||
private $testCase;
|
||||
|
||||
public function __construct(TestCase $testCase)
|
||||
public function __construct(private TestCase $testCase)
|
||||
{
|
||||
$this->testCase = $testCase;
|
||||
}
|
||||
|
||||
protected function getTestCase(): TestCase
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace App\Tests\Mocks;
|
||||
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Tests\Configuration\TestConfigLoader;
|
||||
use App\Timesheet\Rounding\CeilRounding;
|
||||
use App\Timesheet\Rounding\ClosestRounding;
|
||||
@@ -35,7 +34,7 @@ class RoundingServiceFactory extends AbstractMockFactory
|
||||
];
|
||||
}
|
||||
|
||||
$configuration = new SystemConfiguration($loader, [
|
||||
$configuration = SystemConfigurationFactory::create($loader, [
|
||||
'timesheet' => ['rounding' => $rules]
|
||||
]);
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
namespace App\Tests\Mocks\Saml;
|
||||
|
||||
use App\Configuration\SamlConfiguration;
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Saml\SamlAuthFactory;
|
||||
use App\Tests\Configuration\TestConfigLoader;
|
||||
use App\Tests\Mocks\AbstractMockFactory;
|
||||
use App\Tests\Mocks\SystemConfigurationFactory;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
@@ -87,7 +87,7 @@ class SamlAuthFactoryFactory extends AbstractMockFactory
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($request);
|
||||
|
||||
$configuration = new SystemConfiguration(new TestConfigLoader([]), [
|
||||
$configuration = SystemConfigurationFactory::create(new TestConfigLoader([]), [
|
||||
'saml' => ['connection' => $connection]
|
||||
]);
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Mocks\Security;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserPreference;
|
||||
use App\Security\CurrentUser;
|
||||
use App\Tests\Mocks\AbstractMockFactory;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
|
||||
class CurrentUserFactory extends AbstractMockFactory
|
||||
{
|
||||
public function create(User $user, ?string $timezone = null): CurrentUser
|
||||
{
|
||||
return $this->getCurrentUserMock($user, $timezone);
|
||||
}
|
||||
|
||||
protected function getCurrentUserMock(User $user, ?string $timezone = null)
|
||||
{
|
||||
if (null !== $timezone) {
|
||||
$pref = new UserPreference();
|
||||
$pref->setName('timezone');
|
||||
$pref->setValue($timezone);
|
||||
$user->addPreference($pref);
|
||||
}
|
||||
|
||||
$mock = $this->getMockBuilder(UsernamePasswordToken::class)->onlyMethods(['getUser'])->disableOriginalConstructor()->getMock();
|
||||
$mock->method('getUser')->willReturn($user);
|
||||
/** @var UsernamePasswordToken $token */
|
||||
$token = $mock;
|
||||
|
||||
$tokenStorage = new TokenStorage();
|
||||
$tokenStorage->setToken($token);
|
||||
|
||||
return new CurrentUser($tokenStorage);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ use App\Tests\Mocks\AbstractMockFactory;
|
||||
class RoleServiceFactory extends AbstractMockFactory
|
||||
{
|
||||
/**
|
||||
* @param array<string, array<string>>|null $roles
|
||||
* @param array<string>|null $roles
|
||||
* @param Role[]|null $repositoryRoles
|
||||
* @return RoleService
|
||||
*/
|
||||
@@ -26,10 +26,10 @@ class RoleServiceFactory extends AbstractMockFactory
|
||||
{
|
||||
if (null === $roles) {
|
||||
$roles = [
|
||||
User::ROLE_USER => [],
|
||||
User::ROLE_TEAMLEAD => [User::ROLE_USER],
|
||||
User::ROLE_ADMIN => [User::ROLE_TEAMLEAD],
|
||||
User::ROLE_SUPER_ADMIN => [User::ROLE_ADMIN],
|
||||
User::ROLE_USER,
|
||||
User::ROLE_TEAMLEAD,
|
||||
User::ROLE_ADMIN,
|
||||
User::ROLE_SUPER_ADMIN,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
54
tests/Mocks/SystemConfigurationFactory.php
Normal file
54
tests/Mocks/SystemConfigurationFactory.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Mocks;
|
||||
|
||||
use App\Configuration\ConfigLoaderInterface;
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Tests\Configuration\TestConfigLoader;
|
||||
|
||||
class SystemConfigurationFactory
|
||||
{
|
||||
/**
|
||||
* @param array<mixed> $settings
|
||||
* @return SystemConfiguration
|
||||
*/
|
||||
public static function create(ConfigLoaderInterface $repository, array $settings): SystemConfiguration
|
||||
{
|
||||
return new SystemConfiguration($repository, self::flatten($settings));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed> $settings
|
||||
* @return SystemConfiguration
|
||||
*/
|
||||
public static function createStub(array $settings = []): SystemConfiguration
|
||||
{
|
||||
return new SystemConfiguration(new TestConfigLoader([]), self::flatten($settings));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed> $settings
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function flatten(array $settings): array
|
||||
{
|
||||
$iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($settings));
|
||||
$newConfig = [];
|
||||
foreach ($iterator as $value) {
|
||||
$keys = [];
|
||||
foreach (range(0, $iterator->getDepth()) as $depth) {
|
||||
$keys[] = $iterator->getSubIterator($depth)->key();
|
||||
}
|
||||
$newConfig[implode('.', $keys)] = $value;
|
||||
}
|
||||
|
||||
return $newConfig;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace App\Tests\Mocks;
|
||||
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Timesheet\TimesheetService;
|
||||
use App\Timesheet\TrackingModeService;
|
||||
@@ -21,7 +20,7 @@ class TimesheetServiceFactory extends AbstractMockFactory
|
||||
{
|
||||
public function create(): TimesheetService
|
||||
{
|
||||
$configuration = $this->createMock(SystemConfiguration::class);
|
||||
$configuration = SystemConfigurationFactory::createStub();
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
$repository->method('getActiveEntries')->willReturn([]);
|
||||
$service = new TrackingModeService($configuration, []);
|
||||
|
||||
@@ -9,11 +9,9 @@
|
||||
|
||||
namespace App\Tests\Mocks;
|
||||
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Tests\Configuration\TestConfigLoader;
|
||||
use App\Timesheet\TrackingMode\DefaultMode;
|
||||
use App\Timesheet\TrackingMode\DurationFixedBeginMode;
|
||||
use App\Timesheet\TrackingMode\DurationOnlyMode;
|
||||
use App\Timesheet\TrackingMode\PunchInOutMode;
|
||||
use App\Timesheet\TrackingModeService;
|
||||
|
||||
@@ -27,13 +25,12 @@ class TrackingModeServiceFactory extends AbstractMockFactory
|
||||
|
||||
$loader = new TestConfigLoader([]);
|
||||
|
||||
$configuration = new SystemConfiguration($loader, ['timesheet' => ['mode' => $mode]]);
|
||||
$configuration = SystemConfigurationFactory::create($loader, ['timesheet' => ['mode' => $mode]]);
|
||||
|
||||
if (null === $modes) {
|
||||
$modes = [
|
||||
new DefaultMode((new RoundingServiceFactory($this->getTestCase()))->create()),
|
||||
new PunchInOutMode(),
|
||||
new DurationOnlyMode($configuration),
|
||||
new DurationFixedBeginMode($configuration),
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user