Skip to content

Commit

Permalink
fix projection path (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwsupplee authored and jdpedrie committed Oct 6, 2016
1 parent ad867d7 commit 23df68d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/Datastore/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ public function projection($properties)
$properties = [$properties];
}

$this->options['query']['projection'] = $properties;
foreach ($properties as $property) {
$this->options['query']['projection'][]['property']['name'] = $property;
}

return $this;
}
Expand Down
12 changes: 7 additions & 5 deletions tests/Datastore/Query/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,29 @@ public function testQueryKeyIsCorrect()

public function testJsonSerialize()
{

$this->assertEquals($this->query->jsonSerialize(), $this->query->queryObject());
}

public function testProjection()
{
$self = $this->query->projection('propname');
$property = 'propname';
$self = $this->query->projection($property);
$this->assertInstanceOf(Query::class, $self);

$res = $this->query->queryObject();

$this->assertEquals($res['projection'], ['propname']);
$this->assertEquals($res['projection'][0]['property']['name'], $property);
}

public function testProjectionWithArrayArgument()
{
$this->query->projection(['propname', 'propname2']);
$properties = ['propname', 'propname2'];
$this->query->projection($properties);

$res = $this->query->queryObject();

$this->assertEquals($res['projection'], ['propname', 'propname2']);
$this->assertEquals($res['projection'][0]['property']['name'], $properties[0]);
$this->assertEquals($res['projection'][1]['property']['name'], $properties[1]);
}

public function testKind()
Expand Down

0 comments on commit 23df68d

Please sign in to comment.