404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.16.137.150: ~ $
<?php

declare(strict_types=1);

use Nette\Schema\Elements\Structure;
use Nette\Schema\Expect;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';

if (!class_exists(Nette\Utils\Type::class)) {
	Tester\Environment::skip('Expect::from() requires nette/utils 3.x');
}


Assert::with(Structure::class, function () {
	$schema = Expect::from(new stdClass);

	Assert::type(Structure::class, $schema);
	Assert::same([], $schema->items);
	Assert::same(stdClass::class, $schema->castTo);
});


Assert::with(Structure::class, function () {
	$schema = Expect::from(new class {
		/** @var string */
		public $dsn = 'mysql';

		/** @var string|null */
		public $user;

		/** @var ?string */
		public $password;

		/** @var string[] */
		public $options = [1];

		/** @var bool */
		public $debugger = true;
		public $mixed;

		/** @var array|null */
		public $arr;

		/** @var string */
		public $required;
	});

	Assert::type(Structure::class, $schema);
	Assert::equal([
		'dsn' => Expect::string('mysql'),
		'user' => Expect::type('string|null'),
		'password' => Expect::type('?string'),
		'options' => Expect::type('string[]')->default([1]),
		'debugger' => Expect::bool(true),
		'mixed' => Expect::mixed(),
		'arr' => Expect::type('array|null')->default(null),
		'required' => Expect::type('string')->required(),
	], $schema->items);
	Assert::type('string', $schema->castTo);
});


Assert::exception(function () {
	Expect::from(new class {
		/** @var Unknown */
		public $unknown;
	});
}, Nette\NotImplementedException::class, 'Anonymous classes are not supported.');


Assert::with(Structure::class, function () { // overwritten item
	$schema = Expect::from(new class {
		/** @var string */
		public $dsn = 'mysql';

		/** @var string|null */
		public $user;
	}, ['dsn' => Expect::int(123)]);

	Assert::equal([
		'dsn' => Expect::int(123),
		'user' => Expect::type('string|null'),
	], $schema->items);
});


Assert::with(Structure::class, function () { // nested object
	$obj = new class {
		/** @var object */
		public $inner;
	};
	$obj->inner = new class {
		/** @var string */
		public $name;
	};

	$schema = Expect::from($obj);

	Assert::equal([
		'inner' => Expect::structure([
			'name' => Expect::string()->required(),
		])->castTo(get_class($obj->inner)),
	], $schema->items);
});

Filemanager

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