add() public method

public add ( PhpSpec\Matcher\Matcher $matcher )
$matcher PhpSpec\Matcher\Matcher
コード例 #1
0
 /**
  *
  * @param ExampleNode $example        	
  * @param SpecificationInterface $context        	
  * @param MatcherManager $matchers        	
  * @param CollaboratorManager $collaborators        	
  */
 public function prepare(ExampleNode $example, SpecificationInterface $context, MatcherManager $matchers, CollaboratorManager $collaborators)
 {
     $matchers->replace($this->defaultMatchers);
     if (!$context instanceof Matcher\MatchersProviderInterface) {
         return;
     }
     foreach ($context->getMatchers() as $name => $matcher) {
         if ($matcher instanceof Matcher\MatcherInterface) {
             $matchers->add($matcher);
         } else {
             $matchers->add(new Matcher\CallbackMatcher($name, $matcher, $this->presenter));
         }
     }
 }
 /**
  * @param ExampleNode            $example
  * @param SpecificationInterface $context
  * @param MatcherManager         $matchers
  * @param CollaboratorManager    $collaborators
  */
 public function prepare(ExampleNode $example, SpecificationInterface $context, MatcherManager $matchers, CollaboratorManager $collaborators)
 {
     $scalarMatchers = new CoduoMatcher\ChainMatcher(array(new CoduoMatcher\ExpressionMatcher(), new CoduoMatcher\TypeMatcher(), new CoduoMatcher\ScalarMatcher(), new CoduoMatcher\WildcardMatcher()));
     $arrayMatcher = new CoduoMatcher\ArrayMatcher($scalarMatchers);
     $matcher = new CoduoMatcher(new CoduoMatcher\ChainMatcher(array($scalarMatchers, $arrayMatcher, new CoduoMatcher\JsonMatcher($arrayMatcher))));
     $matchers->add(new StringPatternMatcher($matcher));
 }
コード例 #3
0
 /**
  * @param ExampleNode            $example
  * @param SpecificationInterface $context
  * @param MatcherManager         $matchers
  * @param CollaboratorManager    $collaborators
  */
 public function prepare(ExampleNode $example, SpecificationInterface $context, MatcherManager $matchers, CollaboratorManager $collaborators)
 {
     $matchers->add(new Matcher\IdentityMatcher($this->presenter));
     $matchers->add(new Matcher\ComparisonMatcher($this->presenter));
     $matchers->add(new Matcher\ThrowMatcher($this->unwrapper, $this->presenter));
     $matchers->add(new Matcher\TypeMatcher($this->presenter));
     $matchers->add(new Matcher\ObjectStateMatcher($this->presenter));
     $matchers->add(new Matcher\ScalarMatcher($this->presenter));
     $matchers->add(new Matcher\ArrayCountMatcher($this->presenter));
     $matchers->add(new Matcher\ArrayKeyMatcher($this->presenter));
     $matchers->add(new Matcher\ArrayContainMatcher($this->presenter));
     $matchers->add(new Matcher\StringStartMatcher($this->presenter));
     $matchers->add(new Matcher\StringEndMatcher($this->presenter));
     $matchers->add(new Matcher\StringRegexMatcher($this->presenter));
     if (!$context instanceof Matcher\MatchersProviderInterface) {
         return;
     }
     foreach ($context->getMatchers() as $name => $matcher) {
         if ($matcher instanceof Matcher\MatcherInterface) {
             $matchers->add($matcher);
         } else {
             $matchers->add(new Matcher\CallbackMatcher($name, $matcher, $this->presenter));
         }
     }
 }
コード例 #4
0
 /**
  * @param ExampleNode $example
  * @param SpecificationInterface $context
  * @param MatcherManager $matchers
  * @param CollaboratorManager $collaborators
  */
 public function prepare(ExampleNode $example, SpecificationInterface $context, MatcherManager $matchers, CollaboratorManager $collaborators)
 {
     $matchers->add(new IdentityMatcher($this->presenter));
 }
 /**
  * @param ExampleNode $example
  * @param SpecificationInterface $context
  * @param MatcherManager $matchers
  * @param CollaboratorManager $collaborators
  */
 public function prepare(ExampleNode $example, SpecificationInterface $context, MatcherManager $matchers, CollaboratorManager $collaborators)
 {
     foreach ($this->matchers as $name => $matcher) {
         $matchers->add($matcher);
     }
 }
コード例 #6
0
 function expect($sus)
 {
     $presenter = new TaggedPresenter(new Differ());
     $unwrapper = new Unwrapper();
     $eventDispatcher = new EventDispatcher();
     $exampleNode = new ExampleNode('expect', new \ReflectionFunction(__FUNCTION__));
     $matchers = new MatcherManager($presenter);
     $matchers->add(new IdentityMatcher($presenter));
     $matchers->add(new ComparisonMatcher($presenter));
     $matchers->add(new ThrowMatcher($unwrapper, $presenter));
     $matchers->add(new TypeMatcher($presenter));
     $matchers->add(new ObjectStateMatcher($presenter));
     $matchers->add(new ScalarMatcher($presenter));
     $matchers->add(new ArrayCountMatcher($presenter));
     $matchers->add(new ArrayKeyMatcher($presenter));
     $matchers->add(new ArrayContainMatcher($presenter));
     $matchers->add(new StringStartMatcher($presenter));
     $matchers->add(new StringEndMatcher($presenter));
     $matchers->add(new StringRegexMatcher($presenter));
     $trace = debug_backtrace();
     if (isset($trace[1]['object'])) {
         $object = $trace[1]['object'];
         if ($object instanceof MatchersProviderInterface) {
             foreach ($object->getMatchers() as $name => $matcher) {
                 if ($matcher instanceof MatcherInterface) {
                     $matchers->add($matcher);
                 } elseif (is_callable($matcher)) {
                     $matchers->add(new CallbackMatcher($name, $matcher, $presenter));
                 } else {
                     throw new \RuntimeException('Custom matcher has to implement "PhpSpec\\Matcher\\MatcherInterface" or be a callable');
                 }
             }
         }
     }
     $exceptionFactory = new ExceptionFactory($presenter);
     $wrapper = new Wrapper($matchers, $presenter, $eventDispatcher, $exampleNode);
     $wrappedObject = new WrappedObject($sus, $presenter);
     $caller = new Caller($wrappedObject, $exampleNode, $eventDispatcher, $exceptionFactory, $wrapper);
     $arrayAccess = new SubjectWithArrayAccess($caller, $presenter, $eventDispatcher);
     $expectationFactory = new ExpectationFactory($exampleNode, $eventDispatcher, $matchers);
     return new Subject($sus, $wrapper, $wrappedObject, $caller, $arrayAccess, $expectationFactory);
 }