diff --git a/Classes/Domain/Model/Frontend/OpeningHour.php b/Classes/Domain/Model/Frontend/OpeningHour.php index f33839d..ced292f 100644 --- a/Classes/Domain/Model/Frontend/OpeningHour.php +++ b/Classes/Domain/Model/Frontend/OpeningHour.php @@ -83,7 +83,7 @@ class OpeningHour return new self( $rawData['opens'] ?? '', $rawData['closes'] ?? '', - $rawData['daysOfWeek'] ?? '', + $rawData['daysOfWeek'] ?? [], $from, $through ); diff --git a/Tests/Unit/Domain/Model/Frontend/OffersTest.php b/Tests/Unit/Domain/Model/Frontend/OffersTest.php new file mode 100644 index 0000000..60c9939 --- /dev/null +++ b/Tests/Unit/Domain/Model/Frontend/OffersTest.php @@ -0,0 +1,174 @@ + + * + * 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\Offers; + +/** + * @covers WerkraumMedia\ThueCat\Domain\Model\Frontend\Offers + * @testdox Frontend model for offers + */ +class OffersTest extends TestCase +{ + /** + * @test + */ + public function canBeCreated(): void + { + $subject = new Offers('{}'); + + self::assertInstanceOf(Offers::class, $subject); + } + + /** + * @test + */ + public function isCountable(): void + { + $subject = new Offers('{}'); + + self::assertInstanceOf(\Countable::class, $subject); + } + + /** + * @test + */ + public function isIterator(): void + { + $subject = new Offers('{}'); + + self::assertInstanceOf(\Iterator::class, $subject); + } + + /** + * @test + * @dataProvider forCount + * @testdox returns $expected for count + */ + public function returnsExpectedCount(string $serialized, int $expected): void + { + $subject = new Offers($serialized); + + self::assertCount($expected, $subject); + } + + public function forCount(): array + { + return [ + 'zero' => [ + 'serialized' => '{}', + 'expected' => 0, + ], + 'one' => [ + 'serialized' => json_encode([ + [ + 'title' => '', + 'description' => '', + 'prices' => [ + [ + 'title' => '', + 'description' => '', + 'price' => 5.0, + 'currency' => '', + 'rule' => '', + ], + ], + ], + ]), + 'expected' => 1, + ], + 'five' => [ + 'serialized' => json_encode([ + [ + 'title' => '', + 'description' => '', + 'prices' => [ + [ + 'title' => '', + 'description' => '', + 'price' => 5.0, + 'currency' => '', + 'rule' => '', + ], + ], + ], + [ + 'title' => '', + 'description' => '', + 'prices' => [ + [ + 'title' => '', + 'description' => '', + 'price' => 5.0, + 'currency' => '', + 'rule' => '', + ], + ], + ], + [ + 'title' => '', + 'description' => '', + 'prices' => [ + [ + 'title' => '', + 'description' => '', + 'price' => 5.0, + 'currency' => '', + 'rule' => '', + ], + ], + ], + [ + 'title' => '', + 'description' => '', + 'prices' => [ + [ + 'title' => '', + 'description' => '', + 'price' => 5.0, + 'currency' => '', + 'rule' => '', + ], + ], + ], + [ + 'title' => '', + 'description' => '', + 'prices' => [ + [ + 'title' => '', + 'description' => '', + 'price' => 5.0, + 'currency' => '', + 'rule' => '', + ], + ], + ], + ]), + 'expected' => 5, + ], + ]; + } +} diff --git a/Tests/Unit/Domain/Model/Frontend/OpeningHoursTest.php b/Tests/Unit/Domain/Model/Frontend/OpeningHoursTest.php new file mode 100644 index 0000000..d1e0dcf --- /dev/null +++ b/Tests/Unit/Domain/Model/Frontend/OpeningHoursTest.php @@ -0,0 +1,108 @@ + + * + * 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, + ], + ]; + } +}