-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
162 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the sj-i/php-profiler package. | ||
* | ||
* (c) sji <sji@sj-i.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpProfiler\Inspector\Daemon\Reader; | ||
|
||
use Amp\Parallel\Sync\Channel; | ||
use Generator; | ||
use PhpProfiler\Inspector\Settings\GetTraceSettings; | ||
use PhpProfiler\Inspector\Settings\TargetPhpSettings; | ||
use PhpProfiler\Inspector\Settings\TargetProcessSettings; | ||
use PhpProfiler\Inspector\Settings\TraceLoopSettings; | ||
|
||
interface PhpReaderTaskInterface | ||
{ | ||
public function run( | ||
Channel $channel, | ||
TargetProcessSettings $target_process_settings, | ||
TraceLoopSettings $loop_settings, | ||
TargetPhpSettings $target_php_settings, | ||
GetTraceSettings $get_trace_settings | ||
): Generator; | ||
} |
116 changes: 116 additions & 0 deletions
116
tests/Inspector/Daemon/Reader/Context/PhpReaderEntryPointTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the sj-i/php-profiler package. | ||
* | ||
* (c) sji <sji@sj-i.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpProfiler\Inspector\Daemon\Reader\Context; | ||
|
||
use Amp\Parallel\Sync\Channel; | ||
use Amp\Success; | ||
use Hamcrest\Matchers; | ||
use Mockery; | ||
use PhpProfiler\Inspector\Daemon\Dispatcher\Message\DetachWorkerMessage; | ||
use PhpProfiler\Inspector\Daemon\Reader\Message\AttachMessage; | ||
use PhpProfiler\Inspector\Daemon\Reader\Message\SetSettingsMessage; | ||
use PhpProfiler\Inspector\Daemon\Reader\PhpReaderTaskInterface; | ||
use PhpProfiler\Inspector\Settings\GetTraceSettings; | ||
use PhpProfiler\Inspector\Settings\TargetPhpSettings; | ||
use PhpProfiler\Inspector\Settings\TargetProcessSettings; | ||
use PhpProfiler\Inspector\Settings\TraceLoopSettings; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PhpReaderEntryPointTest extends TestCase | ||
{ | ||
public function testRun(): void | ||
{ | ||
$php_reader_task = Mockery::mock(PhpReaderTaskInterface::class); | ||
$channel = Mockery::mock(Channel::class); | ||
$channel->expects()->receive()->andReturns(new Success(1))->once(); | ||
$channel->expects()->receive()->andReturns(new Success(2))->once(); | ||
$php_reader_task->shouldReceive('run') | ||
->withArgs( | ||
function ( | ||
$channel_passed, | ||
$target_process_settings, | ||
$trace_loop_serrings, | ||
$target_php_settings, | ||
$get_trace_settings | ||
) use ($channel) { | ||
$this->assertSame($channel, $channel_passed); | ||
$this->assertEquals( | ||
[ | ||
new TargetProcessSettings(123), | ||
new TraceLoopSettings(1, 'q', 10), | ||
new TargetPhpSettings(), | ||
new GetTraceSettings(PHP_INT_MAX), | ||
], | ||
[ | ||
$target_process_settings, | ||
$trace_loop_serrings, | ||
$target_php_settings, | ||
$get_trace_settings, | ||
] | ||
); | ||
return true; | ||
} | ||
) | ||
->andReturns( | ||
(function () { | ||
yield new Success(3); | ||
yield new Success(4); | ||
yield new Success(5); | ||
})() | ||
) | ||
; | ||
$channel->shouldReceive('send') | ||
->with(Matchers::equalTo(new DetachWorkerMessage(123))) | ||
->andReturns(new Success(6)) | ||
->once(); | ||
|
||
$php_reader_entry_point = new PhpReaderEntryPoint($php_reader_task); | ||
|
||
$generator = $php_reader_entry_point->run($channel); | ||
|
||
$promise = $generator->current(); | ||
$this->assertInstanceOf(Success::class, $promise); | ||
$promise->onResolve(fn ($error, $value) => $this->assertSame(1, $value)); | ||
|
||
$promise = $generator->send( | ||
new SetSettingsMessage( | ||
new TargetPhpSettings(), | ||
new TraceLoopSettings(1, 'q', 10), | ||
new GetTraceSettings(PHP_INT_MAX) | ||
) | ||
); | ||
$this->assertInstanceOf(Success::class, $promise); | ||
$promise->onResolve(fn ($error, $value) => $this->assertSame(1, $value)); | ||
|
||
$promise = $generator->send(new AttachMessage(123)); | ||
$this->assertInstanceOf(Success::class, $promise); | ||
$promise->onResolve(fn ($error, $value) => $this->assertSame(2, $value)); | ||
|
||
$promise = $generator->send(null); | ||
$this->assertInstanceOf(Success::class, $promise); | ||
$promise->onResolve(fn ($error, $value) => $this->assertSame(3, $value)); | ||
|
||
$promise = $generator->send(null); | ||
$this->assertInstanceOf(Success::class, $promise); | ||
$promise->onResolve(fn ($error, $value) => $this->assertSame(4, $value)); | ||
|
||
$promise = $generator->send(null); | ||
$this->assertInstanceOf(Success::class, $promise); | ||
$promise->onResolve(fn ($error, $value) => $this->assertSame(5, $value)); | ||
|
||
$promise = $generator->send(null); | ||
$this->assertInstanceOf(Success::class, $promise); | ||
$promise->onResolve(fn ($error, $value) => $this->assertSame(6, $value)); | ||
} | ||
} |