/**
     * @test
     */
    public function parseMixedNotation()
    {
        $code = '$myVar << array(1,2,3);

                $sym | $result;
                \'!\' | \'123!\';
                \'!\' | $whatever;
                \'4\' | \'1234\';

                $myVar3 << array(1,2,$hoho);';
        $result = $this->parser->parse($code);
        $this->assertInstanceOf('PhpSpock\\Specification\\WhereBlock', $result);
        $params = $result->getParametrizations();
        $this->assertEquals(4, count($params));
        $this->assertInstanceOf('PhpSpock\\Specification\\WhereBlock\\Parameterization', $params[0]);
        $this->assertInstanceOf('PhpSpock\\Specification\\WhereBlock\\Parameterization', $params[1]);
        $this->assertInstanceOf('PhpSpock\\Specification\\WhereBlock\\Parameterization', $params[2]);
        $this->assertInstanceOf('PhpSpock\\Specification\\WhereBlock\\Parameterization', $params[3]);
        $this->assertEquals('$myVar', $params[0]->getLeftExpression());
        $this->assertEquals('array(1,2,3)', $params[0]->getRightExpression());
        $this->assertEquals('$sym', $params[1]->getLeftExpression());
        $this->assertEquals('array(\'!\',\'!\',\'4\')', $params[1]->getRightExpression());
        $this->assertEquals('$result', $params[2]->getLeftExpression());
        $this->assertEquals('array(\'123!\',$whatever,\'1234\')', $params[2]->getRightExpression());
        $this->assertEquals('$myVar3', $params[3]->getLeftExpression());
        $this->assertEquals('array(1,2,$hoho)', $params[3]->getRightExpression());
    }
Esempio n. 2
0
 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);
     }
 }