Test Failed
Pull Request — master (#4)
by Vincent
03:07
created

WithMongoTest::test_kernel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
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
    public function test_kernel()
28
    {
29
        $kernel = new \TestKernel('dev', true);
30
        $kernel->boot();
31
32
        $this->assertInstanceOf(MongoCollectionLocator::class, $kernel->getContainer()->get(MongoCollectionLocator::class));
33
        $this->assertInstanceOf(CollectionSchemaResolver::class, $kernel->getContainer()->get(CollectionSchemaResolver::class));
34
    }
35
36
    /**
37
     *
38
     */
39
    public function test_functional()
40
    {
41
        $kernel = new \TestKernel('dev', true);
42
        $kernel->boot();
43
44
        $kernel->getContainer()->get(CollectionSchemaResolver::class)->resolveByDocumentClass(PersonDocument::class)->migrate();
45
46
        $person1 = new PersonDocument('John', 'Doe');
47
        $person2 = new PersonDocument('Jean', 'Dupont');
48
49
        $person1->save();
50
        $person2->save();
51
52
        $this->assertEquals([$person1], PersonDocument::where('firstName', 'john')->all());
53
        $this->assertEquals([$person1, $person2], PersonDocument::where('lastName', (new Like('o'))->contains())->all());
54
55
        $kernel->getContainer()->get(CollectionSchemaResolver::class)->resolveByDocumentClass(PersonDocument::class)->drop();
56
    }
57
58
    public function test_mapper_with_dependency_injection()
59
    {
60
        $kernel = new \TestKernel('dev', true);
61
        $kernel->boot();
62
63
        /** @var MongoCollectionLocator $locator */
64
        $locator = $kernel->getContainer()->get(MongoCollectionLocator::class);
65
66
        $collection = $locator->collectionByMapper(MapperWithDependency::class);
67
68
        $this->assertInstanceOf(MapperWithDependency::class, $collection->mapper());
69
        $this->assertSame($locator, $collection->mapper()->locator);
70
    }
71
72
    public function test_same_hydrator_instance_should_be_used()
73
    {
74
        $kernel = new \TestKernel('dev', true);
75
        $kernel->boot();
76
77
        /** @var MongoCollectionLocator $locator */
78
        $locator = $kernel->getContainer()->get(MongoCollectionLocator::class);
79
80
        $c1 = $locator->collectionByMapper(OtherDocumentMapper::class);
81
        $c2 = $locator->collectionByMapper(PersonDocumentMapper::class);
82
83
        $c1->mapper()->fromDatabase([], $c1->connection()->platform()->types());
84
        $c2->mapper()->fromDatabase([], $c1->connection()->platform()->types());
85
86
        $r = new \ReflectionProperty(DocumentMapper::class, 'hydrator');
87
        $r->setAccessible(true);
88
89
        $this->assertSame($r->getValue($c1->mapper()), $r->getValue($c2->mapper()));
90
    }
91
}
92