thuecat/Tests/Unit/Domain/Model/Frontend/OpeningHoursTest.php
Daniel Siepmann bbf7ada1d2 Add tests for modified models
That's necessary as models grow.
Added features should be tested to not break with future changes.

The tests revealed an existing error in fallback which got fixed to make
new test pass.

Relates: #18
2021-04-14 11:33:37 +02:00

108 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace WerkraumMedia\ThueCat\Tests\Unit\Domain\Model\Frontend;
/*
* Copyright (C) 2021 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 PHPUnit\Framework\TestCase;
use WerkraumMedia\ThueCat\Domain\Model\Frontend\OpeningHours;
/**
* @covers WerkraumMedia\ThueCat\Domain\Model\Frontend\OpeningHours
* @testdox Frontend model for offers
*/
class OpeningHoursTest extends TestCase
{
/**
* @test
*/
public function canBeCreated(): void
{
$subject = new OpeningHours('{}');
self::assertInstanceOf(OpeningHours::class, $subject);
}
/**
* @test
*/
public function isCountable(): void
{
$subject = new OpeningHours('{}');
self::assertInstanceOf(\Countable::class, $subject);
}
/**
* @test
*/
public function isIterator(): void
{
$subject = new OpeningHours('{}');
self::assertInstanceOf(\Iterator::class, $subject);
}
/**
* @test
* @dataProvider forCount
* @testdox returns $expected for count
*/
public function returnsExpectedCount(string $serialized, int $expected): void
{
$subject = new OpeningHours($serialized);
self::assertCount($expected, $subject);
}
public function forCount(): array
{
return [
'zero' => [
'serialized' => '{}',
'expected' => 0,
],
'one' => [
'serialized' => json_encode([
[
],
]),
'expected' => 1,
],
'five' => [
'serialized' => json_encode([
[
],
[
],
[
],
[
],
[
],
]),
'expected' => 5,
],
];
}
}