Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/composer.lock

/.php_cs.cache
/.phpunit.cache/
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: analyze fix-code
.PHONY: analyze fix-code test

analyze: | vendor
$(COMPOSER) install --optimize-autoloader --no-suggest --prefer-dist
Expand All @@ -19,6 +19,9 @@ fix-code: | vendor
$(COMPOSER) exec -v php-cs-fixer -- fix
@#$(COMPOSER) exec -v psalm -- --alter --issues=all src

test: | vendor
$(COMPOSER) exec -v phpunit tests

vendor:
ifneq (prod,${BUILD_MODE})
$(COMPOSER) install --optimize-autoloader
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@
"rskuipers/php-assumptions": "^0.8.0",
"sebastian/phpcpd": "^6.0",
"sensiolabs/security-checker": "^6.0",
"vimeo/psalm": "^4.2"
"vimeo/psalm": "^4.2",
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
"MacFJA\\RedisSearch\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\MacFJA\\RedisSearch\\": "tests/"
}
},
"support": {
"issues": "https://github.com/MacFJA/php-redisearch/issues",
"source": "https://github.com/MacFJA/php-redisearch"
Expand Down
2 changes: 1 addition & 1 deletion src/Search/QueryBuilder/NumericFacet.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function render(): string
$min = ($this->isMinInclusive ? '' : '(').$this->min;
}
if (is_numeric($this->max)) {
$min = ($this->isMaxInclusive ? '' : '(').$this->max;
$max = ($this->isMaxInclusive ? '' : '(').$this->max;
}

return sprintf('@%s:[%s %s]', $this->fieldName, $min, $max);
Expand Down
65 changes: 65 additions & 0 deletions tests/Search/QueryBuilder/NumericFacetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Tests\MacFJA\RedisSearch\Search\QueryBuilder;

use MacFJA\RedisSearch\Search\QueryBuilder\NumericFacet;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \MacFJA\RedisSearch\Search\QueryBuilder\NumericFacet
*
* @see: https://oss.redislabs.com/redisearch/Query_Syntax/#mapping_common_sql_predicates_to_redisearch
* WHERE num BETWEEN 10 AND 20 @num:[10 20]
* WHERE num >= 10 @num:[10 +inf]
* WHERE num > 10 @num:[(10 +inf]
* WHERE num < 10 @num:[-inf (10]
* WHERE num <= 10 @num:[-inf 10]
* WHERE num < 10 OR num > 20 @num:[-inf (10] | @num:[(20 +inf]
*/
class NumericFacetTest extends TestCase
{
/**
* @covers ::greaterThan
*/
public function testGreaterThan()
{
$facet = NumericFacet::greaterThan('num', 10);
$this->assertSame('@num:[(10 +inf]', $facet->render());
}

/**
* @covers ::greaterThanOrEquals
*/
public function testGreaterThanOrEquals()
{
$facet = NumericFacet::greaterThanOrEquals('num', 10);
$this->assertSame('@num:[10 +inf]', $facet->render());
}

/**
* @covers ::lessThan
*/
public function testLessThan()
{
$facet = NumericFacet::lessThan('num', 10);
$this->assertSame('@num:[-inf (10]', $facet->render());
}

/**
* @covers ::lessThanOrEquals
*/
public function testLessThanOrEquals()
{
$facet = NumericFacet::lessThanOrEquals('num', 10);
$this->assertSame('@num:[-inf 10]', $facet->render());
}

/**
* @covers ::equalsTo
*/
public function testEqualsTo()
{
$facet = NumericFacet::equalsTo('num', 10);
$this->assertSame('@num:[10 10]', $facet->render());
}
}