<?php declare(strict_types=1); use Nette\Schema\Context; use Nette\Schema\Expect; use Tester\Assert; require __DIR__ . '/../bootstrap.php'; class DynamicParameter implements Nette\Schema\DynamicParameter { /** @var string */ private $value; public function __construct(string $value) { $this->value = $value; } } test('', function () { $schema = Expect::structure([ 'a' => Expect::string()->dynamic(), 'b' => Expect::string('def')->dynamic(), 'c' => Expect::int()->dynamic(), 'd' => Expect::int()->min(10)->max(20)->dynamic(), 'arr' => Expect::arrayOf(Expect::int()->dynamic()), 'anyOf' => Expect::anyOf(Expect::int(), Expect::string())->dynamic(), ]); $context = new Context; Assert::equal( (object) [ 'a' => new DynamicParameter("\$this->parameters['foo']"), 'b' => new DynamicParameter("\$this->parameters['bar']"), 'c' => 123, 'd' => new DynamicParameter("\$this->parameters['int']"), 'arr' => ['x' => new DynamicParameter("\$this->parameters['baz']")], 'anyOf' => new DynamicParameter("\$this->parameters['anyOf']"), ], $schema->complete([ 'a' => new DynamicParameter("\$this->parameters['foo']"), 'b' => new DynamicParameter("\$this->parameters['bar']"), 'c' => 123, 'd' => new DynamicParameter("\$this->parameters['int']"), 'arr' => ['x' => new DynamicParameter("\$this->parameters['baz']")], 'anyOf' => new DynamicParameter("\$this->parameters['anyOf']"), ], $context) ); Assert::equal( [ [ new DynamicParameter("\$this->parameters['foo']"), 'string', ], [ new DynamicParameter("\$this->parameters['bar']"), 'string', ], [ new DynamicParameter("\$this->parameters['int']"), 'int:10..20', ], [ new DynamicParameter("\$this->parameters['baz']"), 'int', ], ], $context->dynamics ); });
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
fixtures | Folder | 0755 |
|
|
Expect.anyOf.phpt | File | 8.17 KB | 0644 |
|
Expect.array.phpt | File | 8.14 KB | 0644 |
|
Expect.assert.phpt | File | 1.61 KB | 0644 |
|
Expect.before.phpt | File | 2.26 KB | 0644 |
|
Expect.castTo.phpt | File | 635 B | 0644 |
|
Expect.dynamic.phpt | File | 1.87 KB | 0644 |
|
Expect.from.php74.phpt | File | 906 B | 0644 |
|
Expect.from.php80.phpt | File | 951 B | 0644 |
|
Expect.from.phpt | File | 2.34 KB | 0644 |
|
Expect.list.phpt | File | 3.08 KB | 0644 |
|
Expect.minmax.phpt | File | 3.91 KB | 0644 |
|
Expect.pattern.phpt | File | 722 B | 0644 |
|
Expect.scalars.phpt | File | 2.46 KB | 0644 |
|
Expect.structure.phpt | File | 14.15 KB | 0644 |
|
Helpers.formatValue().phpt | File | 644 B | 0644 |
|
Helpers.getPropertyType.php74.phpt | File | 1.49 KB | 0644 |
|
Helpers.getPropertyType.phpt | File | 974 B | 0644 |
|
Helpers.merge.phpt | File | 2.05 KB | 0644 |
|
Helpers.parseAnnotation().phpt | File | 1.06 KB | 0644 |
|
Processor.context.phpt | File | 828 B | 0644 |
|
heterogenous.phpt | File | 1.34 KB | 0644 |
|