Processor.context.phpt 788 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. declare(strict_types=1);
  3. use Nette\Schema\Context;
  4. use Nette\Schema\Expect;
  5. use Nette\Schema\Processor;
  6. use Tester\Assert;
  7. require __DIR__ . '/../bootstrap.php';
  8. test('', function () {
  9. $schema = Expect::structure([
  10. 'r' => Expect::string()->required(),
  11. ]);
  12. $processor = new Processor;
  13. $processor->onNewContext[] = function (Context $context) {
  14. $context->path = ['first'];
  15. };
  16. $e = checkValidationErrors(function () use ($schema, $processor) {
  17. $processor->process($schema, []);
  18. }, ["The mandatory item 'first\u{a0}›\u{a0}r' is missing."]);
  19. Assert::equal(
  20. [
  21. new Nette\Schema\Message(
  22. 'The mandatory item %path% is missing.',
  23. Nette\Schema\Message::MissingItem,
  24. ['first', 'r'],
  25. ['isKey' => false]
  26. ),
  27. ],
  28. $e->getMessageObjects()
  29. );
  30. });