|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ShlinkioTest\Shlink\Common\Doctrine\Mapping; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Persistence\Mapping\ClassMetadata; |
|
8
|
|
|
use Doctrine\Persistence\Mapping\Driver\FileLocator; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use Prophecy\Argument; |
|
11
|
|
|
use Prophecy\PhpUnit\ProphecyTrait; |
|
12
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
|
13
|
|
|
use Shlinkio\Shlink\Common\Doctrine\Mapping\EnhancedPHPDriver; |
|
14
|
|
|
|
|
15
|
|
|
class EnhancedPHPDriverTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
use ProphecyTrait; |
|
18
|
|
|
|
|
19
|
|
|
private ObjectProphecy $loader; |
|
20
|
|
|
private ObjectProphecy $meta; |
|
21
|
|
|
|
|
22
|
|
|
public function setUp(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$this->loader = $this->prophesize(FileLocator::class); |
|
25
|
|
|
$this->loader->findMappingFile(Argument::any())->willReturn( |
|
26
|
|
|
__DIR__ . '/../../../test-resources/mapping/fake.mapping.php', |
|
27
|
|
|
); |
|
28
|
|
|
$this->meta = $this->prophesize(ClassMetadata::class); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @test |
|
33
|
|
|
* @dataProvider provideFuncStyle |
|
34
|
|
|
*/ |
|
35
|
|
|
public function internalFunctionIsInvokedBasedOnFunctionalStyle(array $args, int $metaExpectedCalls): void |
|
36
|
|
|
{ |
|
37
|
|
|
$metaMethod = $this->meta->getFieldNames(); |
|
38
|
|
|
|
|
39
|
|
|
$driver = new EnhancedPHPDriver($this->loader->reveal(), [], ...$args); |
|
|
|
|
|
|
40
|
|
|
$driver->loadMetadataForClass('', $this->meta->reveal()); |
|
41
|
|
|
|
|
42
|
|
|
$metaMethod->shouldHaveBeenCalledTimes($metaExpectedCalls); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function provideFuncStyle(): iterable |
|
46
|
|
|
{ |
|
47
|
|
|
yield 'func style' => [[true], 1]; |
|
48
|
|
|
yield 'no func style' => [[false], 0]; |
|
49
|
|
|
yield 'default func style' => [[], 0]; |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|