コード例 #1
0
 public function prepare(ExampleNode $example, SpecificationInterface $context, MatcherManager $matchers, CollaboratorManager $collaborators)
 {
     $this->prophet = new Prophet(null, $this->unwrapper, null);
     foreach ($this->getIterators($example) as $name => $class) {
         $collaborators->set($name, new Collaborator($this->prophet->prophesize(), $class));
     }
 }
コード例 #2
0
 /**
  * @param ExampleNode            $example
  * @param SpecificationInterface $context
  * @param MatcherManager         $matchers
  * @param CollaboratorManager    $collaborators
  */
 public function teardown(ExampleNode $example, SpecificationInterface $context, MatcherManager $matchers, CollaboratorManager $collaborators)
 {
     if (!$example->getSpecification()->getClassReflection()->hasMethod('letgo')) {
         return;
     }
     $reflection = $example->getSpecification()->getClassReflection()->getMethod('letgo');
     $reflection->invokeArgs($context, $collaborators->getArgumentsFor($reflection));
 }
コード例 #3
0
 /**
  * @param CollaboratorManager $collaborators
  * @param \ReflectionMethod $beforeMethod
  */
 private function createMissingCollabolators(CollaboratorManager $collaborators, \ReflectionMethod $beforeMethod)
 {
     foreach ($beforeMethod->getParameters() as $parameter) {
         if (!$collaborators->has($parameter->getName())) {
             $collaborator = new Collaborator($this->prophet->prophesize());
             if (null !== ($class = $parameter->getClass())) {
                 $collaborator->beADoubleOf($class->getName());
             }
             $collaborators->set($parameter->getName(), $collaborator);
         }
     }
 }
コード例 #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)
 {
     $exampleNum = $this->getExampleNumber($example->getTitle());
     $providedData = $this->getDataFromProvider($example);
     if (!array_key_exists($exampleNum, $providedData)) {
         return;
     }
     $data = $providedData[$exampleNum];
     foreach ($example->getFunctionReflection()->getParameters() as $position => $parameter) {
         if (!isset($data[$position])) {
             continue;
         }
         $collaborators->set($parameter->getName(), $data[$position]);
     }
 }
コード例 #5
0
 /**
  * @param CollaboratorManager $collaborators
  * @param string              $name
  *
  * @return Collaborator
  */
 private function getOrCreateCollaborator(CollaboratorManager $collaborators, $name)
 {
     if (!$collaborators->has($name)) {
         $collaborator = new Collaborator($this->prophet->prophesize());
         $collaborators->set($name, $collaborator);
     }
     return $collaborators->get($name);
 }