Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #52 from WyriHaximus/patch-1
Browse files Browse the repository at this point in the history
Add autorun argument to run
  • Loading branch information
svpernova09 committed Feb 19, 2016
2 parents 55efba1 + d161624 commit 471b9e1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ $client->run($connection);

// Also works:
// $client->run(array($connection1, ..., $connectionN));

// Also possible:
// Don't autorun the event loopin case you pass your own event loop and run it yourself
// $client->run($connection, false);
```

1. Create and configure an instance of the connection class, `\Phergie\Irc\Connection`, for each server the bot will connect to. See [phergie-irc-connection documentation](https://github.com/phergie/phergie-irc-connection#usage) for more information on configuring connection objects.
Expand Down
7 changes: 5 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,9 @@ public function addConnection(ConnectionInterface $connection)
* connections remain.
*
* @param \Phergie\Irc\ConnectionInterface|\Phergie\Irc\ConnectionInterface[] $connections
* @param bool $autorun
*/
public function run($connections)
public function run($connections, $autorun = true)
{
if (!is_array($connections)) {
$connections = array($connections);
Expand All @@ -728,7 +729,9 @@ function($connection) {
);
$this->emit('connect.after.all', array($connections, $writes));

$this->getLoop()->run();
if ($autorun) {
$this->getLoop()->run();
}
}

/**
Expand Down
27 changes: 27 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,33 @@ public function testRunWithSingleConnection()
);
}

/**
* Tests run() with a single connection but the loop doesn't autorun.
*/
public function testRunWithSingleConnectionNoAutorun()
{
$loop = $this->getMockLoop();
$connection = $this->getMockConnection();
$connections = array($connection);
$writeStream = $this->getMockWriteStream();
$writeStreams = array($writeStream);
Phake::when($connection)->getOption('write')->thenReturn($writeStream);
Phake::when($this->client)->getWriteStream($connection)->thenReturn($writeStream);
Phake::when($this->client)->getLoop()->thenReturn($loop);

$this->client->setLogger($this->getMockLogger());
$this->client->setResolver($this->getMockResolver('null'));
$this->client->run($connection, false);

Phake::inOrder(
Phake::verify($this->client)->emit('connect.before.all', array($connections)),
Phake::verify($this->client)->addConnection($connection),
Phake::verify($this->client)->emit('connect.after.all', array($connections, $writeStreams))
);

Phake::verify($loop, Phake::never())->run();
}

/**
* Tests run() with a connection configured to use the SSL transport.
*/
Expand Down

0 comments on commit 471b9e1

Please sign in to comment.