diff --git a/Datastore/src/Query/Query.php b/Datastore/src/Query/Query.php index 6f67a2d29d82..0d3a62dc595b 100644 --- a/Datastore/src/Query/Query.php +++ b/Datastore/src/Query/Query.php @@ -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; @@ -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, ]; /** @@ -109,7 +115,8 @@ 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 ]; /** @@ -243,7 +250,7 @@ public function kind($kinds) * [here](https://cloud.google.com/datastore/reference/rest/v1/projects/runQuery#operator_1). * Short comparison operators are provided for convenience and are * mapped to their datastore-compatible equivalents. Available short - * operators are `=`, `<`, `<=`, `>`, and `>=`. + * operators are `=`, `!=`, `<`, `<=`, `>`, and `>=`. * @param mixed $value The value to check. * @return Query */ diff --git a/Datastore/tests/Unit/Query/QueryTest.php b/Datastore/tests/Unit/Query/QueryTest.php index 216347fd087a..de289d9ba90b 100644 --- a/Datastore/tests/Unit/Query/QueryTest.php +++ b/Datastore/tests/Unit/Query/QueryTest.php @@ -216,6 +216,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'); @@ -270,6 +297,15 @@ public function testShortOperatorEquals() $this->assertEquals('EQUAL', $filters[0]['propertyFilter']['op']); } + public function testShortOperatorNotEquals() + { + $this->query->filter('propName', '!=', 'val'); + $res = $this->query->queryObject(); + + $filters = $res['filter']['compositeFilter']['filters']; + $this->assertEquals('NOT_EQUAL', $filters[0]['propertyFilter']['op']); + } + public function testOrder() { $direction = 'DESCENDING';