1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Sonata Project package. |
7
|
|
|
* |
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Sonata\EasyExtendsBundle\Tests\Mapper; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
17
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataInfo; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
use Sonata\EasyExtendsBundle\Mapper\DoctrineORMMapper; |
20
|
|
|
|
21
|
|
|
class DoctrineORMMapperTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var ManagerRegistry |
25
|
|
|
*/ |
26
|
|
|
private $doctrine; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var ClassMetadataInfo |
30
|
|
|
*/ |
31
|
|
|
private $metadata; |
32
|
|
|
|
33
|
|
|
public function setUp(): void |
34
|
|
|
{ |
35
|
|
|
$this->doctrine = $this->createMock(ManagerRegistry::class); |
36
|
|
|
$this->metadata = $this->createMock(ClassMetadataInfo::class); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testLoadDiscriminators(): void |
40
|
|
|
{ |
41
|
|
|
$this->metadata |
|
|
|
|
42
|
|
|
->expects($this->atLeastOnce()) |
43
|
|
|
->method('setDiscriminatorMap') |
44
|
|
|
->with(['key' => 'discriminator']); |
45
|
|
|
|
46
|
|
|
$this->metadata->name = 'class'; |
47
|
|
|
$mapper = new DoctrineORMMapper($this->doctrine); |
48
|
|
|
$mapper->addDiscriminator('class', 'key', 'discriminator'); |
49
|
|
|
|
50
|
|
|
$r = new \ReflectionObject($mapper); |
51
|
|
|
$m = $r->getMethod('loadDiscriminators'); |
52
|
|
|
$m->setAccessible(true); |
53
|
|
|
$m->invoke($mapper, $this->metadata); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testLoadDiscriminatorColumns(): void |
57
|
|
|
{ |
58
|
|
|
$this->metadata |
|
|
|
|
59
|
|
|
->expects($this->atLeastOnce()) |
60
|
|
|
->method('setDiscriminatorColumn') |
61
|
|
|
->with(['name' => 'disc']); |
62
|
|
|
|
63
|
|
|
$this->metadata->name = 'class'; |
64
|
|
|
$mapper = new DoctrineORMMapper($this->doctrine); |
65
|
|
|
$mapper->addDiscriminatorColumn('class', ['name' => 'disc']); |
66
|
|
|
|
67
|
|
|
$r = new \ReflectionObject($mapper); |
68
|
|
|
$m = $r->getMethod('loadDiscriminatorColumns'); |
69
|
|
|
$m->setAccessible(true); |
70
|
|
|
$m->invoke($mapper, $this->metadata); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testInheritanceTypes(): void |
74
|
|
|
{ |
75
|
|
|
$this->metadata |
|
|
|
|
76
|
|
|
->expects($this->atLeastOnce()) |
77
|
|
|
->method('setInheritanceType') |
78
|
|
|
->with(1); |
79
|
|
|
|
80
|
|
|
$this->metadata->name = 'class'; |
81
|
|
|
$mapper = new DoctrineORMMapper($this->doctrine); |
82
|
|
|
$mapper->addInheritanceType('class', '1'); |
83
|
|
|
|
84
|
|
|
$r = new \ReflectionObject($mapper); |
85
|
|
|
$m = $r->getMethod('loadInheritanceTypes'); |
86
|
|
|
$m->setAccessible(true); |
87
|
|
|
$m->invoke($mapper, $this->metadata); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.