/** * @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 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; }