timetracking-php-web-app/tests/Unit/Entity/EntryTest.php

172 lines
3.9 KiB
PHP

<?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
*/
public function canBeCreatedViaConstructor(): void
{
$subject = new Entry();
static::assertInstanceOf(Entry::class, $subject);
}
/**
* @test
*/
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
{
$subject = new Entry('Example title');
static::assertInstanceOf(Entry::class, $subject);
}
/**
* @test
*/
public function returnsProvidedTitle(): void
{
$subject = new Entry('Example title');
static::assertSame('Example title', $subject->getTitle());
}
/**
* @test
*/
public function canBeStarted(): void
{
$subject = new Entry();
$subject->start();
static::assertTrue($subject->isRunning());
}
/**
* @test
*/
public function canBeStopped(): void
{
$subject = new Entry();
$subject->start();
$subject->stop();
static::assertFalse($subject->isRunning());
}
/**
* @test
*/
public function canBeStoppedEvenIfNotRunning(): void
{
$subject = new Entry();
$subject->stop();
static::assertFalse($subject->isRunning());
}
/**
* @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());
}
}