Commit be691757 authored by Pavel's avatar Pavel
Browse files

тесты для es

parent c61d9645
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -33,5 +33,11 @@
      "type": "vcs",
      "url": "ssh://git@gitlab.iqdev.digital:8422/piligrimov/search-dc.git"
    }
  ]
  ],
  "require-dev": {
    "phpunit/phpunit": "^9.5"
  },
  "scripts": {
    "tests": "php ./vendor/bin/phpunit --testdox --verbose"
  }
}

phpunit.xml.dist

0 → 100644
+22 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true" 
         convertErrorsToExceptions="true" 
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true" 
         processIsolation="false" 
         stopOnFailure="false"
         bootstrap="tests/bootstrap.php">
    <testsuites>
        <testsuite name="Project Tests Suite">
            <directory>tests/</directory>
        </testsuite>
    </testsuites>

    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">src/ElasticSearch/</directory>
        </include>
    </coverage>
    
</phpunit>
 No newline at end of file
+586 −0

File added.

Preview size limit exceeded, changes collapsed.

+96 −0
Original line number Diff line number Diff line
<?php

namespace IQDEV\ElasticSearchTests\FIlter;

use IQDEV\ElasticSearchTests\Helpers\FormatData;
use IQDEV\ElasticSearchTests\Service\SearchClient;
use IQDEV\Search\SearchQuery\SearchQuery;
use PHPUnit\Framework\TestCase;

class CommonRangeKeywordsTest extends TestCase
{
    /**
     * Поиск элементов по фильтру свойства и цене
     *
     * @return void
     */
    public function testExistByFilterAndMinPrice(): void
    {
        $handler = SearchClient::getInstance();

        $q      = SearchQuery::createFromArray(
            [
                'filters' => [
                    'color' => ['red'],
                    'price' => ['min' => 102]
                ]
            ]
        );
        $result = $handler->handle($q);

        $expected = [
            'hits' => [
                'h1'
            ]
        ];

        $this->assertEqualsCanonicalizing($expected, FormatData::formatData($result));
    }

    /**
     * Поиск элементов по фильтру свойства и цене
     *
     * @return void
     */
    public function testExistByFilterAndMaxPrice(): void
    {
        $handler = SearchClient::getInstance();

        $q      = SearchQuery::createFromArray(
            [
                'filters' => [
                    'color' => ['red'],
                    'price' => ['max' => 102]
                ]
            ]
        );
        $result = $handler->handle($q);

        $expected = [
            'hits' => [
                's2'
            ]
        ];

        $this->assertEqualsCanonicalizing($expected, FormatData::formatData($result));
    }

    /**
     * Поиск элементов по фильтру свойства и цене
     *
     * @return void
     */
    public function testExistByFilterAndRangePrice(): void
    {
        $handler = SearchClient::getInstance();

        $q      = SearchQuery::createFromArray(
            [
                'filters' => [
                    'color' => ['red'],
                    'price' => ['min' => 101, 'max' => 104]
                ]
            ]
        );
        $result = $handler->handle($q);

        $expected = [
            'hits' => [
                'h1',
                's2'
            ]
        ];

        $this->assertEqualsCanonicalizing($expected, FormatData::formatData($result));
    }
}
 No newline at end of file
+175 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading