pastebin

Paste Search Dynamic
Recent pastes
Expect assert
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. use NetteSchemaExpect;
  6. use NetteSchemaProcessor;
  7. use TesterAssert;
  8.  
  9.  
  10. require __DIR__ . '/../bootstrap.php';
  11.  
  12.  
  13. test('single assertion', function () {
  14.         $schema = Expect::string()->assert('is_file');
  15.  
  16.         checkValidationErrors(function () use ($schema) {
  17.                 (new Processor)->process($schema, 'hello');
  18.         }, ["Failed assertion is_file() for item with value 'hello'."]);
  19.  
  20.         assert::same(__file__, (new Processor)->process($schema, __file__));
  21. });
  22.  
  23.  
  24. test('multiple assertions', function () {
  25.         $schema = Expect::string()->assert('ctype_digit')->assert(function ($s) { return strlen($s) >= 3; });
  26.  
  27.         checkValidationErrors(function () use ($schema) {
  28.                 (new Processor)->process($schema, '');
  29.         }, ["Failed assertion ctype_digit() for item with value ''."]);
  30.  
  31.         checkValidationErrors(function () use ($schema) {
  32.                 (new Processor)->process($schema, '1');
  33.         }, ["Failed assertion #1 for item with value '1'."]);
  34.  
  35.         assert::same('123', (new Processor)->process($schema, '123'));
  36. });
  37.  
  38.  
  39. test('multiple assertions with custom descriptions', function () {
  40.         $schema = Expect::string()
  41.                 ->assert('ctype_digit', 'Is number')
  42.                 ->assert(function ($s) { return strlen($s) >= 3; }, 'Minimal lenght');
  43.  
  44.         checkValidationErrors(function () use ($schema) {
  45.                 (new Processor)->process($schema, '');
  46.         }, ["Failed assertion 'Is number' for item with value ''."]);
  47.  
  48.         checkValidationErrors(function () use ($schema) {
  49.                 (new Processor)->process($schema, '1');
  50.         }, ["Failed assertion 'Minimal lenght' for item with value '1'."]);
  51.  
  52.         assert::same('123', (new Processor)->process($schema, '123'));
  53. });
Parsed in 0.070 seconds