File: Type.fromReflection.property.phpt

package info (click to toggle)
php-nette-utils 4.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,444 kB
  • sloc: php: 4,146; xml: 9; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 835 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php

declare(strict_types=1);

use Nette\Utils\Type;
use Tester\Assert;

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


$type = Type::fromReflection((new ReflectionObject(new class {
	public $foo;
}))->getProperty('foo'));
Assert::null($type);


$type = Type::fromReflection((new ReflectionObject(new class {
	public string $foo;
}))->getProperty('foo'));

Assert::same(['string'], $type->getNames());
Assert::same('string', (string) $type);


$type = Type::fromReflection((new ReflectionObject(new class {
	public ?string $foo;
}))->getProperty('foo'));

Assert::same(['string', 'null'], $type->getNames());
Assert::same('?string', (string) $type);


$type = Type::fromReflection((new ReflectionObject(new class {
	public Foo $foo;
}))->getProperty('foo'));

Assert::same(['Foo'], $type->getNames());
Assert::same('Foo', (string) $type);