Skip to content

Commit 3cfc49b

Browse files
committed
Add unit tests
1 parent 834c61b commit 3cfc49b

13 files changed

+211
-45
lines changed

.github/workflows/coding-standards.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
dependencies:
2020
- "locked"
2121
php-version:
22-
- "7.4"
23-
- "8.0"
2422
- "8.1"
2523
operating-system:
2624
- "ubuntu-latest"

.github/workflows/mutation-tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
dependencies:
2020
- "locked"
2121
php-version:
22-
- "7.4"
23-
- "8.0"
2422
- "8.1"
2523
operating-system:
2624
- "ubuntu-latest"

.github/workflows/phpunit.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
dependencies:
2020
- "locked"
2121
php-version:
22-
- "7.4"
23-
- "8.0"
2422
- "8.1"
2523
operating-system:
2624
- "ubuntu-latest"

.github/workflows/psalm.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
dependencies:
2020
- "locked"
2121
php-version:
22-
- "7.4"
23-
- "8.0"
2422
- "8.1"
2523
operating-system:
2624
- "ubuntu-latest"

composer.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@
1313
"name": "kpicaza"
1414
}
1515
],
16+
"repositories": [
17+
{
18+
"type": "git",
19+
"url": "https://github.com/kpicaza/antidot-framework"
20+
}
21+
],
1622
"require": {
17-
"php": "^7.4|>=8.0",
18-
"antidot-fw/framework": "^0.2|@dev",
23+
"php": ">=8.1",
24+
"antidot-fw/framework": "3.x.x-dev",
25+
"nyholm/psr7": "^1.4",
26+
"nyholm/psr7-server": "^1.0",
27+
"react/http": "^1.5",
1928
"symfony/runtime": "^5.3"
2029
},
2130
"require-dev": {

src/AntidotRunner.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
use Antidot\Framework\Application;
88
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
9-
use Nyholm\Psr7\Factory\Psr17Factory;
10-
use Nyholm\Psr7Server\ServerRequestCreator;
119
use Psr\Container\ContainerInterface;
1210
use React\Http\HttpServer;
1311
use React\Socket\SocketServer;
@@ -34,28 +32,23 @@ public function run(): int
3432

3533
private function runAsync(ContainerInterface $container): int
3634
{
35+
/** @var HttpServer $http */
3736
$http = $container->get(HttpServer::class);
37+
/** @var SocketServer $socket */
3838
$socket = $container->get(SocketServer::class);
39+
$runner = new AsyncRunner($http, $socket);
3940

40-
$http->listen($socket);
41-
42-
return 0;
41+
return $runner->run();
4342
}
4443

4544
private function runSync(ContainerInterface $container): int
4645
{
46+
/** @var Application $application */
4747
$application = $container->get(Application::class);
48-
$sapi = new SapiEmitter();
49-
$psr17Factory = new Psr17Factory();
50-
$creator = new ServerRequestCreator(
51-
$psr17Factory, // ServerRequestFactory
52-
$psr17Factory, // UriFactory
53-
$psr17Factory, // UploadedFileFactory
54-
$psr17Factory // StreamFactory
55-
);
56-
57-
$sapi->emit($application->handle($creator->fromGlobals()));
58-
59-
return 0;
48+
/** @var SapiEmitter $sapi */
49+
$sapi = $container->get(SapiEmitter::class);
50+
$runner = new SyncRunner($application, $sapi);
51+
52+
return $runner->run();
6053
}
6154
}

src/AsyncRunner.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Antidot\Runtime;
6+
7+
use React\Http\HttpServer;
8+
use React\Socket\SocketServer;
9+
10+
final class AsyncRunner
11+
{
12+
private HttpServer $httpServer;
13+
private SocketServer $socketServer;
14+
15+
public function __construct(HttpServer $httpServer, SocketServer $socketServer)
16+
{
17+
18+
$this->httpServer = $httpServer;
19+
$this->socketServer = $socketServer;
20+
}
21+
22+
public function run(): int
23+
{
24+
$this->httpServer->listen($this->socketServer);
25+
26+
return 0;
27+
}
28+
}

src/Config/ConfigProvider.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Antidot\Runtime\Config;
6+
7+
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
8+
9+
final class ConfigProvider
10+
{
11+
/**
12+
* @return array{services: array<string, string>}
13+
*/
14+
public function __invoke(): array
15+
{
16+
return [
17+
'services' => [
18+
SapiEmitter::class => SapiEmitter::class,
19+
]
20+
];
21+
}
22+
}

src/RunnerOptions.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/SyncRunner.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Antidot\Runtime;
6+
7+
use Antidot\Framework\Application;
8+
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
9+
use Nyholm\Psr7\Factory\Psr17Factory;
10+
use Nyholm\Psr7Server\ServerRequestCreator;
11+
12+
final class SyncRunner
13+
{
14+
private Application $application;
15+
private SapiEmitter $sapi;
16+
private ServerRequestCreator $responseFactory;
17+
18+
public function __construct(Application $application, SapiEmitter $sapi)
19+
{
20+
$this->application = $application;
21+
$this->sapi = $sapi;
22+
$psr17Factory = new Psr17Factory();
23+
$this->responseFactory = new ServerRequestCreator(
24+
$psr17Factory, // ServerRequestFactory
25+
$psr17Factory, // UriFactory
26+
$psr17Factory, // UploadedFileFactory
27+
$psr17Factory // StreamFactory
28+
);
29+
}
30+
31+
public function run(): int
32+
{
33+
$this->sapi->emit(
34+
$this->application->handle($this->responseFactory->fromGlobals())
35+
);
36+
37+
return 0;
38+
}
39+
}

0 commit comments

Comments
 (0)