Skip to content

Commit

Permalink
Added new operators and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwarajanand committed Apr 2, 2022
1 parent e9c7e49 commit 80e284d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Datastore/src/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class Query implements QueryInterface
const OP_GREATER_THAN = 'GREATER_THAN';
const OP_GREATER_THAN_OR_EQUAL = 'GREATER_THAN_OR_EQUAL';
const OP_EQUALS = 'EQUAL';
const OP_NOT_EQUALS = 'NOT_EQUAL';
const OP_IN = 'IN';
const OP_NOT_IN = 'NOT_IN';
const OP_HAS_ANCESTOR = 'HAS_ANCESTOR';

const ORDER_DEFAULT = self::ORDER_ASCENDING;
Expand All @@ -99,6 +102,9 @@ class Query implements QueryInterface
self::OP_GREATER_THAN_OR_EQUAL,
self::OP_EQUALS,
self::OP_HAS_ANCESTOR,
self::OP_NOT_EQUALS,
self::OP_IN,
self::OP_NOT_IN,
];

/**
Expand All @@ -109,7 +115,10 @@ class Query implements QueryInterface
'<=' => self::OP_LESS_THAN_OR_EQUAL,
'>' => self::OP_GREATER_THAN,
'>=' => self::OP_GREATER_THAN_OR_EQUAL,
'=' => self::OP_EQUALS
'=' => self::OP_EQUALS,
'!=' => self::OP_NOT_EQUALS,
'IN' => self::OP_IN,
'NOT_IN' => self::OP_NOT_IN,
];

/**
Expand Down
27 changes: 27 additions & 0 deletions Datastore/tests/Unit/Query/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,33 @@ public function testOperatorConstantsEquals()
$this->assertEquals('EQUAL', $filters[0]['propertyFilter']['op']);
}

public function testOperatorConstantsNotEquals()
{
$this->query->filter('propName', Query::OP_NOT_EQUALS, 'val');
$res = $this->query->queryObject();

$filters = $res['filter']['compositeFilter']['filters'];
$this->assertEquals('NOT_EQUAL', $filters[0]['propertyFilter']['op']);
}

public function testOperatorConstantsIn()
{
$this->query->filter('propName', Query::OP_IN, 'val');
$res = $this->query->queryObject();

$filters = $res['filter']['compositeFilter']['filters'];
$this->assertEquals('IN', $filters[0]['propertyFilter']['op']);
}

public function testOperatorConstantsNotIn()
{
$this->query->filter('propName', Query::OP_NOT_IN, 'val');
$res = $this->query->queryObject();

$filters = $res['filter']['compositeFilter']['filters'];
$this->assertEquals('NOT_IN', $filters[0]['propertyFilter']['op']);
}

public function testOperatorConstantsHasAncestor()
{
$this->query->filter('propName', Query::OP_HAS_ANCESTOR, 'val');
Expand Down

0 comments on commit 80e284d

Please sign in to comment.