/** * @test */ public function can_assert_different_types() { $types = array('object' => new \stdClass(), 'string' => 'This is a string', 'boolean' => true, 'integer' => 123, 'double' => 3.4, 'NULL' => null); foreach ($types as $type => $example) { $exp = new Expectation($type); $this->assertTrue($exp->assert($example)); foreach ($types as $type2 => $badExample) { if ($type !== $type2) { $this->assertFalse($exp->assert($badExample)); } } } }
public function assert($data) { $this->messages = array(); $definition = $this->definition[0]; $expectation = Expectation::resolver($definition); foreach ($data as $i => $item) { if (!$expectation->assert($item)) { $this->messages = array_merge($this->messages, $expectation->getMessages()); } } $this->assertQuantifier($i + 1); return empty($this->messages); }
public function assert($data) { $this->messages = array(); foreach ($this->definition as $field => $type) { if (isset($data[$field])) { $expectation = Expectation::resolver($type); if (!$expectation->assert($data[$field])) { $this->messages = array_merge($this->messages, $expectation->getMessages()); } unset($data[$field]); } else { $this->messages[] = "Missing field {$field}"; } } return empty($this->messages); }