Example #1
0
 public function testRegisterBaseNamespace()
 {
     ValidatorFactory::clearGlobal();
     (new ValidatorFactory())->setAsGlobal();
     try {
         validator()->testOverTen();
         static::fail();
     } catch (ValidatorNotFoundException $e) {
         static::assertEquals('testOverTen', $e->getName());
     }
     validator()->register(__NAMESPACE__);
     // register
     validator()->testOverTen()->assert(11);
     validator()->from('test_over_ten')->assert(11);
     validator()->from(['age' => 'required|test_over_ten'])->assert(['age' => 11]);
     $this->assertInvalidValueException(function () {
         validator()->testOverTen()->assert(10);
     }, ['test_over_ten:hello']);
     $this->assertInvalidValueException(function () {
         validator()->from('test_over_ten')->assert(10);
     }, ['test_over_ten:hello']);
     $this->assertInvalidValueException(function () {
         validator()->from(['age' => 'required|test_over_ten'])->assert(['age' => 10]);
     }, ['test_over_ten:hello@age']);
 }