Renamed the `StringUtility` to `StringUtil` to make it easier to work with
This commit is contained in:
parent
025751dc47
commit
154c812fc0
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* A class of utilities for dealing with namespaces.
|
||||
* A class of utilities for dealing with strings.
|
||||
*
|
||||
* @package Automattic\WooCommerce\Utilities
|
||||
*/
|
||||
|
@ -8,9 +8,9 @@
|
|||
namespace Automattic\WooCommerce\Utilities;
|
||||
|
||||
/**
|
||||
* A class of utilities for dealing with namespaces.
|
||||
* A class of utilities for dealing with strings.
|
||||
*/
|
||||
final class StringUtility {
|
||||
final class StringUtil {
|
||||
|
||||
/**
|
||||
* Checks to see whether or not a string starts with another.
|
||||
|
@ -21,7 +21,7 @@ final class StringUtility {
|
|||
*
|
||||
* @return bool True if the $string starts with $starts_with, false otherwise.
|
||||
*/
|
||||
public static function starts_with( string $string, string $starts_with, bool $case_sensitive = true ): bool {
|
||||
public static function starts( string $string, string $starts_with, bool $case_sensitive = true ): bool {
|
||||
$len = strlen( $starts_with );
|
||||
if ( $len > 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;
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Automattic\WooCommerce\Tests\Utilities;
|
||||
|
||||
use Automattic\WooCommerce\Utilities\StringUtil;
|
||||
|
||||
/**
|
||||
* A collection of tests for the string utility class.
|
||||
*/
|
||||
class StringUtilTest extends \WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @testdox `starts` should check whether one string starts with another.
|
||||
*/
|
||||
public function test_starts() {
|
||||
$this->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 ) );
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Automattic\WooCommerce\Tests\Utilities;
|
||||
|
||||
use Automattic\WooCommerce\Utilities\StringUtility;
|
||||
|
||||
/**
|
||||
* A collection of tests for the string utility class.
|
||||
*/
|
||||
class StringUtilityTest extends \WC_Unit_Test_Case {
|
||||
|
||||
/**
|
||||
* @testdox `starts_with` should check whether one string starts with another.
|
||||
*/
|
||||
public function test_starts_with() {
|
||||
$this->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 ) );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue