|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace a9f\Fractor\Tests\Helper; |
| 6 | + |
| 7 | +use a9f\Fractor\Helper\StringUtility; |
| 8 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 9 | +use PHPUnit\Framework\Attributes\Test; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +class StringUtilityTest extends TestCase |
| 13 | +{ |
| 14 | + #[DataProvider('inListForItemContainedReturnsTrueDataProvider')] |
| 15 | + #[Test] |
| 16 | + public function inListForItemContainedReturnsTrue(string $haystack): void |
| 17 | + { |
| 18 | + self::assertTrue(StringUtility::inList($haystack, 'findme')); |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * Data provider for inListForItemContainedReturnsTrue. |
| 23 | + */ |
| 24 | + public static function inListForItemContainedReturnsTrueDataProvider(): array |
| 25 | + { |
| 26 | + return [ |
| 27 | + 'Element as second element of four items' => ['one,findme,three,four'], |
| 28 | + 'Element at beginning of list' => ['findme,one,two'], |
| 29 | + 'Element at end of list' => ['one,two,findme'], |
| 30 | + 'One item list' => ['findme'], |
| 31 | + ]; |
| 32 | + } |
| 33 | + |
| 34 | + #[DataProvider('inListForItemNotContainedReturnsFalseDataProvider')] |
| 35 | + #[Test] |
| 36 | + public function inListForItemNotContainedReturnsFalse(string $haystack): void |
| 37 | + { |
| 38 | + self::assertFalse(StringUtility::inList($haystack, 'findme')); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Data provider for inListForItemNotContainedReturnsFalse. |
| 43 | + */ |
| 44 | + public static function inListForItemNotContainedReturnsFalseDataProvider(): array |
| 45 | + { |
| 46 | + return [ |
| 47 | + 'Four item list' => ['one,two,three,four'], |
| 48 | + 'One item list' => ['one'], |
| 49 | + 'Empty list' => [''], |
| 50 | + ]; |
| 51 | + } |
| 52 | +} |
0 commit comments