Example #1
0
 /**
  * @test
  */
 public function expects_an_expected_field_in_each_expectation()
 {
     $this->assertException(new \Exception('Missing expected field.'), function () {
         $definitions = array('expectations' => array(array('uri' => 'http://www.example.com', 'type' => 'json')));
         $d = new Definition($definitions);
         $d->getExpectations();
     });
 }
 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;
 }