Passed
Push — feature/initial-implementation ( f3915b...fbd338 )
by Fike
02:22
created

SetupTest::setUpBeforeClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AmaTeam\ElasticSearch\Test\Suite\E2E\Entity;
6
7
use AmaTeam\ElasticSearch\API\ClientFactoryInterface;
8
use AmaTeam\ElasticSearch\API\Mapping\MappingInterface;
9
use AmaTeam\ElasticSearch\Framework\Builder;
10
use AmaTeam\ElasticSearch\Mapping\Mappings;
11
use AmaTeam\ElasticSearch\Test\Support\Allure\AttachmentAware;
12
use AmaTeam\ElasticSearch\Test\Support\Entity\Acceptance\Business\Department;
13
use AmaTeam\ElasticSearch\Test\Support\Entity\Acceptance\Business\Employee;
14
use AmaTeam\ElasticSearch\Test\Support\Entity\Acceptance\Business\Manager;
15
use AmaTeam\ElasticSearch\Test\Support\Entity\Acceptance\Business\MappingProvider;
16
use AmaTeam\ElasticSearch\Test\Support\Entity\Acceptance\Business\Organization;
17
use AmaTeam\ElasticSearch\Test\Support\TestClientFactory;
18
use Codeception\Test\Unit;
19
use Doctrine\Common\Annotations\AnnotationRegistry;
20
use Elasticsearch\Client;
21
use PHPUnit\Framework\Assert;
22
23
class SetupTest extends Unit
24
{
25
    use AttachmentAware;
26
    /**
27
     * @var Client
28
     */
29
    private $client;
30
    /**
31
     * @var ClientFactoryInterface
32
     */
33
    private $clientFactory;
34
35
    /**
36
     * @inheritDoc
37
     */
38
    protected function _before()
39
    {
40
        $this->clientFactory = new TestClientFactory();
41
        $this->client = (new TestClientFactory())->getClient();
42
    }
43
44
    /**
45
     * @inheritDoc
46
     */
47
    public static function setUpBeforeClass()
48
    {
49
        AnnotationRegistry::registerLoader('class_exists');
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\Common\Annotati...istry::registerLoader() has been deprecated: this method is deprecated and will be removed in doctrine/annotations 2.0 autoloading should be deferred to the globally registered autoloader by then. For now, use @example AnnotationRegistry::registerLoader('class_exists') ( Ignorable by Annotation )

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

49
        /** @scrutinizer ignore-deprecated */ AnnotationRegistry::registerLoader('class_exists');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
50
    }
51
52
    public function dataProvider()
53
    {
54
        $business = MappingProvider::getMapping();
55
        return [
56
            [Department::class, $business['department']],
57
            [Employee::class, $business['employee']],
58
            [Manager::class, $business['manager']],
59
            [Organization::class, $business['organization']],
60
        ];
61
    }
62
63
    /**
64
     * @param string $entityName
65
     * @param MappingInterface $expectation
66
     *
67
     * @test
68
     * @dataProvider dataProvider
69
     */
70
    public function shouldCreateExpectedIndex(string $entityName, MappingInterface $expectation)
71
    {
72
        $framework = (new Builder())->setClientFactory($this->clientFactory)->build();
73
        $entity = $framework->getEntityRegistry()->get($entityName);
74
        $this->addDataAttachment($entity, 'entity');
75
        $this->addDataAttachment($expectation, 'mapping-expectation');
76
        $mapping = $framework->getMappingManager()->get($entityName);
77
        $this->addDataAttachment($mapping, 'mapping-built');
78
        Assert::assertEquals($expectation, $mapping);
79
        $indices = $entity->getIndexing()->getWriteIndices();
80
        $index = reset($indices);
81
        if ($this->client->indices()->exists(['index' => $index])) {
82
            $this->client->indices()->delete(['index' => $index]);
83
        }
84
        $framework->getEntityClient()->setUp($entityName);
85
        $result = $framework->getMappingClient()->get($index, $entity->getIndexing()->getType());
86
        $this->addDataAttachment($result, 'mapping-inserted');
87
        Assert::assertFalse(Mappings::conflict($expectation, $result));
0 ignored issues
show
Bug introduced by
It seems like $result can also be of type null; however, parameter $mappings of AmaTeam\ElasticSearch\Mapping\Mappings::conflict() does only seem to accept AmaTeam\ElasticSearch\API\Mapping\MappingInterface, maybe add an additional type check? ( Ignorable by Annotation )

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

87
        Assert::assertFalse(Mappings::conflict($expectation, /** @scrutinizer ignore-type */ $result));
Loading history...
88
        // second application should not do anything wrong
89
        $framework->getEntityClient()->setUp($entityName);
90
    }
91
}
92