|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace SpameriTests\Elastic\Model\Indices; |
| 4 | + |
| 5 | +require_once __DIR__ . '/../../../../bootstrap.php'; |
| 6 | + |
| 7 | +/** |
| 8 | + * @testCase |
| 9 | + */ |
| 10 | +class CreateTest extends \SpameriTests\Elastic\AbstractTestCase |
| 11 | +{ |
| 12 | + |
| 13 | + public function testProcess(): void |
| 14 | + { |
| 15 | + /** @var \Spameri\Elastic\Model\VersionProvider $versionProvider */ |
| 16 | + $versionProvider = $this->container->getByType(\Spameri\Elastic\Model\VersionProvider::class); |
| 17 | + /** @var \Spameri\Elastic\Model\Indices\GetMapping $getMapping */ |
| 18 | + $getMapping = $this->container->getByType(\Spameri\Elastic\Model\Indices\GetMapping::class); |
| 19 | + /** @var \SpameriTests\Elastic\Data\Model\VideoMapping $videoMapping */ |
| 20 | + $videoMapping = $this->container->getByType(\SpameriTests\Elastic\Data\Model\VideoMapping::class); |
| 21 | + |
| 22 | + $create = new \Spameri\Elastic\Model\Indices\Create( |
| 23 | + $this->container->getByType(\Spameri\Elastic\ClientProvider::class), |
| 24 | + $this->container->getByType(\Spameri\Elastic\Model\VersionProvider::class) |
| 25 | + ); |
| 26 | + |
| 27 | + $create->execute(\SpameriTests\Elastic\Config::INDEX_CREATE, $videoMapping->provide()->toArray()); |
| 28 | + $response = $getMapping->execute(\SpameriTests\Elastic\Config::INDEX_CREATE); |
| 29 | + |
| 30 | + if ($versionProvider->provide() <= \Spameri\ElasticQuery\Response\Result\Version::ELASTIC_VERSION_ID_7) { |
| 31 | + \Tester\Assert::true( |
| 32 | + isset($response[\SpameriTests\Elastic\Config::INDEX_CREATE]['mappings'][\SpameriTests\Elastic\Config::INDEX_CREATE]) |
| 33 | + ); |
| 34 | + $existingMapping = $response[\SpameriTests\Elastic\Config::INDEX_CREATE]['mappings'][\SpameriTests\Elastic\Config::INDEX_CREATE]; |
| 35 | + |
| 36 | + \Tester\Assert::same( |
| 37 | + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_STRING, |
| 38 | + $existingMapping['properties']['name']['type'] |
| 39 | + ); |
| 40 | + \Tester\Assert::same( |
| 41 | + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_STRING, |
| 42 | + $existingMapping['properties']['name']['fields']['edgeNgram']['type'] |
| 43 | + ); |
| 44 | + \Tester\Assert::same( |
| 45 | + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_STRING, |
| 46 | + $existingMapping['properties']['season']['properties']['number']['type'] |
| 47 | + ); |
| 48 | + \Tester\Assert::same( |
| 49 | + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_STRING, |
| 50 | + $existingMapping['properties']['story']['properties']['description']['type'] |
| 51 | + ); |
| 52 | + |
| 53 | + } else { |
| 54 | + \Tester\Assert::true( |
| 55 | + isset($response[\SpameriTests\Elastic\Config::INDEX_CREATE]['mappings']) |
| 56 | + ); |
| 57 | + $existingMapping = $response[\SpameriTests\Elastic\Config::INDEX_CREATE]['mappings']; |
| 58 | + |
| 59 | + \Tester\Assert::same( |
| 60 | + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT, |
| 61 | + $existingMapping['properties']['name']['type'] |
| 62 | + ); |
| 63 | + \Tester\Assert::same( |
| 64 | + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_TEXT, |
| 65 | + $existingMapping['properties']['name']['fields']['edgeNgram']['type'] |
| 66 | + ); |
| 67 | + \Tester\Assert::same( |
| 68 | + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_KEYWORD, |
| 69 | + $existingMapping['properties']['season']['properties']['number']['type'] |
| 70 | + ); |
| 71 | + \Tester\Assert::same( |
| 72 | + \Spameri\Elastic\Model\ValidateMapping\AllowedValues::TYPE_KEYWORD, |
| 73 | + $existingMapping['properties']['story']['properties']['description']['type'] |
| 74 | + ); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + |
| 79 | + protected function tearDown() |
| 80 | + { |
| 81 | + /** @var \Spameri\Elastic\Model\Indices\Delete $delete */ |
| 82 | + $delete = $this->container->getByType(\Spameri\Elastic\Model\Indices\Delete::class); |
| 83 | + $delete->execute(\SpameriTests\Elastic\Config::INDEX_CREATE); |
| 84 | + } |
| 85 | + |
| 86 | +} |
| 87 | + |
| 88 | +(new CreateTest())->run(); |
0 commit comments