Release 1.19.7 (#3286)

* fix isWeekend() test for sunday fdow
* re-use the pattern for optgroup title
* prevent method on null
* composer update
* pre-select an option if it is the only available one
* added command to stop all active timesheets
This commit is contained in:
Kevin Papst
2022-05-07 23:47:32 +02:00
committed by GitHub
parent 100f8a5165
commit c8098b2e00
31 changed files with 818 additions and 484 deletions

View File

@@ -0,0 +1,58 @@
<?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\Command;
use App\Command\TimesheetStopAllCommand;
use App\Tests\Mocks\TimesheetServiceFactory;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
/**
* @covers \App\Command\TimesheetStopAllCommand
* @group integration
*/
class TimesheetStopAllCommandTest extends KernelTestCase
{
/**
* @var Application
*/
protected $application;
protected function setUp(): void
{
$factory = new TimesheetServiceFactory($this);
$service = $factory->create();
parent::setUp();
$kernel = self::bootKernel();
$this->application = new Application($kernel);
$this->application->add(new TimesheetStopAllCommand($service));
}
public function testCommandName()
{
$command = $this->application->find('kimai:timesheet:stop-all');
self::assertInstanceOf(TimesheetStopAllCommand::class, $command);
}
public function testRun()
{
$command = $this->application->find('kimai:timesheet:stop-all');
$commandTester = new CommandTester($command);
$commandTester->execute(['command' => $command->getName()]);
$result = $commandTester->getDisplay();
self::assertStringContainsString('[OK] Stopped 0 timesheet records.', $result);
self::assertEquals(0, $commandTester->getStatusCode());
}
}

View File

@@ -88,6 +88,7 @@ class InvoiceModelTest extends TestCase
self::assertNull($sut->getDueDate());
self::assertInstanceOf(InvoiceModel::class, $sut->setTemplate($template));
self::assertSame($template, $sut->getTemplate());
/* @phpstan-ignore-next-line */
self::assertInstanceOf(\DateTime::class, $sut->getDueDate());
}

View File

@@ -29,6 +29,11 @@ abstract class AbstractMockFactory
return $this->testCase;
}
protected function createMock(string $className)
{
return $this->getMockBuilder($className)->disableOriginalConstructor()->getMock();
}
protected function getMockBuilder(string $className): MockBuilder
{
return new MockBuilder($this->testCase, $className);

View File

@@ -0,0 +1,34 @@
<?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\SystemConfiguration;
use App\Repository\TimesheetRepository;
use App\Timesheet\TimesheetService;
use App\Timesheet\TrackingModeService;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
class TimesheetServiceFactory extends AbstractMockFactory
{
public function create(): TimesheetService
{
$configuration = $this->createMock(SystemConfiguration::class);
$repository = $this->createMock(TimesheetRepository::class);
$repository->method('getActiveEntries')->willReturn([]);
$service = new TrackingModeService($configuration, []);
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$security = $this->createMock(AuthorizationCheckerInterface::class);
$validator = $this->createMock(ValidatorInterface::class);
return new TimesheetService($configuration, $repository, $service, $dispatcher, $security, $validator);
}
}

View File

@@ -341,10 +341,8 @@ class BaseQueryTest extends TestCase
$dateRange->setEnd($end);
self::assertSame($begin, $sut->getDateRange()->getBegin());
/* @phpstan-ignore-next-line */
self::assertSame($begin, $sut->getBegin());
self::assertSame($end, $sut->getDateRange()->getEnd());
/* @phpstan-ignore-next-line */
self::assertSame($end, $sut->getEnd());
}
}

View File

@@ -96,6 +96,7 @@ class TimesheetRepositoryTest extends AbstractRepositoryTest
$result = $repository->stopRecording($timesheet);
$this->assertTrue($result);
/* @phpstan-ignore-next-line */
$this->assertInstanceOf(\DateTime::class, $timesheet->getEnd());
}

View File

@@ -12,6 +12,7 @@ namespace App\Tests\Twig;
use App\Configuration\LanguageFormattings;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Entity\UserPreference;
use App\Twig\LocaleFormatExtensions;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Intl\Util\IntlTestHelper;
@@ -35,9 +36,10 @@ class LocaleFormatExtensionsTest extends TestCase
/**
* @param string|array $locale
* @param array|string $dateSettings
* @param bool $fdowSunday
* @return LocaleFormatExtensions
*/
protected function getSut($locale, $dateSettings)
protected function getSut($locale, $dateSettings, $fdowSunday = false)
{
$language = $locale;
if (\is_array($locale)) {
@@ -45,8 +47,10 @@ class LocaleFormatExtensionsTest extends TestCase
$dateSettings = $locale;
}
$user = new User();
$user->setPreferenceValue(UserPreference::FIRST_WEEKDAY, ($fdowSunday ? 'sunday' : 'monday'));
$security = $this->createMock(Security::class);
$security->expects($this->any())->method('getUser')->willReturn(new User());
$security->expects($this->any())->method('getUser')->willReturn($user);
$sut = new LocaleFormatExtensions(new LanguageFormattings($dateSettings), $security);
$sut->setLocale($language);
@@ -519,9 +523,8 @@ class LocaleFormatExtensionsTest extends TestCase
$this->assertEquals('0.00', $sut->durationDecimal(null));
}
private function getTest(string $name): TwigTest
private function getTest(LocaleFormatExtensions $sut, string $name): TwigTest
{
$sut = $this->getSut('en', $this->localeEn);
foreach ($sut->getTests() as $test) {
if ($test->getName() === $name) {
return $test;
@@ -533,7 +536,8 @@ class LocaleFormatExtensionsTest extends TestCase
public function testIsToday()
{
$test = $this->getTest('today');
$sut = $this->getSut('en', $this->localeEn);
$test = $this->getTest($sut, 'today');
self::assertTrue(\call_user_func($test->getCallable(), new \DateTime()));
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('-1 day')));
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('+1 day')));
@@ -543,11 +547,27 @@ class LocaleFormatExtensionsTest extends TestCase
public function testIsWeekend()
{
$test = $this->getTest('weekend');
$sut = $this->getSut('en', $this->localeEn, false);
$test = $this->getTest($sut, 'weekend');
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first monday this month')));
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first tuesday this month')));
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first wednesday this month')));
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first thursday this month')));
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first friday this month')));
self::assertTrue(\call_user_func($test->getCallable(), new \DateTime('first saturday this month')));
self::assertTrue(\call_user_func($test->getCallable(), new \DateTime('first sunday this month')));
self::assertFalse(\call_user_func($test->getCallable(), new \stdClass()));
self::assertFalse(\call_user_func($test->getCallable(), null));
$sut = $this->getSut('en', $this->localeEn, true);
$test = $this->getTest($sut, 'weekend');
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first monday this month')));
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first friday this month')));
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first tuesday this month')));
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first wednesday this month')));
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first thursday this month')));
self::assertTrue(\call_user_func($test->getCallable(), new \DateTime('first friday this month')));
self::assertTrue(\call_user_func($test->getCallable(), new \DateTime('first saturday this month')));
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first sunday this month')));
self::assertFalse(\call_user_func($test->getCallable(), new \stdClass()));
self::assertFalse(\call_user_func($test->getCallable(), null));
}

View File

@@ -8,8 +8,6 @@ includes:
parameters:
tmpDir: %rootDir%/../../../var/cache/phpstan
ignoreErrors:
- '#Call to static method PHPUnit\\Framework\\Assert::assertSame\(\) with App\\Entity\\[a-zA-Z0-9]+ and null will always evaluate to false.#'
excludePaths:
- %rootDir%/../../../tests/Ldap/LdapDriverTest.php
inferPrivatePropertyTypeFromConstructor: true