Skip to content

Commit

Permalink
Remove mockery (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Jul 2, 2023
1 parent a5b04d7 commit d3b6766
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
3 changes: 1 addition & 2 deletions composer.json
Expand Up @@ -56,8 +56,7 @@
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.7",
"yiisoft/middleware-dispatcher": "^5.0",
"yiisoft/test-support": "^3.0",
"mockery/mockery": "^1.6.2"
"yiisoft/test-support": "^3.0"
},
"suggest": {
"grpc/grpc": "Needed for gRPC support",
Expand Down
2 changes: 1 addition & 1 deletion tests/RoadRunnerHttpApplicationRunnerTest.php
Expand Up @@ -53,7 +53,7 @@ public function testCheckGarbageCollector(int $gcRuns): void
$runner->run();
$this->assertSame(2, $worker->getRequestCount());

$this->assertSame($gcRuns === 0 ? 1 : 3, gc_status()['runs']);
$this->assertSame($gcRuns === 0 ? 1 : 2, gc_status()['runs']);
}

/**
Expand Down
27 changes: 8 additions & 19 deletions tests/Unit/RoadRunnerGrpcApplicationRunnerTest.php
Expand Up @@ -4,7 +4,6 @@

namespace Yiisoft\Yii\Runner\RoadRunner\Tests\Unit;

use Mockery;
use PHPUnit\Framework\TestCase;
use Service\EchoInterface;
use Service\Message;
Expand All @@ -16,8 +15,6 @@

final class RoadRunnerGrpcApplicationRunnerTest extends TestCase
{
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;

public function testSetServices(): void
{
$services = [
Expand All @@ -43,7 +40,7 @@ public function testRun(): void
'context' => [],
]
);
$relay->shouldReceive('send')->once()->withArgs(function (Frame $frame) {
$relay->expects($this->once())->method('send')->willReturnCallback(function (Frame $frame) {
return $frame->payload === '{}' . $this->packMessage('PONG');
});

Expand All @@ -66,20 +63,18 @@ private function createRunner(): RoadRunnerGrpcApplicationRunner
);
}

protected function createRelay(string $body, array $header): RelayInterface
protected function createRelay(string $body, array $header): RelayInterface|\PHPUnit\Framework\MockObject\MockObject
{
$body = $this->packMessage($body);
$header = json_encode($header, JSON_THROW_ON_ERROR);
$header1 = json_encode($header, JSON_THROW_ON_ERROR);
$header2 = json_encode(['stop' => true]);

$relay = Mockery::mock(RelayInterface::class);
$relay->shouldReceive('waitFrame')->once()->andReturn(
new Frame($header . $body, [mb_strlen($header)])
$relay = $this->createMock(RelayInterface::class);
$relay->expects($this->exactly(2))->method('waitFrame')->willReturnOnConsecutiveCalls(
new Frame($header1 . $body, [mb_strlen($header1)]),
new Frame($header2, [mb_strlen($header2)], Frame::CONTROL)
);

$header = json_encode(['stop' => true]);
$relay->shouldReceive('waitFrame')->once()->andReturn(
new Frame($header, [mb_strlen($header)], Frame::CONTROL)
);

return $relay;
}
Expand All @@ -90,10 +85,4 @@ private function packMessage(string $message): string
->setMsg($message)
->serializeToString();
}

public function tearDown(): void
{
parent::tearDown();
Mockery::close();
}
}

0 comments on commit d3b6766

Please sign in to comment.