From 154c812fc02f2ff8e599edeb69b8902a9586d5ba Mon Sep 17 00:00:00 2001 From: Christopher Allford Date: Thu, 6 Aug 2020 11:58:37 -0700 Subject: [PATCH] Renamed the `StringUtility` to `StringUtil` to make it easier to work with --- .../ExtendedContainer.php | 4 +- .../{StringUtility.php => StringUtil.php} | 10 ++-- tests/php/src/Utilities/StringUtilTest.php | 51 +++++++++++++++++++ tests/php/src/Utilities/StringUtilityTest.php | 51 ------------------- 4 files changed, 58 insertions(+), 58 deletions(-) rename src/Utilities/{StringUtility.php => StringUtil.php} (80%) create mode 100644 tests/php/src/Utilities/StringUtilTest.php delete mode 100644 tests/php/src/Utilities/StringUtilityTest.php diff --git a/src/Internal/DependencyManagement/ExtendedContainer.php b/src/Internal/DependencyManagement/ExtendedContainer.php index 5f19a45a30c..15a8c205be9 100644 --- a/src/Internal/DependencyManagement/ExtendedContainer.php +++ b/src/Internal/DependencyManagement/ExtendedContainer.php @@ -7,7 +7,7 @@ namespace Automattic\WooCommerce\Internal\DependencyManagement; -use Automattic\WooCommerce\Utilities\StringUtility; +use Automattic\WooCommerce\Utilities\StringUtil; use League\Container\Container as BaseContainer; use League\Container\Definition\DefinitionInterface; @@ -149,6 +149,6 @@ class ExtendedContainer extends BaseContainer { * @return bool True if the class is allowed to be registered, false otherwise. */ protected function is_class_allowed( string $class_name ): bool { - return StringUtility::starts_with( $class_name, $this->woocommerce_namespace, false ) || in_array( $class_name, $this->registration_whitelist, true ); + return StringUtil::starts( $class_name, $this->woocommerce_namespace, false ) || in_array( $class_name, $this->registration_whitelist, true ); } } diff --git a/src/Utilities/StringUtility.php b/src/Utilities/StringUtil.php similarity index 80% rename from src/Utilities/StringUtility.php rename to src/Utilities/StringUtil.php index cd54b1b8f7b..8c04b1fc930 100644 --- a/src/Utilities/StringUtility.php +++ b/src/Utilities/StringUtil.php @@ -1,6 +1,6 @@ strlen( $string ) ) { return false; @@ -45,7 +45,7 @@ final class StringUtility { * * @return bool True if the $string ends with $ends_with, false otherwise. */ - public static function ends_with( string $string, string $ends_with, bool $case_sensitive = true ): bool { + public static function ends( string $string, string $ends_with, bool $case_sensitive = true ): bool { $len = strlen( $ends_with ); if ( $len > strlen( $string ) ) { return false; diff --git a/tests/php/src/Utilities/StringUtilTest.php b/tests/php/src/Utilities/StringUtilTest.php new file mode 100644 index 00000000000..aae6bae13cb --- /dev/null +++ b/tests/php/src/Utilities/StringUtilTest.php @@ -0,0 +1,51 @@ +assertTrue( StringUtil::starts( 'test', 'te' ) ); + $this->assertTrue( StringUtil::starts( ' foo bar', ' foo' ) ); + $this->assertFalse( StringUtil::starts( 'test', 'st' ) ); + $this->assertFalse( StringUtil::starts( ' foo bar', ' bar' ) ); + + $this->assertTrue( StringUtil::starts( 'TEST', 'te', false ) ); + $this->assertTrue( StringUtil::starts( ' FOO BAR', ' foo', false ) ); + $this->assertFalse( StringUtil::starts( 'TEST', 'st', false ) ); + $this->assertFalse( StringUtil::starts( ' FOO BAR', ' bar', false ) ); + + $this->assertTrue( StringUtil::starts( 'test', 'TE', false ) ); + $this->assertTrue( StringUtil::starts( ' foo bar', ' FOO', false ) ); + $this->assertFalse( StringUtil::starts( 'test', 'ST', false ) ); + $this->assertFalse( StringUtil::starts( ' foo bar', ' BAR', false ) ); + } + + /** + * @testdox `ends` should check whether one string ends with another. + */ + public function test_ends() { + $this->assertFalse( StringUtil::ends( 'test', 'te' ) ); + $this->assertFalse( StringUtil::ends( ' foo bar', ' foo' ) ); + $this->assertTrue( StringUtil::ends( 'test', 'st' ) ); + $this->assertTrue( StringUtil::ends( ' foo bar', ' bar' ) ); + + $this->assertFalse( StringUtil::ends( 'TEST', 'te', false ) ); + $this->assertFalse( StringUtil::ends( ' FOO BAR', ' foo', false ) ); + $this->assertTrue( StringUtil::ends( 'TEST', 'st', false ) ); + $this->assertTrue( StringUtil::ends( ' FOO BAR', ' bar', false ) ); + + $this->assertFalse( StringUtil::ends( 'test', 'TE', false ) ); + $this->assertFalse( StringUtil::ends( ' foo bar', ' FOO', false ) ); + $this->assertTrue( StringUtil::ends( 'test', 'ST', false ) ); + $this->assertTrue( StringUtil::ends( ' foo bar', ' BAR', false ) ); + } +} diff --git a/tests/php/src/Utilities/StringUtilityTest.php b/tests/php/src/Utilities/StringUtilityTest.php deleted file mode 100644 index b29aceb04b7..00000000000 --- a/tests/php/src/Utilities/StringUtilityTest.php +++ /dev/null @@ -1,51 +0,0 @@ -assertTrue( StringUtility::starts_with( 'test', 'te' ) ); - $this->assertTrue( StringUtility::starts_with( ' foo bar', ' foo' ) ); - $this->assertFalse( StringUtility::starts_with( 'test', 'st' ) ); - $this->assertFalse( StringUtility::starts_with( ' foo bar', ' bar' ) ); - - $this->assertTrue( StringUtility::starts_with( 'TEST', 'te', false ) ); - $this->assertTrue( StringUtility::starts_with( ' FOO BAR', ' foo', false ) ); - $this->assertFalse( StringUtility::starts_with( 'TEST', 'st', false ) ); - $this->assertFalse( StringUtility::starts_with( ' FOO BAR', ' bar', false ) ); - - $this->assertTrue( StringUtility::starts_with( 'test', 'TE', false ) ); - $this->assertTrue( StringUtility::starts_with( ' foo bar', ' FOO', false ) ); - $this->assertFalse( StringUtility::starts_with( 'test', 'ST', false ) ); - $this->assertFalse( StringUtility::starts_with( ' foo bar', ' BAR', false ) ); - } - - /** - * @testdox `ends_with` should check whether one string ends with another. - */ - public function test_ends_with() { - $this->assertFalse( StringUtility::ends_with( 'test', 'te' ) ); - $this->assertFalse( StringUtility::ends_with( ' foo bar', ' foo' ) ); - $this->assertTrue( StringUtility::ends_with( 'test', 'st' ) ); - $this->assertTrue( StringUtility::ends_with( ' foo bar', ' bar' ) ); - - $this->assertFalse( StringUtility::ends_with( 'TEST', 'te', false ) ); - $this->assertFalse( StringUtility::ends_with( ' FOO BAR', ' foo', false ) ); - $this->assertTrue( StringUtility::ends_with( 'TEST', 'st', false ) ); - $this->assertTrue( StringUtility::ends_with( ' FOO BAR', ' bar', false ) ); - - $this->assertFalse( StringUtility::ends_with( 'test', 'TE', false ) ); - $this->assertFalse( StringUtility::ends_with( ' foo bar', ' FOO', false ) ); - $this->assertTrue( StringUtility::ends_with( 'test', 'ST', false ) ); - $this->assertTrue( StringUtility::ends_with( ' foo bar', ' BAR', false ) ); - } -}