Release 2.36.0 (#5514)
This commit is contained in:
@@ -251,7 +251,7 @@ class TimesheetValidationTest extends KernelTestCase
|
||||
$entity->setBegin($begin);
|
||||
$entity->setEnd($end);
|
||||
|
||||
$this->assertHasViolationForField($entity, 'end_date');
|
||||
$this->assertHasViolationForField($entity, ['end_date', 'duration']);
|
||||
|
||||
// allow same begin and end
|
||||
$entity = $this->getEntity();
|
||||
|
||||
@@ -65,6 +65,9 @@ class TimesheetServiceTest extends TestCase
|
||||
return $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testCannotSavePersistedTimesheetAsNew(): void
|
||||
{
|
||||
$timesheet = $this->createMock(Timesheet::class);
|
||||
@@ -75,7 +78,7 @@ class TimesheetServiceTest extends TestCase
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Cannot create timesheet, already persisted');
|
||||
|
||||
$sut->saveNewTimesheet($timesheet);
|
||||
$sut->saveNewTimesheet($timesheet); // @phpstan-ignore method.deprecated
|
||||
}
|
||||
|
||||
public function testCannotStartTimesheet(): void
|
||||
@@ -88,7 +91,7 @@ class TimesheetServiceTest extends TestCase
|
||||
$this->expectException(AccessDeniedHttpException::class);
|
||||
$this->expectExceptionMessage('You are not allowed to start this timesheet record');
|
||||
|
||||
$sut->saveNewTimesheet(new Timesheet());
|
||||
$sut->saveTimesheet(new Timesheet());
|
||||
}
|
||||
|
||||
public function testSaveNewTimesheetHasValidationError(): void
|
||||
@@ -107,7 +110,7 @@ class TimesheetServiceTest extends TestCase
|
||||
$this->expectException(ValidationFailedException::class);
|
||||
$this->expectExceptionMessage('Validation Failed');
|
||||
|
||||
$sut->saveNewTimesheet(new Timesheet());
|
||||
$sut->saveTimesheet(new Timesheet());
|
||||
}
|
||||
|
||||
public function testSaveNewTimesheetStopsActiveRecords(): void
|
||||
@@ -134,7 +137,7 @@ class TimesheetServiceTest extends TestCase
|
||||
|
||||
$sut = $this->getSut($authorizationChecker, null, null, $repository);
|
||||
|
||||
$sut->saveNewTimesheet($newTimesheet);
|
||||
$sut->saveTimesheet($newTimesheet);
|
||||
}
|
||||
|
||||
public function testSaveNewTimesheetFixesTimezone(): void
|
||||
@@ -155,11 +158,14 @@ class TimesheetServiceTest extends TestCase
|
||||
$authorizationChecker->expects($this->once())->method('isGranted')->willReturn(true);
|
||||
$sut = $this->getSut($authorizationChecker);
|
||||
|
||||
$sut->saveNewTimesheet($timesheet);
|
||||
$sut->saveTimesheet($timesheet);
|
||||
|
||||
self::assertEquals('Europe/Paris', $timesheet->getTimezone());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testUpdateTimesheetFixesTimezone(): void
|
||||
{
|
||||
$user = new User();
|
||||
@@ -176,7 +182,7 @@ class TimesheetServiceTest extends TestCase
|
||||
|
||||
$sut = $this->getSut();
|
||||
|
||||
$sut->updateTimesheet($timesheet);
|
||||
$sut->updateTimesheet($timesheet); // @phpstan-ignore method.deprecated
|
||||
|
||||
self::assertEquals('Europe/Paris', $timesheet->getTimezone());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?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\Validator\Constraints;
|
||||
|
||||
use App\Validator\Constraints\TimesheetConstraint;
|
||||
use App\Validator\Constraints\TimesheetNegativeDuration;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Validator\Constraints\TimesheetNegativeDuration
|
||||
*/
|
||||
class TimesheetNegativeDurationTest extends TestCase
|
||||
{
|
||||
public function testIsTimesheetConstraint(): void
|
||||
{
|
||||
self::assertInstanceOf(TimesheetConstraint::class, new TimesheetNegativeDuration());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?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\Validator\Constraints;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Validator\Constraints\TimesheetNegativeDuration;
|
||||
use App\Validator\Constraints\TimesheetNegativeDurationValidator;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Validator\Constraints\TimesheetNegativeDuration
|
||||
* @covers \App\Validator\Constraints\TimesheetNegativeDurationValidator
|
||||
* @extends ConstraintValidatorTestCase<TimesheetNegativeDurationValidator>
|
||||
*/
|
||||
class TimesheetNegativeDurationValidatorTest extends ConstraintValidatorTestCase
|
||||
{
|
||||
protected function createValidator(): TimesheetNegativeDurationValidator
|
||||
{
|
||||
return new TimesheetNegativeDurationValidator();
|
||||
}
|
||||
|
||||
public function testConstraintIsInvalid(): void
|
||||
{
|
||||
$this->expectException(UnexpectedTypeException::class);
|
||||
|
||||
$this->validator->validate(new Timesheet(), new NotBlank());
|
||||
}
|
||||
|
||||
public function testInvalidValueThrowsException(): void
|
||||
{
|
||||
$this->expectException(UnexpectedTypeException::class);
|
||||
|
||||
$this->validator->validate(new NotBlank(), new TimesheetNegativeDuration(['message' => 'Duration cannot be negative.']));
|
||||
}
|
||||
|
||||
public function testNegativeDurationIsNotAllowed(): void
|
||||
{
|
||||
$begin = new \DateTime();
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet->setBegin(clone $begin);
|
||||
$timesheet->setEnd(clone $begin);
|
||||
$timesheet->setBreak(3600);
|
||||
|
||||
$this->validator->validate($timesheet, new TimesheetNegativeDuration(['message' => 'Duration cannot be negative.']));
|
||||
|
||||
$this->buildViolation('Duration cannot be negative.')
|
||||
->atPath('property.path.duration')
|
||||
->setCode(TimesheetNegativeDuration::NEGATIVE_DURATION_ERROR)
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testZeroDurationIsAllowed(): void
|
||||
{
|
||||
$begin = new \DateTime();
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet->setBegin(clone $begin);
|
||||
$timesheet->setEnd(clone $begin);
|
||||
|
||||
$this->validator = $this->createValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
|
||||
$this->validator->validate($timesheet, new TimesheetNegativeDuration(['message' => 'Duration cannot be negative.']));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testDoesNotTriggerOnRunningTimesheet(): void
|
||||
{
|
||||
$begin = new \DateTime();
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet->setBegin(clone $begin);
|
||||
$timesheet->setBreak(3600);
|
||||
|
||||
$this->validator = $this->createValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
|
||||
$this->validator->validate($timesheet, new TimesheetNegativeDuration(['message' => 'Duration cannot be negative.']));
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ class ValidationExceptionTest extends TestCase
|
||||
{
|
||||
$sut = new ValidationException();
|
||||
self::assertEquals(400, $sut->getCode());
|
||||
self::assertEquals('Validation failed', $sut->getMessage());
|
||||
self::assertEquals('Validation Failed', $sut->getMessage());
|
||||
}
|
||||
|
||||
public function testConstruct(): void
|
||||
|
||||
@@ -23,7 +23,7 @@ class ValidationFailedExceptionTest extends TestCase
|
||||
$list = new ConstraintViolationList();
|
||||
$sut = new ValidationFailedException($list);
|
||||
self::assertEquals(400, $sut->getCode());
|
||||
self::assertEquals('Validation failed', $sut->getMessage());
|
||||
self::assertEquals('Validation Failed', $sut->getMessage());
|
||||
self::assertSame($list, $sut->getViolations());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user