DataSift\Storyplayer\ValidationLib\MustBeValidStoryTemplate::validate PHP Method

validate() public method

public validate ( $value, Phix_Project\ValidationLib4\ValidationResult $result = null )
$result Phix_Project\ValidationLib4\ValidationResult
    public function validate($value, ValidationResult $result = null)
    {
        if ($result === null) {
            $result = new ValidationResult($value);
        }
        // we need a valid PHP class
        if (!class_exists($value)) {
            $result->addError(static::MSG_NOTVALIDCLASS);
            return $result;
        }
        // the class must be a StoryTemplate
        $refClass = new ReflectionClass($value);
        if (!$refClass->isSubclassOf('DataSift\\Storyplayer\\PlayerLib\\StoryTemplate')) {
            $result->addError(static::MSG_NOTVALIDTEMPLATE);
            return $result;
        }
        // all done
        return $result;
    }

Usage Example

 /**
  * @covers DataSift\Storyplayer\ValidationLib\MustBeValidStoryTemplate::validate()
  */
 public function testRejectsNonClasses()
 {
     // ----------------------------------------------------------------
     // setup your test
     $obj = new MustBeValidStoryTemplate();
     // ----------------------------------------------------------------
     // perform the change
     $result = $obj->validate("DataSift\\Storyplayer\\ValidationLib\\ClassDoesNotExist");
     // ----------------------------------------------------------------
     // test the results
     $this->assertNotNull($result);
     $this->assertFalse($result->isValid());
 }
MustBeValidStoryTemplate