Skip to content

Commit

Permalink
Override React's loop factory (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Sep 26, 2019
1 parent 9eee0fa commit 87fafa3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"autoload": {
"psr-4": {
"Amp\\ReactAdapter\\": "src"
}
},
"files": [
"etc/Factory.php"
]
},
"autoload-dev": {
"psr-4": {
Expand Down
18 changes: 18 additions & 0 deletions etc/Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace React\EventLoop;

use Amp\ReactAdapter\ReactAdapter;

/**
* Class used to overwrite React's loop factory with an implementation returning the adaptor.
*
* @noinspection PhpUndefinedClassInspection
*/
final class Factory
{
public static function create(): LoopInterface
{
return ReactAdapter::get();
}
}
16 changes: 16 additions & 0 deletions test/FactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Amp\ReactAdapter\Test;

use Amp\ReactAdapter\ReactAdapter;
use PHPUnit\Framework\TestCase;
use React\EventLoop\Factory;

class FactoryTest extends TestCase
{
public function testFactoryReturnsAdaptor()
{
$loop = Factory::create();
$this->assertInstanceOf(ReactAdapter::class, $loop);
}
}

0 comments on commit 87fafa3

Please sign in to comment.