I am new to phpspec and I want to test my CourseCode class for number of invalid format possibilities.
I have this class
/**
* The course code
*/
final class CourseCode
{
/**
* Matches the range
* AA000 | ZZ999
* AA000-0 | ZZ999-9 | ZZ000-A | ZZ999-F
*/
const CODE_PATTERN = '/[A-Za-z]{2}[0-9]{3}-?[A-Za-z0-9]?^/';
/**
* @var string
*/
private $code;
/**
* The course code should match the CODE_PATTERN
*
* @param string $aCode The course code.
*/
public function __construct($aCode)
{
AssertionConcern::regex(
$aCode,
self::CODE_PATTERN,
sprintf(
'Code should match the pattern %s. Ex: AA000 | ZZ999 | AA000-0 | ZZ999-9 | ZZ000-A | ZZ999-F. %s given',
self::CODE_PATTERN,
$aCode
));
$this->code = $aCode;
}
/**
* @return string
*/
public function code()
{
return $this->code;
}
}
I want to test if my regex is working as expected.
How can I achieve this using phpspec?