|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace Tests\Torr\TaskManager\Task; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use Torr\TaskManager\Exception\Task\InvalidTaskDefinitionException; |
| 7 | +use Torr\TaskManager\Task\TaskMetaData; |
| 8 | + |
| 9 | +/** |
| 10 | + * @internal |
| 11 | + */ |
| 12 | +final class TaskMetaDataTest extends TestCase |
| 13 | +{ |
| 14 | + public static function provideValidUniqueTaskIds () : iterable |
| 15 | + { |
| 16 | + yield "plain" => ["test"]; |
| 17 | + yield "with dash" => ["a-b"]; |
| 18 | + yield "with underscore" => ["a-b_c"]; |
| 19 | + yield "all characters" => ["a-b_c.d"]; |
| 20 | + yield "numbers" => ["5"]; |
| 21 | + yield "numbers longer" => ["1-2-3-4"]; |
| 22 | + } |
| 23 | + |
| 24 | + /** |
| 25 | + * @dataProvider provideValidUniqueTaskIds |
| 26 | + */ |
| 27 | + public function testValidUniqueTaskIds (string $uniqueTaskId) : void |
| 28 | + { |
| 29 | + $metadata = new TaskMetaData("Test", uniqueTaskId: $uniqueTaskId); |
| 30 | + self::assertSame($uniqueTaskId, $metadata->getKey()); |
| 31 | + } |
| 32 | + |
| 33 | + public static function provideInvalidUniqueTaskIds () : iterable |
| 34 | + { |
| 35 | + yield "empty" => [""]; |
| 36 | + yield "dash at the end" => ["test-"]; |
| 37 | + yield "dot at the end" => ["test."]; |
| 38 | + yield "underscore at the end" => ["test_"]; |
| 39 | + yield "dash at the beginning" => ["-test"]; |
| 40 | + yield "dot at the beginning" => ["_test"]; |
| 41 | + yield "underscore at the beginning" => [".test"]; |
| 42 | + yield "double dash" => ["a--b"]; |
| 43 | + yield "special characters" => ["a@b"]; |
| 44 | + yield "upper case characters" => ["aBc"]; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @dataProvider provideInvalidUniqueTaskIds |
| 49 | + */ |
| 50 | + public function testInvalidUniqueTaskIds (string $uniqueTaskId) : void |
| 51 | + { |
| 52 | + $this->expectException(InvalidTaskDefinitionException::class); |
| 53 | + $this->expectExceptionMessage(\sprintf( |
| 54 | + "Invalid unique task id: '%s'", |
| 55 | + $uniqueTaskId, |
| 56 | + )); |
| 57 | + |
| 58 | + new TaskMetaData("Test", uniqueTaskId: $uniqueTaskId); |
| 59 | + } |
| 60 | +} |
0 commit comments