public function setUserStyles(array $userStyles)
{
foreach ($userStyles as $name => $styles) {
if (!$this->isAValidStyleName($name)) {
throw new InvalidStyleNameException("{$name} is not a valid style name");
}
if (in_array($name, (array) $styles)) {
throw new RecursionInUserStylesException('User style cannot reference itself.');
}
}
$this->userStyles = $userStyles;
return $this;
}
public function testGivenInvalidUserStyleNameShouldThrowAnException() { $color = new Color(); try { $color->setUserStyles(array('foo-bar' => 'red')); $this->fail('must throw an InvalidArgumentException'); } catch (InvalidStyleNameException $e) { assertInstanceOf('InvalidArgumentException', $e); assertSame('foo-bar is not a valid style name', $e->getMessage()); } }