Example #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);
 }