Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
chaz6chez committed Oct 18, 2024
1 parent 74c230e commit 249fef0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
47 changes: 25 additions & 22 deletions tests/EventsCase/SwooleEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,29 +235,24 @@ public function testAddAndDelRead()
$result = $swooleEvent->add('123', EventInterface::EV_READ, function () {
echo 'Read event error';
});

$this->assertFalse($result);
// add
// Event::add
$stream = fopen('php://memory', 'r+');
$result = $swooleEvent->add($stream, EventInterface::EV_READ, function () {
echo 'Read event1';
});

$this->assertTrue($result);
// set
// Event::set
$eventMock->shouldReceive('isset')->andReturn(true);
$stream2 = fopen('php://memory', 'r+');
$result = $swooleEvent->add($stream2, EventInterface::EV_READ, function () {
echo 'Read event2';
});

$this->assertTrue($result);
// del
$eventMock->shouldReceive('del')->andReturn(true);
$eventMock->shouldReceive('isset')->andReturn(true);

$result = $swooleEvent->del($stream, EventInterface::EV_READ);
$this->assertTrue($result);
// del set
// ----

$eventMock->shouldReceive('del')->andReturn(true);
$eventMock->shouldReceive('set')->andReturnUsing(function ($stream, $readCallback, $writeCallback, $event) {
$this->assertTrue(is_resource($stream));
$this->assertTrue(is_int($event));
Expand All @@ -266,7 +261,13 @@ public function testAddAndDelRead()

return true;
});
// Event::del
$eventMock->shouldReceive('isset')->andReturn(false);
$result = $swooleEvent->del($stream, EventInterface::EV_READ);
$this->assertTrue($result);
// Event::set
$eventMock->shouldReceive('isset')->andReturn(false);


$result = $swooleEvent->del($stream2, EventInterface::EV_READ);
$this->assertTrue($result);
Expand Down Expand Up @@ -297,33 +298,31 @@ public function testAddAndDelWrite()

return true;
});

$eventMock->shouldReceive('isset')->andReturn(false);
// false
$result = $swooleEvent->add('321', EventInterface::EV_WRITE, function () {
echo 'Write event error';
});

$this->assertFalse($result);
// add
// Event::add
$eventMock->shouldReceive('isset')->andReturn(false);
$stream = fopen('php://memory', 'w+');
$result = $swooleEvent->add($stream, EventInterface::EV_WRITE, function () {
echo 'Write event1';
});
$this->assertTrue($result);
// set
// Event::set
$eventMock->shouldReceive('isset')->andReturn(true);
$stream2 = fopen('php://memory', 'w+');
$result = $swooleEvent->add($stream2, EventInterface::EV_WRITE, function () {
echo 'Write event2';
});

$this->assertTrue($result);
// del
$eventMock->shouldReceive('del')->andReturn(true);
$eventMock->shouldReceive('isset')->andReturn(true);

$result = $swooleEvent->del($stream, EventInterface::EV_WRITE);
$this->assertTrue($result);
// del set
// -----

$eventMock->shouldReceive('del')->andReturn(true);
$eventMock->shouldReceive('set')->andReturnUsing(function ($stream, $readCallback, $writeCallback, $event) {
$this->assertTrue(is_resource($stream));
$this->assertTrue(is_int($event));
Expand All @@ -332,8 +331,12 @@ public function testAddAndDelWrite()

return true;
});
// Event::del
$eventMock->shouldReceive('isset')->andReturn(false);

$result = $swooleEvent->del($stream, EventInterface::EV_WRITE);
$this->assertTrue($result);
// Event::set
$eventMock->shouldReceive('isset')->andReturn(true);
$result = $swooleEvent->del($stream, EventInterface::EV_WRITE);
$this->assertTrue($result);
// false
Expand Down
3 changes: 0 additions & 3 deletions tests/UtilsCase/Worker/WorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ public function testWorkerUseFactoryInit()
$reflection = new \ReflectionClass(AbstractWorker::class);
$init = $reflection->getMethod('initWorkers');
$init->invoke(null);
// onWorkerStart
$start = $reflection->getProperty('onWorkerStart');
call_user_func($start->getValue($worker), $worker);

$this->assertEquals($onWorkerStart, $worker->getParentOnWorkerStart());
$this->assertEquals($onWorkerStop, $worker->getParentOnWorkerStop());
Expand Down

0 comments on commit 249fef0

Please sign in to comment.