|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Cycle\ORM\Promise\Tests\Declaration; |
|
5
|
|
|
|
|
6
|
|
|
use Cycle\ORM\Promise\Declaration\Declaration; |
|
7
|
|
|
use Cycle\ORM\Promise\Declaration\Extractor; |
|
8
|
|
|
use Cycle\ORM\Promise\Tests\Declaration\Fixtures\Entity; |
|
9
|
|
|
use Cycle\ORM\Promise\Tests\Declaration\Fixtures\EntityWithConstructor; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
use Spiral\Core\Container; |
|
12
|
|
|
|
|
13
|
|
|
class ExtractorTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
public function testExtractProperties() |
|
16
|
|
|
{ |
|
17
|
|
|
$this->assertSame(['public', 'protected'], $this->getDeclaration(Entity::class)->properties); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function testHasConstructor() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->assertFalse($this->getDeclaration(Entity::class)->hasConstructor); |
|
23
|
|
|
$this->assertTrue($this->getDeclaration(EntityWithConstructor::class)->hasConstructor); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testExtractMethods() |
|
27
|
|
|
{ |
|
28
|
|
|
$methods = []; |
|
29
|
|
|
foreach ($this->getDeclaration(Entity::class)->methods as $method) { |
|
30
|
|
|
$methods[] = $method->name->name; |
|
31
|
|
|
} |
|
32
|
|
|
$this->assertSame(['public', 'protected'], $methods); |
|
33
|
|
|
|
|
34
|
|
|
//__construct is not listed |
|
35
|
|
|
$this->assertSame(['public', 'protected'], $this->getDeclaration(EntityWithConstructor::class)->properties); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
private function getDeclaration(string $class): Declaration |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->extractor()->extract($class); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
private function extractor(): Extractor |
|
44
|
|
|
{ |
|
45
|
|
|
$container = new Container(); |
|
46
|
|
|
|
|
47
|
|
|
return $container->get(Extractor::class); |
|
48
|
|
|
} |
|
49
|
|
|
} |