/**
  * Before executing an it() spec it should be setup like a test case.
  *
  * @param Spec $spec
  */
 public function beforeSpec(Spec $spec)
 {
     self::$testCase->setUp();
     self::$result->startTest(self::$test);
     /** @var Closure $closure */
     $closure = self::$testCase->getProperty($spec, 'closure');
     // This will not be set for incomplete specs.
     if (!$closure) {
         return;
     }
     $suite = self::$testCase->getProperty($spec, 'suite');
     $newSuite = new ProxySuite($spec->getTitle(), $closure, $suite);
     $reflection = new \ReflectionClass($suite);
     foreach ($reflection->getProperties() as $property) {
         $v = self::$testCase->getProperty($suite, $property->getName());
         self::$testCase->setProperty($newSuite, $property->getName(), $v);
     }
     /** @noinspection PhpUndefinedMethodInspection */
     $closure = $closure->bindTo($newSuite);
     self::$testCase->setProperty($spec, 'closure', $closure);
 }
Beispiel #2
0
 /**
  * Compiler the mock into a usable instance.
  *
  * @return object
  */
 public function get()
 {
     $compiler = new ClassCompiler($this->className, $this->niceMock, $this->constructorArgs, $this->disableConstructor, $this->disableClone);
     if ($this->customClassName) {
         $compiler->setCustomClassName($this->customClassName);
     }
     $compiler->setRules($this->rules);
     foreach ($this->expose as $method) {
         $compiler->addExpose($method);
     }
     $mockInstance = $compiler->newInstance();
     $this->testCase->addMockInstance($this, $mockInstance);
     $this->restoreState($mockInstance);
     foreach ($this->properties as $name => $value) {
         $this->testCase->setProperty($mockInstance, $name, $value);
     }
     return $mockInstance;
 }