2017-12-14 02:29:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp\ParallelFunctions\Test;
|
|
|
|
|
2017-12-15 03:26:03 +01:00
|
|
|
use Amp\Parallel\Worker\Pool;
|
2017-12-14 02:29:19 +01:00
|
|
|
use Amp\PHPUnit\TestCase;
|
2017-12-15 03:26:03 +01:00
|
|
|
use Amp\Promise;
|
|
|
|
use Amp\Success;
|
2017-12-14 02:29:19 +01:00
|
|
|
use function Amp\ParallelFunctions\parallel;
|
|
|
|
|
|
|
|
class ParallelTest extends TestCase {
|
|
|
|
/**
|
|
|
|
* @expectedException \Error
|
2017-12-14 17:33:41 +01:00
|
|
|
* @expectedExceptionMessage Unsupported callable: Serialization of 'class@anonymous' is not allowed
|
2017-12-14 02:29:19 +01:00
|
|
|
*/
|
|
|
|
public function testUnserializableClosure() {
|
2017-12-14 08:31:15 +01:00
|
|
|
$unserializable = new class {
|
|
|
|
};
|
2017-12-14 17:33:41 +01:00
|
|
|
parallel(function () use ($unserializable) {
|
2017-12-14 02:29:19 +01:00
|
|
|
return 1;
|
|
|
|
});
|
|
|
|
}
|
2017-12-15 03:26:03 +01:00
|
|
|
|
|
|
|
public function testCustomPool() {
|
|
|
|
$mock = $this->createMock(Pool::class);
|
|
|
|
$mock->expects($this->once())
|
|
|
|
->method("enqueue")
|
|
|
|
->willReturn(new Success(1));
|
|
|
|
|
|
|
|
$callable = parallel(function () {
|
|
|
|
return 0;
|
|
|
|
}, $mock);
|
|
|
|
|
|
|
|
$this->assertSame(1, Promise\wait($callable()));
|
|
|
|
}
|
2017-12-14 02:29:19 +01:00
|
|
|
}
|