예제 #1
0
 private function createSpecification($body, $fileName, $lineStart, $lineEnd)
 {
     $body = preg_replace('/^\\s*{/', '', $body);
     // fix for { on next line after function()
     try {
         list($tDocComments, $blocks) = $this->splitOnBlocks($body);
     } catch (\Exception $e) {
         $newEx = new ParseException('Can not parse function defined in file ' . $fileName . ' on line ' . $lineStart . "\n" . get_class($e) . ': ' . $e->getMessage(), 0, $e);
         throw $newEx;
     }
     $parser = new \PhpSpock\SpecificationParser\FileUseTokensParser();
     list($namespace, $useStatements) = $parser->parseFile($fileName);
     $spec = new Specification();
     $spec->setVarDeclarations($this->parseMockVars($tDocComments));
     $spec->setNamespace($namespace);
     $spec->setUseStatements($useStatements);
     $spec->setFile($fileName);
     $spec->setStartLine($lineStart);
     $spec->setEndLine($lineEnd);
     $spec->setRawBody($body);
     $spec->setRawBlocks($blocks);
     $this->parseBlocks($blocks, $spec);
     return $spec;
 }
예제 #2
0
 /**
  * @test
  */
 public function mockObjectGeneration()
 {
     $spec = new Specification();
     $setupBlock = \Mockery::mock(SimpleBlock::clazz())->shouldReceive('compileCode')->once()->andReturn('$__specification__assertCount = 1;')->mock();
     $whenBlock = \Mockery::mock(SimpleBlock::clazz())->shouldReceive('compileCode')->once()->andReturn('if($foo instanceof \\Mockery\\MockInterface) $__specification__assertCount += 1;')->mock();
     $thenBlock = \Mockery::mock(ThenBlock::clazz())->shouldReceive('compileCode')->once()->andReturn('if($baz instanceof \\Mockery\\MockInterface) $__specification__assertCount += 2;')->shouldReceive('getPreConditions')->once()->andReturn(array('$__specification__assertCount += 3'))->mock();
     // and +1 for preconditions
     $spec->setSetupBlock($setupBlock);
     $pair1 = new \PhpSpock\Specification\WhenThenPair();
     $pair1->setWhenBlock($whenBlock);
     $pair1->setThenBlock($thenBlock);
     $spec->setWhenThenPairs(array($pair1));
     $spec->setVarDeclarations(array('foo' => '', 'baz' => ''));
     $result = $spec->run();
     $this->assertEquals(8, $result);
 }