2020-10-20 21:41:19 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Tests\Entity;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use App\Entity\Entry;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers App\Entity\Entry
|
|
|
|
*/
|
|
|
|
class EntryTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2020-10-20 22:52:46 +02:00
|
|
|
public function canBeCreatedViaConstructor(): void
|
2020-10-20 21:41:19 +02:00
|
|
|
{
|
|
|
|
$subject = new Entry();
|
|
|
|
|
|
|
|
static::assertInstanceOf(Entry::class, $subject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2020-10-20 22:52:46 +02:00
|
|
|
public function canBeCreatedFromPersistence(): void
|
|
|
|
{
|
|
|
|
$subject = Entry::fromPersistence(
|
|
|
|
'Example Title',
|
|
|
|
new \DateTimeImmutable('2020-10-29 17:10:05'),
|
|
|
|
new \DateTimeImmutable('2020-10-29 18:12:15')
|
|
|
|
);
|
|
|
|
|
|
|
|
static::assertInstanceOf(Entry::class, $subject);
|
|
|
|
static::assertSame('Example Title', $subject->getTitle());
|
|
|
|
static::assertSame('2020-10-29 17:10:05', $subject->getBegan()->format('Y-m-d H:i:s'));
|
|
|
|
static::assertSame('2020-10-29 18:12:15', $subject->getEnded()->format('Y-m-d H:i:s'));
|
|
|
|
static::assertSame('01:02:10', $subject->getDuration()->format('%r%H:%I:%S'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function canBeCreatedWithTitle(): void
|
2020-10-20 21:41:19 +02:00
|
|
|
{
|
|
|
|
$subject = new Entry('Example title');
|
|
|
|
|
|
|
|
static::assertInstanceOf(Entry::class, $subject);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2020-10-20 22:52:46 +02:00
|
|
|
public function returnsProvidedTitle(): void
|
2020-10-20 21:41:19 +02:00
|
|
|
{
|
|
|
|
$subject = new Entry('Example title');
|
|
|
|
|
|
|
|
static::assertSame('Example title', $subject->getTitle());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2020-10-20 22:52:46 +02:00
|
|
|
public function canBeStarted(): void
|
2020-10-20 21:41:19 +02:00
|
|
|
{
|
|
|
|
$subject = new Entry();
|
|
|
|
|
|
|
|
$subject->start();
|
|
|
|
|
|
|
|
static::assertTrue($subject->isRunning());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2020-10-20 22:52:46 +02:00
|
|
|
public function canBeStopped(): void
|
2020-10-20 21:41:19 +02:00
|
|
|
{
|
|
|
|
$subject = new Entry();
|
|
|
|
|
|
|
|
$subject->start();
|
|
|
|
$subject->stop();
|
|
|
|
|
|
|
|
static::assertFalse($subject->isRunning());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2020-10-20 22:52:46 +02:00
|
|
|
public function canBeStoppedEvenIfNotRunning(): void
|
2020-10-20 21:41:19 +02:00
|
|
|
{
|
|
|
|
$subject = new Entry();
|
|
|
|
|
|
|
|
$subject->stop();
|
|
|
|
|
|
|
|
static::assertFalse($subject->isRunning());
|
|
|
|
}
|
2020-10-20 22:52:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsNullForBeganBeforeStarted(): void
|
|
|
|
{
|
|
|
|
$subject = new Entry();
|
|
|
|
|
|
|
|
static::assertNull($subject->getBegan());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsBeganAfterStarted(): void
|
|
|
|
{
|
|
|
|
$subject = new Entry();
|
|
|
|
$subject->start();
|
|
|
|
|
|
|
|
static::assertInstanceOf(\DateTimeImmutable::class, $subject->getBegan());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsNullForEndedBeforeStarted(): void
|
|
|
|
{
|
|
|
|
$subject = new Entry();
|
|
|
|
|
|
|
|
static::assertNull($subject->getEnded());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsEndedAfterStoped(): void
|
|
|
|
{
|
|
|
|
$subject = new Entry();
|
|
|
|
$subject->start();
|
|
|
|
$subject->stop();
|
|
|
|
|
|
|
|
static::assertInstanceOf(\DateTimeImmutable::class, $subject->getEnded());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function returnsDurationAfterStopped(): void
|
|
|
|
{
|
|
|
|
$subject = new Entry();
|
|
|
|
$subject->start();
|
|
|
|
$subject->stop();
|
|
|
|
|
|
|
|
static::assertInstanceOf(\DateInterval::class, $subject->getDuration());
|
|
|
|
}
|
2020-10-20 21:41:19 +02:00
|
|
|
}
|