2014-09-22 22:47:48 +02:00
|
|
|
<?php
|
|
|
|
|
2014-09-23 04:38:32 +02:00
|
|
|
namespace Amp\Test;
|
2014-09-22 22:47:48 +02:00
|
|
|
|
2014-09-23 04:38:32 +02:00
|
|
|
use Amp\Success;
|
2014-09-22 22:47:48 +02:00
|
|
|
|
|
|
|
class SuccessTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
2015-07-21 04:24:51 +02:00
|
|
|
public function testDefaultNullResult() {
|
|
|
|
$wasInvoked = false;
|
|
|
|
$success = new Success;
|
|
|
|
$success->when(function ($error, $result) use (&$wasInvoked) {
|
2014-09-22 22:47:48 +02:00
|
|
|
$this->assertNull($error);
|
2015-07-21 04:24:51 +02:00
|
|
|
$this->assertNull($result);
|
|
|
|
$wasInvoked = true;
|
2014-09-22 22:47:48 +02:00
|
|
|
});
|
2015-07-21 04:24:51 +02:00
|
|
|
$this->assertTrue($wasInvoked);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideInstantiationArgs
|
|
|
|
*/
|
|
|
|
public function testWhenInvokedImmediately($arg) {
|
|
|
|
$wasInvoked = false;
|
|
|
|
$success = new Success($arg);
|
|
|
|
$success->when(function ($error, $result) use (&$wasInvoked, $arg) {
|
|
|
|
$this->assertNull($error);
|
|
|
|
$this->assertSame($arg, $result);
|
|
|
|
$wasInvoked = true;
|
|
|
|
});
|
|
|
|
$this->assertTrue($wasInvoked);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideInstantiationArgs() {
|
|
|
|
return [
|
|
|
|
[42],
|
|
|
|
["string"],
|
|
|
|
[new \StdClass],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWhenReturnsSelf() {
|
|
|
|
$success = new Success;
|
|
|
|
$result = $success->when(function () {});
|
|
|
|
$this->assertSame($success, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWatchReturnsSelf() {
|
|
|
|
$success = new Success;
|
|
|
|
$result = $success->watch(function () {});
|
|
|
|
$this->assertSame($success, $result);
|
2014-09-22 22:47:48 +02:00
|
|
|
}
|
|
|
|
}
|