Passed
Pull Request — master (#4)
by Vincent
03:12
created

WithMongoTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 34
c 2
b 0
f 0
dl 0
loc 80
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_kernel() 0 7 1
A test_mapper_with_dependency_injection() 0 12 1
A setUp() 0 7 2
A test_same_hydrator_instance_should_be_used() 0 18 1
A test_functional() 0 17 1
1
<?php
2
3
namespace Bdf\PrimeBundle\Tests;
4
5
require_once __DIR__.'/TestKernel.php';
6
7
use Bdf\Prime\MongoDB\Collection\MongoCollectionLocator;
0 ignored issues
show
Bug introduced by
The type Bdf\Prime\MongoDB\Collec...\MongoCollectionLocator was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Bdf\Prime\MongoDB\Document\DocumentMapper;
0 ignored issues
show
Bug introduced by
The type Bdf\Prime\MongoDB\Document\DocumentMapper was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Bdf\Prime\MongoDB\Document\MongoDocument;
0 ignored issues
show
Bug introduced by
The type Bdf\Prime\MongoDB\Document\MongoDocument was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Bdf\Prime\MongoDB\Schema\CollectionDefinitionBuilder;
0 ignored issues
show
Bug introduced by
The type Bdf\Prime\MongoDB\Schema...ectionDefinitionBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Bdf\Prime\MongoDB\Schema\CollectionSchemaResolver;
0 ignored issues
show
Bug introduced by
The type Bdf\Prime\MongoDB\Schema\CollectionSchemaResolver was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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