1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bdf\PrimeBundle\Tests; |
4
|
|
|
|
5
|
|
|
require_once __DIR__.'/TestKernel.php'; |
6
|
|
|
|
7
|
|
|
use Bdf\Prime\MongoDB\Collection\MongoCollectionLocator; |
|
|
|
|
8
|
|
|
use Bdf\Prime\MongoDB\Document\DocumentMapper; |
|
|
|
|
9
|
|
|
use Bdf\Prime\MongoDB\Document\MongoDocument; |
|
|
|
|
10
|
|
|
use Bdf\Prime\MongoDB\Schema\CollectionDefinitionBuilder; |
|
|
|
|
11
|
|
|
use Bdf\Prime\MongoDB\Schema\CollectionSchemaResolver; |
|
|
|
|
12
|
|
|
use Bdf\Prime\Query\Expression\Like; |
13
|
|
|
use Bdf\PrimeBundle\Tests\Documents\MapperWithDependency; |
14
|
|
|
use Bdf\PrimeBundle\Tests\Documents\OtherDocumentMapper; |
15
|
|
|
use Bdf\PrimeBundle\Tests\Documents\PersonDocument; |
16
|
|
|
use Bdf\PrimeBundle\Tests\Documents\PersonDocumentMapper; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* BdfSerializerBundleTest |
21
|
|
|
*/ |
22
|
|
|
class WithMongoTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* |
26
|
|
|
*/ |
27
|
|
|
protected function setUp(): void |
28
|
|
|
{ |
29
|
|
|
if (!class_exists(MongoCollectionLocator::class)) { |
30
|
|
|
$this->markTestSkipped('MongoDB driver not installed'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
parent::setUp(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* |
38
|
|
|
*/ |
39
|
|
|
public function test_kernel() |
40
|
|
|
{ |
41
|
|
|
$kernel = new \TestKernel('dev', true); |
42
|
|
|
$kernel->boot(); |
43
|
|
|
|
44
|
|
|
$this->assertInstanceOf(MongoCollectionLocator::class, $kernel->getContainer()->get(MongoCollectionLocator::class)); |
45
|
|
|
$this->assertInstanceOf(CollectionSchemaResolver::class, $kernel->getContainer()->get(CollectionSchemaResolver::class)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* |
50
|
|
|
*/ |
51
|
|
|
public function test_functional() |
52
|
|
|
{ |
53
|
|
|
$kernel = new \TestKernel('dev', true); |
54
|
|
|
$kernel->boot(); |
55
|
|
|
|
56
|
|
|
$kernel->getContainer()->get(CollectionSchemaResolver::class)->resolveByDomainClass(PersonDocument::class)->migrate(); |
57
|
|
|
|
58
|
|
|
$person1 = new PersonDocument('John', 'Doe'); |
59
|
|
|
$person2 = new PersonDocument('Jean', 'Dupont'); |
60
|
|
|
|
61
|
|
|
$person1->save(); |
62
|
|
|
$person2->save(); |
63
|
|
|
|
64
|
|
|
$this->assertEquals([$person1], PersonDocument::where('firstName', 'john')->all()); |
65
|
|
|
$this->assertEquals([$person1, $person2], PersonDocument::where('lastName', (new Like('o'))->contains())->all()); |
66
|
|
|
|
67
|
|
|
$kernel->getContainer()->get(CollectionSchemaResolver::class)->resolveByDomainClass(PersonDocument::class)->drop(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function test_mapper_with_dependency_injection() |
71
|
|
|
{ |
72
|
|
|
$kernel = new \TestKernel('dev', true); |
73
|
|
|
$kernel->boot(); |
74
|
|
|
|
75
|
|
|
/** @var MongoCollectionLocator $locator */ |
76
|
|
|
$locator = $kernel->getContainer()->get(MongoCollectionLocator::class); |
77
|
|
|
|
78
|
|
|
$collection = $locator->collectionByMapper(MapperWithDependency::class); |
79
|
|
|
|
80
|
|
|
$this->assertInstanceOf(MapperWithDependency::class, $collection->mapper()); |
81
|
|
|
$this->assertSame($locator, $collection->mapper()->locator); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function test_same_hydrator_instance_should_be_used() |
85
|
|
|
{ |
86
|
|
|
$kernel = new \TestKernel('dev', true); |
87
|
|
|
$kernel->boot(); |
88
|
|
|
|
89
|
|
|
/** @var MongoCollectionLocator $locator */ |
90
|
|
|
$locator = $kernel->getContainer()->get(MongoCollectionLocator::class); |
91
|
|
|
|
92
|
|
|
$c1 = $locator->collectionByMapper(OtherDocumentMapper::class); |
93
|
|
|
$c2 = $locator->collectionByMapper(PersonDocumentMapper::class); |
94
|
|
|
|
95
|
|
|
$c1->mapper()->fromDatabase([], $c1->connection()->platform()->types()); |
96
|
|
|
$c2->mapper()->fromDatabase([], $c1->connection()->platform()->types()); |
97
|
|
|
|
98
|
|
|
$r = new \ReflectionProperty(DocumentMapper::class, 'hydrator'); |
99
|
|
|
$r->setAccessible(true); |
100
|
|
|
|
101
|
|
|
$this->assertSame($r->getValue($c1->mapper()), $r->getValue($c2->mapper())); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths