diff --git a/src/Type/StringType.php b/src/Type/StringType.php index d8a4315..e260814 100644 --- a/src/Type/StringType.php +++ b/src/Type/StringType.php @@ -23,5 +23,19 @@ use Stringy\Stringy; */ class StringType extends Stringy { + /** + * See if two strings match, despite being delemeted differently, + * such as camelCase, PascalCase, kebab-case, or snake_case. + * + * @param string $strToMatch + * @return boolean + */ + public function fuzzyCaseMatch(string $strToMatch): bool + { + $firstStr = StringType::create($this->str)->dasherize($this->str)->__toString(); + $secondStr = StringType::create($strToMatch)->dasherize()->__toString(); + + return $firstStr === $secondStr; + } } // End of StringType.php \ No newline at end of file diff --git a/tests/Type/StringTypeTest.php b/tests/Type/StringTypeTest.php new file mode 100644 index 0000000..ad1744f --- /dev/null +++ b/tests/Type/StringTypeTest.php @@ -0,0 +1,66 @@ + + * @copyright 2015 - 2017 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @version 2.1.0 + * @link https://git.timshomepage.net/timw4mail/ion + */ + +namespace Aviat\Ion\Tests\Type; + +use Aviat\Ion\StringWrapper; +use Aviat\Ion\Tests\Ion_TestCase; + +class StringTypeTest extends Ion_TestCase { + use StringWrapper; + + + public function dataFuzzyCaseMatch() + { + return [ + 'space separated' => [ + 'str1' => 'foo bar baz', + 'str2' => 'foo-bar-baz', + 'expected' => true + ], + 'camelCase' => [ + 'str1' => 'fooBarBaz', + 'str2' => 'foo-bar-baz', + 'expected' => true + ], + 'PascalCase' => [ + 'str1' => 'FooBarBaz', + 'str2' => 'foo-bar-baz', + 'expected' => true + ], + 'snake_case' => [ + 'str1' => 'foo_bar_baz', + 'str2' => 'foo-bar-baz', + 'expected' => true + ], + 'mEsSYcAse' => [ + 'str1' => 'fOObArBAZ', + 'str2' => 'foo-bar-baz', + 'expected' => false + ], + ]; + } + + /** + * @dataProvider dataFuzzyCaseMatch + */ + public function testFuzzyCaseMatch($str1, $str2, $expected) + { + $actual = $this->string($str1)->fuzzyCaseMatch($str2); + $this->assertEquals($expected, $actual); + } + +} \ No newline at end of file