refactor: unified kernal logic clean up
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -65,6 +65,44 @@ final class KernelTest extends TestCase
|
||||
self::assertTrue($scope->terminated());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[TestDox('Runner returns execution results and terminates')]
|
||||
public function runs(): void
|
||||
{
|
||||
$processor = new RecordingProcessor();
|
||||
[$kernel] = $this->kernel($processor);
|
||||
|
||||
$result = $kernel->executionRunner()->execute(
|
||||
ExecutionDescriptor::cli(),
|
||||
static fn(): string => 'complete',
|
||||
);
|
||||
|
||||
self::assertSame('complete', $result);
|
||||
self::assertSame(1, $processor->processed);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[TestDox('Runner terminates before rethrowing execution failures')]
|
||||
public function rethrows(): void
|
||||
{
|
||||
[$kernel] = $this->kernel();
|
||||
|
||||
try {
|
||||
$kernel->executionRunner()->execute(
|
||||
ExecutionDescriptor::cli(),
|
||||
static fn() => throw new \RuntimeException('Execution failed.'),
|
||||
);
|
||||
self::fail('Expected execution to fail.');
|
||||
} catch (\RuntimeException $error) {
|
||||
self::assertSame('Execution failed.', $error->getMessage());
|
||||
}
|
||||
|
||||
$scope = $kernel->beginExecution(ExecutionDescriptor::cli());
|
||||
$kernel->terminateExecution($scope, ExecutionOutcome::success());
|
||||
|
||||
self::assertTrue($scope->terminated());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[TestDox('Only one execution scope can be active')]
|
||||
public function rejectsConcurrentScopes(): void
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace KTXT\Unit\Runtime;
|
||||
use KTXC\Application\Execution\ExecutionContext;
|
||||
use KTXC\Application\Execution\ExecutionDescriptor;
|
||||
use KTXC\Application\Execution\ExecutionOutcome;
|
||||
use KTXC\Application\Execution\ExecutionRunner;
|
||||
use KTXC\Application\Execution\ExecutionRunnerInterface;
|
||||
use KTXC\Application\Execution\ExecutionScope;
|
||||
use KTXC\Application\Execution\TerminationReport;
|
||||
use KTXC\Context\IdentityContext;
|
||||
@@ -110,6 +112,11 @@ final class ConsoleKernel implements KernelInterface
|
||||
{
|
||||
}
|
||||
|
||||
public function executionRunner(): ExecutionRunnerInterface
|
||||
{
|
||||
return new ExecutionRunner($this);
|
||||
}
|
||||
|
||||
public function beginExecution(ExecutionDescriptor $descriptor): ExecutionScope
|
||||
{
|
||||
return new ExecutionScope(
|
||||
|
||||
@@ -7,6 +7,8 @@ namespace KTXT\Unit\Runtime;
|
||||
use KTXC\Application\Execution\ExecutionContext;
|
||||
use KTXC\Application\Execution\ExecutionDescriptor;
|
||||
use KTXC\Application\Execution\ExecutionOutcome;
|
||||
use KTXC\Application\Execution\ExecutionRunner;
|
||||
use KTXC\Application\Execution\ExecutionRunnerInterface;
|
||||
use KTXC\Application\Execution\ExecutionScope;
|
||||
use KTXC\Application\Execution\TerminationReport;
|
||||
use KTXC\Context\IdentityContext;
|
||||
@@ -68,7 +70,7 @@ final class HttpRuntimeTest extends TestCase
|
||||
public function succeeds(): void
|
||||
{
|
||||
$kernel = $this->kernel(new ResponseMiddleware(new Response('ok', 200)));
|
||||
$response = (new HttpRuntime($kernel, false))->handle(Request::create('/'));
|
||||
$response = (new HttpRuntime($kernel, false))->run(Request::create('/'), send: false);
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertSame('ok', $response->getContent());
|
||||
@@ -84,7 +86,7 @@ final class HttpRuntimeTest extends TestCase
|
||||
$previousLog = ini_get('error_log');
|
||||
ini_set('error_log', '/dev/null');
|
||||
try {
|
||||
$response = (new HttpRuntime($kernel, false))->handle(Request::create('/'));
|
||||
$response = (new HttpRuntime($kernel, false))->run(Request::create('/'), send: false);
|
||||
} finally {
|
||||
ini_set('error_log', (string) $previousLog);
|
||||
}
|
||||
@@ -104,7 +106,7 @@ final class HttpRuntimeTest extends TestCase
|
||||
failures: [new \RuntimeException('Deferred listener failed.')],
|
||||
);
|
||||
|
||||
$response = (new HttpRuntime($kernel, false))->handle(Request::create('/'));
|
||||
$response = (new HttpRuntime($kernel, false))->run(Request::create('/'), send: false);
|
||||
|
||||
self::assertSame(202, $response->getStatusCode());
|
||||
self::assertSame('accepted', $response->getContent());
|
||||
@@ -144,6 +146,11 @@ final class RuntimeKernel implements KernelInterface
|
||||
{
|
||||
}
|
||||
|
||||
public function executionRunner(): ExecutionRunnerInterface
|
||||
{
|
||||
return new ExecutionRunner($this);
|
||||
}
|
||||
|
||||
public function beginExecution(ExecutionDescriptor $descriptor): ExecutionScope
|
||||
{
|
||||
$this->active = true;
|
||||
|
||||
Reference in New Issue
Block a user