public function testIsValid_FieldEmail()
{
// mock of document
$document = $this->getMock('\\Sokil\\Mongo\\Document', array('rules'), array($this->collection));
$document->expects($this->any())->method('rules')->will($this->returnValue(array(array('some-field-name', 'email'), array('some-field-name-mx', 'email', 'mx' => true))));
// required field empty
$this->assertTrue($document->isValid());
// Email invalid
$document->set('some-field-name', 'wrongValue');
$this->assertFalse($document->isValid());
// Email valid
$document->set('some-field-name', '[email protected]');
$this->assertTrue($document->isValid());
try {
// additional MX check on wrong email
$document->set('some-field-name-mx', '[email protected]');
$this->assertFalse($document->isValid());
// additional MX check on valid email
$document->set('some-field-name-mx', '[email protected]');
$this->assertTrue($document->isValid());
} catch (\RuntimeException $e) {
if ($e->getMessage() !== '') {
throw $e;
}
}
}