Пример #1
0
 public function expects($invocationRestriction)
 {
     $current_expectation = new Expectation($this);
     $current_expectation->setInvocationRestriction($invocationRestriction);
     $this->expectations[] = $current_expectation;
     return $current_expectation;
 }
Пример #2
0
 /**
  * @test
  */
 public function can_assert_arrays_of_data()
 {
     $expectation = array(array('name' => 'string', 'address' => array('civic#' => 'integer', 'street' => 'string'), 'is_male' => 'boolean', 'birthdate' => '~[0-9]{4}/[0-9]{2}/[0-9]{2}~'), '1+');
     $data = array(array('name' => 'jo blo', 'address' => array('civic#' => 123, 'street' => 'main'), 'is_male' => true, 'birthdate' => '1999/12/21'), array('name' => 'jo blo', 'address' => array('civic#' => 123, 'street' => 'main'), 'is_male' => true, 'birthdate' => '1999/12/21'), array('name' => 'jo blo', 'address' => array('civic#' => 123, 'street' => 'main'), 'is_male' => true, 'birthdate' => '1999/12/21'));
     $exp = new Expectation($expectation);
     $this->assertTrue($exp->assert($data));
 }
 public function verify(Expectation $expectation)
 {
     foreach ($this->methodCalls as $methodCall) {
         if ($methodCall->getMethod() !== $expectation->getName()) {
             continue;
         }
         if (!$expectation->matchArgs($methodCall->getArgs())) {
             continue;
         }
         $expectation->verifyCall($methodCall->getArgs());
     }
     $expectation->verify();
 }
 /**
  * Records the call as expectation and returns the mehtod options object.
  *
  * @param   string method the method name
  * @param   var[] args an array of arguments
  * @return  var
  */
 public function handleInvocation($method, $args)
 {
     $expectation = new Expectation($method);
     $expectation->setArguments($args);
     if ($this->expectationMap->containsKey($method)) {
         $methodExpectations = $this->expectationMap->get($method);
     } else {
         $methodExpectations = new ExpectationList();
         $this->expectationMap->put($method, $methodExpectations);
     }
     $methodExpectations->add($expectation);
     return new MethodOptions($expectation, $method);
 }
 public function throws_sets_the_exception_property_of_the_expectation()
 {
     $expectation = new Expectation('foo');
     $sut = new MethodOptions($expectation, 'foo');
     $expected = new XPException('foo');
     $sut->throws($expected);
     $this->assertEquals($expected, $expectation->getException());
 }
Пример #6
0
 public function test()
 {
     $loader = new ResourceLoader();
     $definitions = new Definition($loader->load($this->source));
     foreach ($definitions->getExpectations() as $definition) {
         if (null !== $definition['type']) {
             $actual = $loader->getType($definition['uri']);
             if ($actual !== $definition['type']) {
                 throw new FailedExpectationException("Type mismatch for {$definition['uri']}. Got [{$actual}] but expected [{$definition['type']}]");
             }
         }
         $expectation = new Expectation($definition['expected']);
         if (!$expectation->assert($loader->load($definition['uri']))) {
             throw new FailedExpectationException(implode("\n", $expectation->getMessages()));
         }
     }
     return true;
 }
 public static function setProperty($propertyName)
 {
     $expectation = new Expectation(Core::getLanguage());
     return $expectation->setProperty($propertyName);
 }
Пример #8
0
 public function __clone()
 {
     parent::__clone();
     $this->_actualCount = 0;
 }
Пример #9
0
 public function stubs($method)
 {
     if (empty($this->expectations[$method])) {
         $expectation = new Expectation($this, $method);
         $expectation->atLeast(0);
         $this->expectations[$method] = $expectation;
     } else {
         $expectation = $this->expectations[$method];
     }
     return $expectation;
 }
 public function getNext_SameExpectationTwice_whenRepeatIs2()
 {
     $expect = new Expectation('method');
     $expect->setRepeat(2);
     $this->sut->add($expect);
     $this->assertEquals($expect, $this->sut->getNext(array()));
     $this->assertEquals($expect, $this->sut->getNext(array()));
     $this->assertNull($this->sut->getNext(array()));
 }
Пример #11
0
 public function handleInvocation_should_throw_exception_when_expectation_defines_one()
 {
     $expected = new XPException('foo');
     $myExpectation = new Expectation('foo');
     $myExpectation->setException($expected);
     $expectationsList = new ExpectationList();
     $expectationsList->add($myExpectation);
     $this->expectationMap->put('foo', $expectationsList);
     try {
         $this->sut->handleInvocation('foo', NULL);
         $this->fail('Exception not thrown.', NULL, $expect);
     } catch (XPException $e) {
         $this->assertEquals($expected, $e);
     }
 }
Пример #12
0
 public function __construct($groupName, $method = NULL, $with = NULL, $will = NULL)
 {
     parent::__construct(NULL, $method, $with, $will);
     $this->groupName = $groupName;
 }