1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\Annotations\Constructor; |
6
|
|
|
|
7
|
|
|
use Doctrine\Annotations\Constructor\Constructor; |
8
|
|
|
use Doctrine\Annotations\Constructor\Instantiator\ConstructorInstantiatorStrategy; |
9
|
|
|
use Doctrine\Annotations\Constructor\Instantiator\Instantiator; |
10
|
|
|
use Doctrine\Annotations\Constructor\Instantiator\PropertyInstantiatorStrategy; |
11
|
|
|
use Doctrine\Annotations\Metadata\AnnotationMetadata; |
12
|
|
|
use Doctrine\Annotations\Parser\Scope; |
13
|
|
|
use Doctrine\Tests\Annotations\Fixtures\AnnotationWithConstructor; |
14
|
|
|
use Doctrine\Tests\Annotations\Fixtures\Metadata\AnnotationWithConstructorMetadata; |
15
|
|
|
use Doctrine\Tests\Annotations\Parser\ScopeMother; |
16
|
|
|
use PHPUnit\Framework\TestCase; |
17
|
|
|
|
18
|
|
|
final class ConstructorTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** @var Constructor */ |
21
|
|
|
private $constructor; |
22
|
|
|
|
23
|
|
|
public function setUp() : void |
24
|
|
|
{ |
25
|
|
|
$this->constructor = new Constructor( |
26
|
|
|
new Instantiator( |
27
|
|
|
new ConstructorInstantiatorStrategy(), |
28
|
|
|
new PropertyInstantiatorStrategy() |
29
|
|
|
) |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param mixed[] $parameters |
35
|
|
|
* |
36
|
|
|
* @dataProvider validProvider |
37
|
|
|
*/ |
38
|
|
|
public function testCreatesAnnotation( |
39
|
|
|
AnnotationMetadata $annotationMetadata, |
40
|
|
|
Scope $scope, |
41
|
|
|
iterable $parameters, |
42
|
|
|
callable $asserter |
43
|
|
|
) : void { |
44
|
|
|
$result = $this->constructor->construct($annotationMetadata, $scope, $parameters); |
45
|
|
|
|
46
|
|
|
$asserter($result); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return mixed[] |
51
|
|
|
*/ |
52
|
|
|
public function validProvider() : iterable |
53
|
|
|
{ |
54
|
|
|
yield 'with constructor' => [ |
|
|
|
|
55
|
|
|
AnnotationWithConstructorMetadata::get(), |
56
|
|
|
ScopeMother::example(), |
57
|
|
|
['value' => 'foo'], |
58
|
|
|
static function (AnnotationWithConstructor $result) : void { |
59
|
|
|
self::assertSame('foo', $result->getValue()); |
60
|
|
|
}, |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|