Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw ConnectionException when stream is not open (#76) #77

Merged
merged 2 commits into from
Nov 20, 2018
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
6 changes: 2 additions & 4 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ $connections = [
$registry = new Registry($connections);

$r = new Rethink($registry->getConnection('default_connection'));
```

The driver class `Rethink` has a default database defined in the connection options. However you can always switch database if needed.
```php
$r->use('demoDB-2');
// Now you can connect to RethinkDB.
$r->connection()->connect();
```

The driver class `Rethink` has an API Interface that supports the ReQL domain-specific language (DSL).
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ $connections = [
$registry = new Registry($connections);

$r = new Rethink($registry->getConnection('default_connection'));

// Now you can connect to RethinkDB.
$r->connection()->connect();
```

The driver class `Rethink` has a default database defined in the connection options. However you can always switch database if needed.
Expand Down
16 changes: 11 additions & 5 deletions src/Connection/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,37 @@ class Connection implements ConnectionInterface, ConnectionCursorInterface
* @var int[]
*/
private $activeTokens;

/**
* @var string
*/
private $dbName;

/**
* @var HandshakeInterface
*/
private $handshake;

/**
* @var bool
*/
private $noReply = false;

/**
* @var SerializerInterface
*/
private $querySerializer;

/**
* @var SerializerInterface
*/
private $responseSerializer;

/**
* @var StreamInterface
*/
private $stream;

/**
* @var \Closure
*/
Expand All @@ -66,11 +73,6 @@ public function __construct(
$this->responseSerializer = $responseSerializer;
}

public function changes(MessageInterface $query): void
{
// TODO: Implement changes() method.
}

/**
* @throws \Exception
*/
Expand Down Expand Up @@ -241,6 +243,10 @@ public function use(string $name): void
*/
public function writeQuery(int $token, MessageInterface $message): int
{
if (!$this->stream) {
throw new ConnectionException('No open stream, please connect first');
}

if ($this->dbName) {
$message->setOptions((new QueryOptions())->setDb($this->dbName));
}
Expand Down
2 changes: 0 additions & 2 deletions src/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

interface ConnectionInterface
{
public function changes(MessageInterface $query): void;

public function close($noreplyWait = true): void;

public function connect(): Connection;
Expand Down
25 changes: 9 additions & 16 deletions test/unit/Connection/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public function testConnectThrowsCorrectException(): void
$this->connection->connect();
}

/**
* @expectedException \TBolier\RethinkQL\Connection\ConnectionException
* @expectedExceptionMessage No open stream, please connect first
*/
public function testQueryWithoutConnection(): void
{
$this->connection->writeQuery(1223456789, \Mockery::mock(MessageInterface::class));
}

public function testExpr()
{
$this->connect();
Expand Down Expand Up @@ -115,22 +124,6 @@ public function testRunSequence()
}
}

/**
* @throws Exception
*/
public function testChanges()
{
$message = \Mockery::mock(MessageInterface::class);

try {
$this->connection->changes($message);
} catch (\Exception $e) {
$this->fail($e->getMessage());
}

$this->assertTrue(true);
}

/**
* @throws Exception
*/
Expand Down