/** * @test */ public function parseSeveralLines() { $code = '1 * $service->call(); $test == 123;'; $result = $this->parser->parse($code); $this->assertInstanceOf('PhpSpock\\Specification\\SimpleBlock', $result); $this->assertEquals($code, $result->getCode()); }
/** * @test */ public function parseSeveralLines() { $code = '1 * $service->call(); $test == 123; // hoho'; $result = $this->parser->parse($code); $this->assertInstanceOf('PhpSpock\\Specification\\ThenBlock', $result); $expressions = $result->getExpressions(); $this->assertEquals(2, count($expressions)); $this->assertInstanceOf('PhpSpock\\Specification\\ThenBlock\\Expression', $expressions[0]); $this->assertEquals('1 * $service->call()', $expressions[0]->getCode()); $this->assertInstanceOf('PhpSpock\\Specification\\ThenBlock\\Expression', $expressions[1]); $this->assertEquals('$test == 123', $expressions[1]->getCode()); $this->assertEquals('hoho', $expressions[1]->getComment()); }
public function parseBlocks($blocks, Specification $spec) { $pairs = array(); $currentPair = null; for ($i = 0; $i < count($blocks); $i++) { $block = $blocks[$i]; $blockName = $block['name']; $blockCode = $block['code']; if (in_array($blockName, array('when', 'then'))) { if (!$currentPair) { $currentPair = new \PhpSpock\Specification\WhenThenPair(); } if ($blockName == 'when') { $parser = new SimpleBlockParser(); $currentPair->setWhenBlock($parser->parse($blockCode)); } if ($blockName == 'then') { $parser = new ThenBlockParser(); $currentPair->setThenBlock($parser->parse($blockCode)); $pairs[] = $currentPair; $currentPair = null; } } else { switch ($blockName) { case 'setup': $parser = new SetupBlockParser(); $spec->setSetupBlock($parser->parse($blockCode)); break; case 'cleanup': $parser = new SimpleBlockParser(); $spec->setCleanupBlock($parser->parse($blockCode)); break; case 'where': $parser = new WhereBlockParser(); $spec->setWhereBlock($parser->parse($blockCode)); break; } } } if (count($pairs)) { $spec->setWhenThenPairs($pairs); } }