Test Failed
Push — master ( 15382f...02157a )
by Sébastien
03:01
created

WithMongoTest.php$0 ➔ setUp()   A

Complexity

Conditions 1

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 26
cc 1
rs 9.504

3 Methods

Rating   Name   Duplication   Size   Complexity  
A WithMongoTest.php$0 ➔ configureRoutes() 0 1 1
A WithMongoTest.php$0 ➔ configureContainer() 0 3 1
A WithMongoTest.php$0 ➔ registerBundles() 0 5 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\MongoDB\Schema\CollectionStructureUpgrader;
0 ignored issues
show
Bug introduced by
The type Bdf\Prime\MongoDB\Schema...ectionStructureUpgrader 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...
13
use Bdf\Prime\MongoDB\Schema\CollectionStructureUpgraderResolver;
0 ignored issues
show
Bug introduced by
The type Bdf\Prime\MongoDB\Schema...ructureUpgraderResolver 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...
14
use Bdf\Prime\Query\Expression\Like;
15
use Bdf\Prime\Schema\StructureUpgraderResolverAggregate;
16
use Bdf\PrimeBundle\PrimeBundle;
17
use Bdf\PrimeBundle\Tests\Documents\MapperWithDependency;
18
use Bdf\PrimeBundle\Tests\Documents\OtherDocumentMapper;
19
use Bdf\PrimeBundle\Tests\Documents\PersonDocument;
20
use Bdf\PrimeBundle\Tests\Documents\PersonDocumentMapper;
21
use PHPUnit\Framework\TestCase;
22
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
23
use Symfony\Component\Config\Loader\LoaderInterface;
24
use Symfony\Component\DependencyInjection\ContainerBuilder;
25
use Symfony\Component\HttpKernel\Kernel;
26
27
/**
28
 * BdfSerializerBundleTest
29
 */
30
class WithMongoTest extends TestCase
31
{
32
    private $kernel;
33
34
    /**
35
     *
36
     */
37
    protected function setUp(): void
38
    {
39
        if (!class_exists(MongoCollectionLocator::class)) {
40
            $this->markTestSkipped('MongoDB driver not installed');
41
        }
42
43
44
        $this->kernel = new class('test', true) extends Kernel {
45
            use \Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
0 ignored issues
show
Bug introduced by
The trait Symfony\Bundle\Framework...Kernel\MicroKernelTrait requires the property $instanceof which is not provided by anonymous//Tests/WithMongoTest.php$0.
Loading history...
46
47
            public function registerBundles(): iterable
48
            {
49
                return [
50
                    new FrameworkBundle(),
51
                    new PrimeBundle(),
52
                ];
53
            }
54
55
            protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

55
            protected function configureContainer(/** @scrutinizer ignore-unused */ ContainerBuilder $c, LoaderInterface $loader)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
            {
57
                $loader->import(__DIR__.'/Fixtures/conf_mongo.yaml');
0 ignored issues
show
Bug introduced by
The method import() does not exist on Symfony\Component\Config\Loader\LoaderInterface. It seems like you code against a sub-type of Symfony\Component\Config\Loader\LoaderInterface such as Symfony\Component\Config\Loader\Loader. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
                $loader->/** @scrutinizer ignore-call */ 
58
                         import(__DIR__.'/Fixtures/conf_mongo.yaml');
Loading history...
58
            }
59
60
            protected function configureRoutes($routes) { }
0 ignored issues
show
Unused Code introduced by
The parameter $routes is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

60
            protected function configureRoutes(/** @scrutinizer ignore-unused */ $routes) { }

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
        };
62
        $this->kernel->boot();
63
    }
64
65
    /**
66
     *
67
     */
68
    public function test_kernel()
69
    {
70
        $this->assertInstanceOf(MongoCollectionLocator::class, $this->kernel->getContainer()->get(MongoCollectionLocator::class));
71
        $this->assertInstanceOf(CollectionStructureUpgraderResolver::class, $this->kernel->getContainer()->get(CollectionStructureUpgraderResolver::class));
72
    }
73
74
    /**
75
     *
76
     */
77
    public function test_functional()
78
    {
79
        $this->kernel->getContainer()->get(CollectionStructureUpgraderResolver::class)->resolveByDomainClass(PersonDocument::class)->migrate();
80
81
        $person1 = new PersonDocument('John', 'Doe');
82
        $person2 = new PersonDocument('Jean', 'Dupont');
83
84
        $person1->save();
85
        $person2->save();
86
87
        $this->assertEquals([$person1], PersonDocument::where('firstName', 'john')->all());
88
        $this->assertEquals([$person1, $person2], PersonDocument::where('lastName', (new Like('o'))->contains())->all());
89
90
        $this->kernel->getContainer()->get(CollectionStructureUpgraderResolver::class)->resolveByDomainClass(PersonDocument::class)->drop();
91
    }
92
93
    public function test_mapper_with_dependency_injection()
94
    {
95
        /** @var MongoCollectionLocator $locator */
96
        $locator = $this->kernel->getContainer()->get(MongoCollectionLocator::class);
97
98
        $collection = $locator->collectionByMapper(MapperWithDependency::class);
99
100
        $this->assertInstanceOf(MapperWithDependency::class, $collection->mapper());
101
        $this->assertSame($locator, $collection->mapper()->locator);
102
    }
103
104
    public function test_same_hydrator_instance_should_be_used()
105
    {
106
        /** @var MongoCollectionLocator $locator */
107
        $locator = $this->kernel->getContainer()->get(MongoCollectionLocator::class);
108
109
        $c1 = $locator->collectionByMapper(OtherDocumentMapper::class);
110
        $c2 = $locator->collectionByMapper(PersonDocumentMapper::class);
111
112
        $c1->mapper()->fromDatabase([], $c1->connection()->platform()->types());
113
        $c2->mapper()->fromDatabase([], $c1->connection()->platform()->types());
114
115
        $r = new \ReflectionProperty(DocumentMapper::class, 'hydrator');
116
        $r->setAccessible(true);
117
118
        $this->assertSame($r->getValue($c1->mapper()), $r->getValue($c2->mapper()));
119
    }
120
121
    public function test_upgrader()
122
    {
123
        if (!class_exists(StructureUpgraderResolverAggregate::class)) {
124
            $this->markTestSkipped('StructureUpgraderResolverAggregate is not found');
125
        }
126
127
        $this->assertInstanceOf(CollectionStructureUpgrader::class, $this->kernel->getContainer()->get(StructureUpgraderResolverAggregate::class)->resolveByDomainClass(PersonDocument::class));
128
        $this->assertInstanceOf(CollectionStructureUpgrader::class, $this->kernel->getContainer()->get(StructureUpgraderResolverAggregate::class)->resolveByMapperClass(PersonDocumentMapper::class));
129
    }
130
}
131