Skip to content

Commit

Permalink
Fix without implementation manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
tbolier committed Sep 8, 2018
1 parent 08d4b83 commit 0d2dcd3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Query/Manipulation/ManipulationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function pluck(...$keys): Pluck
return new Pluck($this->rethink, /** @scrutinizer ignore-type */ $this, $keys);
}

public function without(...$keys)
public function without(...$keys): Without
{
return new Without($this->rethink, /** @scrutinizer ignore-type */ $this, $keys);
}
Expand Down
19 changes: 14 additions & 5 deletions src/Query/Manipulation/Without.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,27 @@ public function __construct(
parent::__construct($rethink);

$this->query = $query;
$this->keys = $keys;
$this->rethink = $rethink;
$this->keys = $keys;
}

public function toArray(): array
{
if (\count($this->keys) === 1) {
$keysQuery = implode($this->keys);
} else {
$keysQuery = [
TermType::MAKE_ARRAY,
array_values($this->keys)
];
}

return [
TermType::WITHOUT,
array_merge(
[$this->query->toArray()],
array_values($this->keys)
),
[
$this->query->toArray(),
$keysQuery
]
];
}
}
11 changes: 7 additions & 4 deletions test/integration/Manipulation/WithoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace TBolier\RethinkQL\IntegrationTest\Manipulation;

use TBolier\RethinkQL\IntegrationTest\Query\AbstractTableTest;
use TBolier\RethinkQL\Response\ResponseInterface;

class WithoutTest extends AbstractTableTest
{
Expand All @@ -14,14 +15,16 @@ public function testWithoutResult()
{
$this->insertDocumentWithNumber(1, 1);

/** @var Cursor $cursor */
$cursor = $this->r()
/** @var ResponseInterface $cursor */
$response = $this->r()
->table('tabletest')
->get(1)
->without('title', 'number')
->run();

$this->assertInstanceOf(\Iterator::class, $cursor);
$this->assertEquals(1, $cursor->count());
$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertCount(2, $response->getData());
$this->assertArrayNotHasKey('title', $response->getData());
$this->assertArrayNotHasKey('number', $response->getData());
}
}

0 comments on commit 0d2dcd3

Please sign in to comment.