Expect.pattern.phpt 689 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. declare(strict_types=1);
  3. use Nette\Schema\Expect;
  4. use Nette\Schema\Processor;
  5. use Tester\Assert;
  6. require __DIR__ . '/../bootstrap.php';
  7. test('', function () {
  8. $schema = Expect::string()->pattern('\d{9}');
  9. Assert::same('123456789', (new Processor)->process($schema, '123456789'));
  10. });
  11. test('', function () {
  12. $schema = Expect::string()->pattern('\d{9}');
  13. checkValidationErrors(function () use ($schema) {
  14. (new Processor)->process($schema, '123');
  15. }, ["The item expects to match pattern '\\d{9}', '123' given."]);
  16. });
  17. test('', function () {
  18. $schema = Expect::string()->nullable()->pattern('\d{9}');
  19. Assert::same(null, (new Processor)->process($schema, null));
  20. });