Ejemplo n.º 1
0
 /**
  * @test
  */
 public function executeSpecificationWithParametrization()
 {
     $spec = new Specification();
     $setupBlock = \Mockery::mock(SimpleBlock::clazz())->shouldReceive('compileCode')->twice()->andReturn('$__specification__assertCount += 1;')->mock();
     $whenBlock = \Mockery::mock(SimpleBlock::clazz())->shouldReceive('compileCode')->times(4)->andReturn('$__specification__assertCount += 1;')->mock();
     $thenBlock = \Mockery::mock(ThenBlock::clazz())->shouldReceive('compileCode')->times(4)->andReturn('$__specification__assertCount += 2;')->shouldReceive('getPreConditions')->times(4)->andReturn(array('$__specification__assertCount += 3'))->mock();
     // and +4 for preconditions
     $spec->setSetupBlock($setupBlock);
     $pair1 = new \PhpSpock\Specification\WhenThenPair();
     $pair1->setWhenBlock($whenBlock);
     $pair1->setThenBlock($thenBlock);
     $pair2 = new \PhpSpock\Specification\WhenThenPair();
     $pair2->setWhenBlock($whenBlock);
     $pair2->setThenBlock($thenBlock);
     $spec->setWhenThenPairs(array($pair1, $pair2));
     $whereBlock = \Mockery::mock(WhereBlock::clazz())->shouldReceive('compileCode')->twice()->with(\Mockery::on(function ($arg) {
         static $counter = 0;
         $counter++;
         return $arg == $counter;
     }))->andReturn('$__parametrization__hasMoreVariants = true;', '$__parametrization__hasMoreVariants = false;')->mock();
     $spec->setSetupBlock($setupBlock);
     $spec->setWhereBlock($whereBlock);
     $result = $spec->run();
     $this->assertEquals(30, $result);
 }
Ejemplo n.º 2
0
 public function buildParametrizationCode($stepCounter)
 {
     return $this->attachBlockCode('Where', $this->whereBlock->compileCode($stepCounter));
 }
Ejemplo n.º 3
0
 /**
  * @test
  */
 public function compileCodeWithSeveralParametrizations()
 {
     /**
      * @var $foo
      * @var $baz
      * @var $__parametrization__hasMoreVariants
      */
     $setup = new SimpleBlock();
     $setup->setCode('$boo = 123;');
     eval($setup->compileCode());
     $block = new WhereBlock();
     $p1 = new Parameterization();
     $p1->setLeftExpression('$foo');
     $p1->setRightExpression('array(1,2,$boo + 3)');
     $p2 = new Parameterization();
     $p2->setLeftExpression('$baz');
     $p2->setRightExpression('array($foo,$foo + 1)');
     $block->setParametrizations(array($p1, $p2));
     // step 1 : [11]
     $code = $block->compileCode(0);
     eval($code);
     $this->assertTrue($__parametrization__hasMoreVariants);
     $this->assertEquals(1, $foo);
     $this->assertEquals(1, $baz);
     // step 2 : [22]
     $code = $block->compileCode(1);
     eval($code);
     $this->assertTrue($__parametrization__hasMoreVariants);
     $this->assertEquals(2, $foo);
     $this->assertEquals(3, $baz);
     // step 3 : [31]
     $code = $block->compileCode(2);
     eval($code);
     $this->assertFalse($__parametrization__hasMoreVariants);
     $this->assertEquals(126, $foo);
     $this->assertEquals(126, $baz);
     // step 4 : [12]
     $code = $block->compileCode(3);
     eval($code);
     $this->assertFalse($__parametrization__hasMoreVariants);
     $this->assertEquals(1, $foo);
     $this->assertEquals(2, $baz);
     // step 5 : [21]
     $code = $block->compileCode(4);
     eval($code);
     $this->assertFalse($__parametrization__hasMoreVariants);
     $this->assertEquals(2, $foo);
     $this->assertEquals(2, $baz);
 }