Skip to content

Commit

Permalink
Adjust CallableAction construct to be more permissive
Browse files Browse the repository at this point in the history
  • Loading branch information
KorvinSzanto committed Jul 1, 2015
1 parent 95271a6 commit e23fad3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/Buttress/IRC/Action/CallableAction.php
Expand Up @@ -11,7 +11,12 @@ class CallableAction implements ActionInterface
protected $connectCallable;
protected $tickCallable;

public function __construct(callable $message_callable, callable $connect_callable, callable $tick_callable)
/**
* @param callable $message_callable
* @param callable $connect_callable
* @param callable $tick_callable
*/
public function __construct($message_callable, $connect_callable, $tick_callable)
{
$this->messageCallable = $message_callable;
$this->connectCallable = $connect_callable;
Expand Down
28 changes: 23 additions & 5 deletions tests/Action/CallableActionTest.php
Expand Up @@ -21,8 +21,9 @@ public function testHandleMessage()
$action = new CallableAction(
function () use (&$hit) {
$hit = true;
}, function () {
});
},
null,
null);

$action->handleMessage($mock);
$this->assertTrue($hit);
Expand All @@ -34,13 +35,30 @@ public function testHandleConnect()
$mock = $this->getMock('\Buttress\IRC\Connection\ConnectionInterface');

$action = new CallableAction(
function () {
}, function () use (&$hit) {
null,
function () use (&$hit) {
$hit = true;
});
},
null);

$action->handleConnect($mock);
$this->assertTrue($hit);
}

public function testHandleTick()
{
$hit = false;
$mock = $this->getMock('\Buttress\IRC\Connection\ConnectionInterface');

$action = new CallableAction(
null,
null,
function () use (&$hit) {
$hit = true;
});

$action->handleTick($mock);
$this->assertTrue($hit);
}

}
5 changes: 2 additions & 3 deletions tests/Connection/ConnectionTest.php
Expand Up @@ -40,7 +40,7 @@ function ($message) use (&$hit) {
}, function ($connection) {
fwrite($connection->getSocket(), 'TEST');
rewind($connection->getSocket());
});
}, null);

$this->manager->add('*', $action);

Expand All @@ -59,7 +59,7 @@ function ($message) use (&$hit) {
}, function ($connection) {
fwrite($connection->getSocket(), 'TEST');
rewind($connection->getSocket());
});
}, null);

$this->manager->add('*', $action);
$this->connection->connect();
Expand All @@ -72,7 +72,6 @@ protected function setUp()
$this->factory = new MessageFactory();
$this->manager = new ActionManager($this->factory);
$this->connection = new Connection($this->manager, '127.0.0.1', 80);

}

protected function tearDown()
Expand Down

0 comments on commit e23fad3

Please sign in to comment.