Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Oct 10, 2024
1 parent a09078b commit 8a74fe9
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 47 deletions.
27 changes: 0 additions & 27 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

24 changes: 19 additions & 5 deletions tests/HandlersCase/RevoltHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,41 @@ public function testInitEnv()
$this->assertTrue(true);
}

/**
* @runInSeparateProcess
* @return void
*/
public function testWaitFor()
{
$rippleHandlerMock = Mockery::mock(RevoltHandler::class . '[sleep]');
$rippleHandlerMock->shouldReceive('sleep')->andReturnNull();
$suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension');
$suspensionMock->shouldReceive('resume')->andReturnNull();
$suspensionMock->shouldReceive('suspend')->andReturnNull();

$eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop');
$eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock);
$eventLoopMock->shouldReceive('defer')->andReturnUsing(function ($closure) {
$closure();
});
$eventLoopMock->shouldReceive('delay')->andReturnUsing(function ($timeout, $closure) {
$closure();
});

$return = false;
$rippleHandlerMock::waitFor(function () use (&$return) {
RevoltHandler::waitFor(function () use (&$return) {
return $return = true;
});
$this->assertTrue($return);

$return = false;
$rippleHandlerMock::waitFor(function () use (&$return) {
RevoltHandler::waitFor(function () use (&$return) {
sleep(1);

return $return = true;
});
$this->assertTrue($return);

$return = false;
$rippleHandlerMock::waitFor(function () use (&$return) {
RevoltHandler::waitFor(function () use (&$return) {
return false;
}, 1);
$this->assertFalse($return);
Expand Down
31 changes: 24 additions & 7 deletions tests/UtilsCase/Channel/RevoltChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use PHPUnit\Framework\TestCase;
use Workbunny\WebmanCoroutine\Utils\Channel\Handlers\RevoltChannel;

/**
* @runTestsInSeparateProcesses
*/
class RevoltChannelTest extends TestCase
{
protected function tearDown(): void
Expand Down Expand Up @@ -62,8 +59,18 @@ public function testClose()

public function testPushWithTimeout()
{
Mockery::mock('alias:\Workbunny\WebmanCoroutine\Handlers\RevoltHandler')
->shouldReceive('sleep')->andReturnNull();
$suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension');
$suspensionMock->shouldReceive('resume')->andReturnNull();
$suspensionMock->shouldReceive('suspend')->andReturnNull();

$eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop');
$eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock);
$eventLoopMock->shouldReceive('defer')->andReturnUsing(function ($closure) {
$closure();
});
$eventLoopMock->shouldReceive('delay')->andReturnUsing(function ($timeout, $closure) {
$closure();
});
$channel = new RevoltChannel(1);
$channel->push('test');

Expand All @@ -72,8 +79,18 @@ public function testPushWithTimeout()

public function testPopWithTimeout()
{
Mockery::mock('alias:\Workbunny\WebmanCoroutine\Handlers\RevoltHandler')
->shouldReceive('sleep')->andReturnNull();
$suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension');
$suspensionMock->shouldReceive('resume')->andReturnNull();
$suspensionMock->shouldReceive('suspend')->andReturnNull();

$eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop');
$eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock);
$eventLoopMock->shouldReceive('defer')->andReturnUsing(function ($closure) {
$closure();
});
$eventLoopMock->shouldReceive('delay')->andReturnUsing(function ($timeout, $closure) {
$closure();
});
$channel = new RevoltChannel(1);

$this->assertFalse($channel->pop(1));
Expand Down
3 changes: 0 additions & 3 deletions tests/UtilsCase/Coroutine/RevoltCoroutineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use PHPUnit\Framework\TestCase;
use Workbunny\WebmanCoroutine\Utils\Coroutine\Handlers\RevoltCoroutine;

/**
* @runTestsInSeparateProcesses
*/
class RevoltCoroutineTest extends TestCase
{
protected function tearDown(): void
Expand Down
17 changes: 12 additions & 5 deletions tests/UtilsCase/WaitGroup/RevoltWaitGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use PHPUnit\Framework\TestCase;
use Workbunny\WebmanCoroutine\Utils\WaitGroup\Handlers\RevoltWaitGroup;

/**
* @runTestsInSeparateProcesses
*/
class RevoltWaitGroupTest extends TestCase
{
protected function tearDown(): void
Expand Down Expand Up @@ -43,8 +40,18 @@ public function testCount()

public function testWait()
{
Mockery::mock('Workbunny\WebmanCoroutine\Handlers\RevoltHandler')
->shouldReceive('sleep')->andReturnNull();
$suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension');
$suspensionMock->shouldReceive('resume')->andReturnNull();
$suspensionMock->shouldReceive('suspend')->andReturnNull();

$eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop');
$eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock);
$eventLoopMock->shouldReceive('defer')->andReturnUsing(function ($closure) {
$closure();
});
$eventLoopMock->shouldReceive('delay')->andReturnUsing(function ($timeout, $closure) {
$closure();
});
$wg = new RevoltWaitGroup();
$wg->add();
$wg->done();
Expand Down

0 comments on commit 8a74fe9

Please sign in to comment.