1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 05:11:42 +01:00
amp/test/FailureTest.php

51 lines
1.4 KiB
PHP
Raw Normal View History

2014-09-22 16:47:48 -04:00
<?php
2014-09-22 22:38:32 -04:00
namespace Amp\Test;
2014-09-22 16:47:48 -04:00
2014-09-22 22:38:32 -04:00
use Amp\Failure;
2014-09-22 16:47:48 -04:00
class FailureTest extends \PHPUnit_Framework_TestCase {
public function testWhenInvokedImmediately() {
2015-07-20 22:24:51 -04:00
$wasInvoked = false;
$exception = new \Exception("test");
2014-09-22 16:47:48 -04:00
$failure = new Failure($exception);
2015-07-20 22:24:51 -04:00
$failure->when(function ($error, $result) use ($exception, &$wasInvoked) {
2014-09-22 16:47:48 -04:00
$this->assertNull($result);
$this->assertSame($exception, $error);
2015-07-20 22:24:51 -04:00
$wasInvoked = true;
2014-09-22 16:47:48 -04:00
});
2015-07-20 22:24:51 -04:00
$this->assertTrue($wasInvoked);
}
public function testWhenReturnsSelf() {
$exception = new \Exception("test");
$failure = new Failure($exception);
$result = $failure->when(function () {});
$this->assertSame($failure, $result);
}
public function testWatchReturnsSelf() {
$exception = new \Exception("test");
$failure = new Failure($exception);
$result = $failure->watch(function () {});
$this->assertSame($failure, $result);
}
/**
* @dataProvider provideBadCtorArgs
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Throwable Exception instance required
*/
public function testCtorThrowsOnNonThrowableParam($arg) {
$failure = new Failure($arg);
}
public function provideBadCtorArgs() {
return [
[42],
["string"],
[new \StdClass],
];
2014-09-22 16:47:48 -04:00
}
}