From 9948ee5d3da9fc072a9ea62341630700794dcd92 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Thu, 16 Jan 2025 14:21:04 +0100 Subject: [PATCH] Add clsas for MD_STD_STRINGS more obscure string operations --- phpstan-baseline.neon | 0 phpstan.neon | 12 ++++++ src/MD_STD_STRINGS.php | 39 ++++++++++++++++++++ src/testing/MD_STD_TEST_PROVIDERS.php | 2 +- tests/MD_STD_STRINGS_Test.php | 53 +++++++++++++++++++++++++++ tests/MD_STD_Test.php | 1 + 6 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon create mode 100644 src/MD_STD_STRINGS.php create mode 100644 tests/MD_STD_STRINGS_Test.php diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..e69de29 diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..3f819ca --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,12 @@ +parameters: + level: 8 + bootstrapFiles: + - ./tests/bootstrap.php + paths: + - src + - tests + dynamicConstantNames: + - DATABASENAME + - DATABASENAME_NODA +includes: + - phpstan-baseline.neon diff --git a/src/MD_STD_STRINGS.php b/src/MD_STD_STRINGS.php new file mode 100644 index 0000000..c684fb0 --- /dev/null +++ b/src/MD_STD_STRINGS.php @@ -0,0 +1,39 @@ + + * @return array */ public static function invalid_email_provider():array { diff --git a/tests/MD_STD_STRINGS_Test.php b/tests/MD_STD_STRINGS_Test.php new file mode 100644 index 0000000..a3e33f6 --- /dev/null +++ b/tests/MD_STD_STRINGS_Test.php @@ -0,0 +1,53 @@ + + */ +declare(strict_types = 1); + +use PHPUnit\Framework\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\Attributes\CoversClass; + +/** + * Tests for MD_STD_STRINGS. + */ +#[small] +#[CoversClass(\MD_STD_STRINGS::class)] +final class MD_STD_STRINGS_Test extends TestCase { + /** + * Data provider for strings to duplicate words with dots in. + * + * @return array + */ + public static function duplicated_words_with_dots_provider():array { + + $values = [ + ["hallo test. hallo", "hallo test. hallo test"], + ]; + + $output = []; + foreach ($values as $value) { + $output[$value[0] . ' > ' . $value[1]] = $value; + } + return $output; + + } + + /** + * Function for testing duplicate_words_with_dots_for_indexing(). + * + * @param string $input Input. + * @param string $expected Expected output. + * + * @return void + */ + #[DataProvider('duplicated_words_with_dots_provider')] + public function test_duplicate_words_with_dots_for_indexing(string $input, string $expected):void { + + self::assertEquals($expected, MD_STD_STRINGS::duplicate_words_with_dots_for_indexing($input)); + + } +} diff --git a/tests/MD_STD_Test.php b/tests/MD_STD_Test.php index 5fb48b3..21c0707 100644 --- a/tests/MD_STD_Test.php +++ b/tests/MD_STD_Test.php @@ -739,6 +739,7 @@ final class MD_STD_Test extends TestCase { self::assertEmpty(MD_STD::strpos_multi($haystack, $needles)); } else { + self::assertNotEmpty(MD_STD::strpos_multi($haystack, $needles)); self::assertEquals($expected, MD_STD::strpos_multi($haystack, $needles)['position']); }