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'); |
|
|
|
|
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)); |
|
|
|
|
88
|
|
|
// second application should not do anything wrong |
89
|
|
|
$framework->getEntityClient()->setUp($entityName); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
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.