Skip to content

Commit

Permalink
feat: Revolt测试
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Oct 10, 2024
1 parent 897aa8d commit 135d0b6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
7 changes: 5 additions & 2 deletions tests/UtilsCase/Channel/RevoltChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use PHPUnit\Framework\TestCase;
use Workbunny\WebmanCoroutine\Utils\Channel\Handlers\RevoltChannel;

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

public function testPushWithTimeout()
{
Mockery::mock('alias:Workbunny\WebmanCoroutine\Handlers\RevoltHandler')
Mockery::mock('alias:\Workbunny\WebmanCoroutine\Handlers\RevoltHandler')
->shouldReceive('sleep')->andReturnNull();
$channel = new RevoltChannel(1);
$channel->push('test');
Expand All @@ -69,7 +72,7 @@ public function testPushWithTimeout()

public function testPopWithTimeout()
{
Mockery::mock('alias:Workbunny\WebmanCoroutine\Handlers\RevoltHandler')
Mockery::mock('alias:\Workbunny\WebmanCoroutine\Handlers\RevoltHandler')
->shouldReceive('sleep')->andReturnNull();
$channel = new RevoltChannel(1);

Expand Down
19 changes: 11 additions & 8 deletions tests/UtilsCase/Coroutine/RevoltCoroutineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use PHPUnit\Framework\TestCase;
use Workbunny\WebmanCoroutine\Utils\Coroutine\Handlers\RevoltCoroutine;

/**
* @runTestsInSeparateProcesses
*/
class RevoltCoroutineTest extends TestCase
{
protected function tearDown(): void
Expand All @@ -26,11 +29,11 @@ public function testConstruct()

// mock
$callback = null;
$suspensionMock = Mockery::mock('Revolt\EventLoop\Suspension');
$suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension');
$suspensionMock->shouldReceive('resume')->andReturnNull();
$suspensionMock->shouldReceive('suspend')->andReturnNull();

$eventLoopMock = Mockery::mock('alias:Revolt\EventLoop');
$eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop');
$eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock);
$eventLoopMock->shouldReceive('queue')->andReturnUsing(function ($closure) use (&$callback) {
$closure();
Expand All @@ -55,11 +58,11 @@ public function testDestruct()

// mock
$callback = null;
$suspensionMock = Mockery::mock('Revolt\EventLoop\Suspension');
$suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension');
$suspensionMock->shouldReceive('resume')->andReturnNull();
$suspensionMock->shouldReceive('suspend')->andReturnNull();

$eventLoopMock = Mockery::mock('alias:Revolt\EventLoop');
$eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop');
$eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock);
$eventLoopMock->shouldReceive('queue')->andReturnUsing(function ($closure) use (&$callback) {
$closure();
Expand All @@ -81,11 +84,11 @@ public function testOrigin()
};
// mock
$callback = null;
$suspensionMock = Mockery::mock('Revolt\EventLoop\Suspension');
$suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension');
$suspensionMock->shouldReceive('resume')->andReturnNull();
$suspensionMock->shouldReceive('suspend')->andReturnNull();

$eventLoopMock = Mockery::mock('alias:Revolt\EventLoop');
$eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop');
$eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock);
$eventLoopMock->shouldReceive('queue')->andReturnUsing(function ($closure) use (&$callback) {
$closure();
Expand All @@ -104,11 +107,11 @@ public function testId()
};
// mock
$callback = null;
$suspensionMock = Mockery::mock('Revolt\EventLoop\Suspension');
$suspensionMock = Mockery::mock('alias:\Revolt\EventLoop\Suspension');
$suspensionMock->shouldReceive('resume')->andReturnNull();
$suspensionMock->shouldReceive('suspend')->andReturnNull();

$eventLoopMock = Mockery::mock('alias:Revolt\EventLoop');
$eventLoopMock = Mockery::mock('alias:\Revolt\EventLoop');
$eventLoopMock->shouldReceive('getSuspension')->andReturn($suspensionMock);
$eventLoopMock->shouldReceive('queue')->andReturnUsing(function ($closure) use (&$callback) {
$closure();
Expand Down
5 changes: 4 additions & 1 deletion tests/UtilsCase/WaitGroup/RevoltWaitGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use PHPUnit\Framework\TestCase;
use Workbunny\WebmanCoroutine\Utils\WaitGroup\Handlers\RevoltWaitGroup;

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

public function testWait()
{
Mockery::mock('alias:Workbunny\WebmanCoroutine\Handlers\RevoltHandler')
Mockery::mock('Workbunny\WebmanCoroutine\Handlers\RevoltHandler')
->shouldReceive('sleep')->andReturnNull();
$wg = new RevoltWaitGroup();
$wg->add();
Expand Down

0 comments on commit 135d0b6

Please sign in to comment.