mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 01:31:45 +01:00
Regex - isValidBundleName() method - returns information if given name of bundle is valid
This commit is contained in:
@@ -37,6 +37,7 @@ class Regex
|
|||||||
'windowsBasedPath' => '/^[A-Z]{1}:\\\.*$/',
|
'windowsBasedPath' => '/^[A-Z]{1}:\\\.*$/',
|
||||||
'money' => '/^[-+]?\d+([\.,]{1}\d*)?$/',
|
'money' => '/^[-+]?\d+([\.,]{1}\d*)?$/',
|
||||||
'color' => '/^[a-f0-9]{6}$/i',
|
'color' => '/^[a-f0-9]{6}$/i',
|
||||||
|
'bundleName' => '/^(([A-Z]{1}[a-z0-9]+)((?2))*)(Bundle)$/',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -723,4 +724,21 @@ class Regex
|
|||||||
|
|
||||||
return strtolower($color);
|
return strtolower($color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns information if given name of bundle is valid
|
||||||
|
*
|
||||||
|
* @param string $bundleName Full name of bundle to verify, e.g. "MyExtraBundle"
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isValidBundleName($bundleName)
|
||||||
|
{
|
||||||
|
if (!is_string($bundleName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pattern = self::$patterns['bundleName'];
|
||||||
|
|
||||||
|
return (bool)preg_match($pattern, $bundleName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace Meritoo\Common\Utilities;
|
namespace Meritoo\Common\Utilities;
|
||||||
|
|
||||||
|
use Generator;
|
||||||
use Meritoo\Common\Test\Base\BaseTestCase;
|
use Meritoo\Common\Test\Base\BaseTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -273,6 +274,69 @@ class RegexTest extends BaseTestCase
|
|||||||
self::assertTrue(Regex::isValidNip('5252530705')); // Facebook Poland sp. z o.o.
|
self::assertTrue(Regex::isValidNip('5252530705')); // Facebook Poland sp. z o.o.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $emptyValue Empty value, e.g. ""
|
||||||
|
* @dataProvider provideEmptyValue
|
||||||
|
*/
|
||||||
|
public function testIsValidBundleNameUsingEmptyValue($emptyValue)
|
||||||
|
{
|
||||||
|
self::assertFalse(Regex::isValidBundleName($emptyValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $bundleName Full name of bundle to verify, e.g. "MyExtraBundle"
|
||||||
|
* @param bool $expected Information if it's valid name
|
||||||
|
*
|
||||||
|
* @dataProvider provideBundleName
|
||||||
|
*/
|
||||||
|
public function testIsValidBundleName($bundleName, $expected)
|
||||||
|
{
|
||||||
|
self::assertEquals($expected, Regex::isValidBundleName($bundleName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides name of bundle and information if it's valid name
|
||||||
|
*
|
||||||
|
* @return Generator
|
||||||
|
*/
|
||||||
|
public function provideBundleName()
|
||||||
|
{
|
||||||
|
yield[
|
||||||
|
'something',
|
||||||
|
false,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
'something_different',
|
||||||
|
false,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
'something-else',
|
||||||
|
false,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
'myExtraBundle',
|
||||||
|
false,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
'MyExtra',
|
||||||
|
false,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
'MyExtraBundle',
|
||||||
|
true,
|
||||||
|
];
|
||||||
|
|
||||||
|
yield[
|
||||||
|
'MySuperExtraGorgeousBundle',
|
||||||
|
true,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user