From 24c6d4ddcba77169ad9a927d3e2fa2bc351c84f5 Mon Sep 17 00:00:00 2001 From: Marc Morera Date: Fri, 15 Apr 2022 10:22:10 +0200 Subject: [PATCH] Added _id in path_by_field method - Tested the whole method - Added php8.1 --- .circleci/config.yml | 16 +++++++++++++++- Model/Item.php | 4 ++++ Tests/Model/ItemTest.php | 12 ++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ca2c52..d15e778 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -54,6 +54,19 @@ jobs: composer update -n --prefer-dist php vendor/bin/phpunit + php81: + docker: + - image: cimg/php:8.1 + + working_directory: ~/project + steps: + - checkout + - run: + name: Run tests + command: | + composer update -n --prefer-dist + php vendor/bin/phpunit + workflows: version: 2 test: @@ -61,4 +74,5 @@ workflows: - php72 - php73 - php74 - - php80 \ No newline at end of file + - php80 + - php81 diff --git a/Model/Item.php b/Model/Item.php index bc8c5d8..96f9aa9 100644 --- a/Model/Item.php +++ b/Model/Item.php @@ -671,6 +671,10 @@ public static function createFromArray(array $array): self */ public static function getPathByField(string $field) { + if ('_id' === $field) { + return $field; + } + return in_array($field, ['id', 'type']) ? 'uuid.'.$field : 'indexed_metadata.'.$field; diff --git a/Tests/Model/ItemTest.php b/Tests/Model/ItemTest.php index df787e1..1e65805 100644 --- a/Tests/Model/ItemTest.php +++ b/Tests/Model/ItemTest.php @@ -525,4 +525,16 @@ public function testMap() $this->assertEquals(10, $item->getScore()); $this->assertNull($item->getCoordinate()); } + + /** + * @return void + */ + public function testPathByField() + { + $this->assertEquals('_id', Item::getPathByField('_id')); + $this->assertEquals('uuid.id', Item::getPathByField('id')); + $this->assertEquals('uuid.type', Item::getPathByField('type')); + $this->assertEquals('indexed_metadata.another_id', Item::getPathByField('another_id')); + $this->assertEquals('indexed_metadata._field', Item::getPathByField('_field')); + } }