|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Cycle\ORM\Promise\Tests\Declaration; |
|
5
|
|
|
|
|
6
|
|
|
use Cycle\ORM\Promise\Declaration\Extractor; |
|
7
|
|
|
use Cycle\ORM\Promise\Declaration\Structure; |
|
8
|
|
|
use Cycle\ORM\Promise\Tests\Declaration\Fixtures\Entity; |
|
9
|
|
|
use Cycle\ORM\Promise\Tests\Declaration\Fixtures\EntityWithConstructor; |
|
10
|
|
|
use Cycle\ORM\Promise\Tests\Fixtures\ChildEntity; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
use Spiral\Core\Container; |
|
13
|
|
|
|
|
14
|
|
|
class ExtractorTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
public function testExtractProperties(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$extracted = $this->getDeclaration(ChildEntity::class)->properties; |
|
19
|
|
|
sort($extracted); |
|
20
|
|
|
|
|
21
|
|
|
$expected = ['public', 'protected', 'ownProperty', '__resolver']; |
|
22
|
|
|
sort($expected); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertSame($expected, $extracted); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testHasConstructor(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$this->assertFalse($this->getDeclaration(Entity::class)->hasConstructor); |
|
30
|
|
|
$this->assertTrue($this->getDeclaration(EntityWithConstructor::class)->hasConstructor); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testExtractParentMethods(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$extracted = []; |
|
36
|
|
|
foreach ($this->getDeclaration(ChildEntity::class)->methods as $method) { |
|
37
|
|
|
$extracted[$method->name->name] = $method->name->name; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$this->assertArrayHasKey('getParentProp', $extracted); |
|
41
|
|
|
$this->assertArrayHasKey('parentProtectedProp', $extracted); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testExtractMethods(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$methods = []; |
|
47
|
|
|
foreach ($this->getDeclaration(Entity::class)->methods as $method) { |
|
48
|
|
|
$methods[] = $method->name->name; |
|
49
|
|
|
} |
|
50
|
|
|
$this->assertSame(['public', 'protected'], $methods); |
|
51
|
|
|
|
|
52
|
|
|
//__construct is not listed |
|
53
|
|
|
$this->assertSame(['public', 'protected'], $this->getDeclaration(EntityWithConstructor::class)->properties); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
private function getDeclaration(string $class): Structure |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->extractor()->extract(new \ReflectionClass($class)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
private function extractor(): Extractor |
|
62
|
|
|
{ |
|
63
|
|
|
$container = new Container(); |
|
64
|
|
|
|
|
65
|
|
|
return $container->get(Extractor::class); |
|
66
|
|
|
} |
|
67
|
|
|
} |