Skip to content

Commit

Permalink
use default_begin in duration only mode (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpapst authored Jun 19, 2019
1 parent dcdbf23 commit bdd05a2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/Timesheet/TrackingMode/DurationOnlyMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace App\Timesheet\TrackingMode;

use App\Entity\Timesheet;
use Symfony\Component\HttpFoundation\Request;

class DurationOnlyMode extends AbstractTrackingMode
{
public function canEditBegin(): bool
Expand Down Expand Up @@ -40,4 +43,15 @@ public function canSeeBeginAndEndTimes(): bool
{
return false;
}

public function create(Timesheet $timesheet, Request $request): void
{
if (null === $timesheet->getBegin()) {
$timesheet->setBegin($this->dateTime->createDateTime());
}

$timesheet->getBegin()->modify($this->configuration->getDefaultBeginTime());

parent::create($timesheet, $request);
}
}
11 changes: 8 additions & 3 deletions tests/Timesheet/TrackingMode/AbstractTrackingModeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ abstract class AbstractTrackingModeTest extends TestCase
*/
abstract protected function createSut();

protected function assertDefaultBegin(Timesheet $timesheet)
{
self::assertNull($timesheet->getBegin());
}

public function testCreateDoesNotChangeAnythingOnEmptyRequest()
{
$sut = $this->createSut();
Expand All @@ -35,7 +40,7 @@ public function testCreateDoesNotChangeAnythingOnEmptyRequest()

$sut->create($timesheet, new Request());

self::assertNull($timesheet->getBegin());
$this->assertDefaultBegin($timesheet);
self::assertNull($timesheet->getEnd());
}

Expand Down Expand Up @@ -88,7 +93,7 @@ public function testCreateIgnoresValidEndOnInvalidBeginDateFromRequest()

$sut->create($timesheet, $request);

self::assertNull($timesheet->getBegin());
$this->assertDefaultBegin($timesheet);
self::assertNull($timesheet->getEnd());
self::assertEquals(0, $timesheet->getDuration());
}
Expand Down Expand Up @@ -181,7 +186,7 @@ public function testCreateIgnoresValidToOnInvalidFromDatetimeFromRequest()

$sut->create($timesheet, $request);

self::assertNull($timesheet->getBegin());
$this->assertDefaultBegin($timesheet);
self::assertNull($timesheet->getEnd());
self::assertEquals(0, $timesheet->getDuration());
}
Expand Down
9 changes: 8 additions & 1 deletion tests/Timesheet/TrackingMode/DurationOnlyModeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace App\Tests\Timesheet\TrackingMode;

use App\Configuration\TimesheetConfiguration;
use App\Entity\Timesheet;
use App\Tests\Configuration\TestConfigLoader;
use App\Tests\Mocks\Security\UserDateTimeFactoryFactory;
use App\Timesheet\TrackingMode\DurationOnlyMode;
Expand All @@ -19,11 +20,17 @@
*/
class DurationOnlyModeTest extends AbstractTrackingModeTest
{
protected function assertDefaultBegin(Timesheet $timesheet)
{
self::assertNotNull($timesheet->getBegin());
self::assertEquals('13:45:37', $timesheet->getBegin()->format('H:i:s'));
}

protected function createSut()
{
$loader = new TestConfigLoader([]);
$dateTime = (new UserDateTimeFactoryFactory($this))->create();
$configuration = new TimesheetConfiguration($loader, []);
$configuration = new TimesheetConfiguration($loader, ['default_begin' => '13:45:37']);

return new DurationOnlyMode($dateTime, $configuration);
}
Expand Down

0 comments on commit bdd05a2

Please sign in to comment.