diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 189105d..2f3eecb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,5 +12,3 @@ jobs: uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main cs: uses: innmind/github-workflows/.github/workflows/cs.yml@main - with: - php-version: '8.2' diff --git a/README.md b/README.md index d5427d1..9a8536c 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ use Innmind\Framework\{ Application, }; use Innmind\OperatingSystem\OperatingSystem; -use Innmind\TimeContinuum\{ +use Innmind\Time\{ Clock, Format, }; diff --git a/composer.json b/composer.json index 5688278..c4fcc01 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,8 @@ "issues": "http://github.com/Innmind/framework/issues" }, "require": { - "php": "~8.2", - "innmind/foundation": "~1.10", + "php": "~8.4", + "innmind/foundation": "~2.1", "innmind/di": "~3.0" }, "autoload": { @@ -30,14 +30,14 @@ } }, "require-dev": { - "innmind/static-analysis": "^1.2.1", + "innmind/static-analysis": "~1.3", "innmind/black-box": "~6.5", "innmind/coding-standard": "~2.0", - "innmind/async-http-server": "~4.0" + "innmind/async-http-server": "~5.0" }, "conflict": { "innmind/black-box": "<6.0|~7.0", - "innmind/async-http-server": "<3.0|~5.0" + "innmind/async-http-server": "<4.0|~6.0" }, "suggest": { "innmind/black-box": "For property based testing", diff --git a/docs/services.md b/docs/services.md index 4be520d..4502203 100644 --- a/docs/services.md +++ b/docs/services.md @@ -59,7 +59,7 @@ use Innmind\Framework\{ use Innmind\OperatingSystem\OperatingSystem; use Innmind\AMQP\Factory; use Innmind\IO\Sockets\Internet\Transport; -use Innmind\TimeContinuum\Period; +use Innmind\Time\Period; use Innmind\Url\Url; new class extends Http|Cli { @@ -96,7 +96,7 @@ use Innmind\Framework\{ use Innmind\OperatingSystem\OperatingSystem; use Innmind\AMQP\Factory; use Innmind\IO\Sockets\Internet\Transport; -use Innmind\TimeContinuum\Period; +use Innmind\Time\Period; use Innmind\Url\Url; new class extends Http|Cli { diff --git a/docs/testing.md b/docs/testing.md index 18725b4..227d1d7 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -50,7 +50,7 @@ use Innmind\Framework\{ Environment, }; use Innmind\OperatingSystem\Factory; -use Innmind\CLI\Environment\InMemory; +use Innmind\CLI\Environment; use PHPUnit\Framework\TestCase; final class AppTest extends TestCase @@ -65,7 +65,7 @@ final class AppTest extends TestCase new Kernel, ); - $environment = $app->run(InMemory::of( + $environment = $app->run(Environment::inMemory( [], // input chunks false, // interactive ['entrypoint.php'], // arguments diff --git a/src/Application/Async/Http.php b/src/Application/Async/Http.php index 6e9075f..b11d560 100644 --- a/src/Application/Async/Http.php +++ b/src/Application/Async/Http.php @@ -32,6 +32,7 @@ Sequence, Attempt, SideEffect, + Map, }; /** @@ -258,7 +259,7 @@ public function run($input): Attempt $run = Commands::of(Serve::of( $this->os, - static function(ServerRequest $request, OperatingSystem $os) use ( + static function(ServerRequest $request, OperatingSystem $os, Map $env) use ( $map, $container, $routes, @@ -266,7 +267,7 @@ static function(ServerRequest $request, OperatingSystem $os) use ( $mapRoute, $recover, ): Response { - $env = Environment::http($request->environment()); + $env = Environment::of($env); [$os, $env] = $map($os, $env); $container = $container($os, $env)->build(); $pipe = Pipe::new(); diff --git a/src/Environment.php b/src/Environment.php index ed3b960..e8a847b 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -4,7 +4,6 @@ namespace Innmind\Framework; use Innmind\Framework\Exception\LogicException; -use Innmind\Http\ServerRequest\Environment as HttpEnvironment; use Innmind\Immutable\{ Map, Maybe, @@ -44,18 +43,6 @@ public static function test(array $variables): self return self::of(Map::of(...$variables)); } - /** - * @psalm-pure - */ - #[\NoDiscard] - public static function http(HttpEnvironment $env): self - { - return $env->reduce( - new self(Map::of()), - static fn(self $env, $key, $value) => $env->with($key, $value), - ); - } - #[\NoDiscard] public function with(string $key, string $value): self { diff --git a/src/Main/Http.php b/src/Main/Http.php index 3dfa43d..07c1b0e 100644 --- a/src/Main/Http.php +++ b/src/Main/Http.php @@ -12,8 +12,8 @@ use Innmind\Http\{ ServerRequest, Response, - ServerRequest\Environment, }; +use Innmind\Immutable\Map; abstract class Http extends Main { @@ -21,9 +21,9 @@ abstract class Http extends Main private Application $app; #[\Override] - protected function preload(OperatingSystem $os, Environment $env): void + protected function preload(OperatingSystem $os, Map $env): void { - $this->app = static::configure(Application::http($os, AppEnv::http($env))); + $this->app = static::configure(Application::http($os, AppEnv::of($env))); } #[\Override] diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php index 2ec7d4b..1b1059d 100644 --- a/tests/ApplicationTest.php +++ b/tests/ApplicationTest.php @@ -14,7 +14,7 @@ }; use Innmind\OperatingSystem\Factory; use Innmind\CLI\{ - Environment\InMemory, + Environment as CliEnv, Command, Command\Usage, Console, @@ -105,7 +105,7 @@ public function testCliApplicationReturnsHelloWorldByDefault(): BlackBox\Proof ->prove(function($inputs, $interactive, $arguments, $variables) { $app = Application::cli(Factory::build(), $env = Environment::test($variables)); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, $arguments, @@ -113,7 +113,13 @@ public function testCliApplicationReturnsHelloWorldByDefault(): BlackBox\Proof '/', ))->unwrap(); - $this->assertSame(["Hello world\n"], $env->outputs()); + $this->assertSame( + ["Hello world\n"], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, @@ -147,7 +153,7 @@ public function testOrderOfMappingEnvironmentAndOperatingSystemIsKept(): BlackBo return $in; }); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, $arguments, @@ -173,7 +179,7 @@ public function testOrderOfMappingEnvironmentAndOperatingSystemIsKept(): BlackBo return $env; }); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, $arguments, @@ -216,7 +222,7 @@ public function usage(): Usage } }); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, ['script-name'], @@ -224,7 +230,13 @@ public function usage(): Usage '/', ))->unwrap(); - $this->assertSame(['my command output'], $env->outputs()); + $this->assertSame( + ['my command output'], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, @@ -271,7 +283,7 @@ public function usage(): Usage } }); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, ['script-name', 'my-command-a'], @@ -279,13 +291,19 @@ public function usage(): Usage '/', ))->unwrap(); - $this->assertSame(['my command A output'], $env->outputs()); + $this->assertSame( + ['my command A output'], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, )); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, ['script-name', 'my-command-b'], @@ -293,7 +311,13 @@ public function usage(): Usage '/', ))->unwrap(); - $this->assertSame(['my command B output'], $env->outputs()); + $this->assertSame( + ['my command B output'], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, @@ -320,7 +344,7 @@ public function testServicesAreNotLoadedIfNotUsed(): BlackBox\Proof $app = Application::cli(Factory::build(), Environment::test($variables)) ->service(Services::service, static fn() => throw new \Exception); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, $arguments, @@ -328,7 +352,13 @@ public function testServicesAreNotLoadedIfNotUsed(): BlackBox\Proof '/', ))->unwrap(); - $this->assertSame(["Hello world\n"], $env->outputs()); + $this->assertSame( + ["Hello world\n"], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, @@ -370,7 +400,7 @@ public function usage(): Usage }) ->service(Services::service, static fn() => Str::of('my command output')); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, ['script-name'], @@ -378,7 +408,13 @@ public function usage(): Usage '/', ))->unwrap(); - $this->assertSame(['my command output'], $env->outputs()); + $this->assertSame( + ['my command output'], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, @@ -421,7 +457,7 @@ public function usage(): Usage ->service(Services::serviceA, static fn($get) => Str::of('my command output')->append($get(Services::serviceB)->toString())) ->service(Services::serviceB, static fn() => Str::of(' twice')); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, ['script-name'], @@ -429,7 +465,13 @@ public function usage(): Usage '/', ))->unwrap(); - $this->assertSame(['my command output twice'], $env->outputs()); + $this->assertSame( + ['my command output twice'], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, @@ -481,7 +523,7 @@ public function usage(): Usage } }); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, ['script-name', 'my-command-a'], @@ -489,7 +531,13 @@ public function usage(): Usage '/', ))->unwrap(); - $this->assertSame(['my command A output'], $env->outputs()); + $this->assertSame( + ['my command A output'], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, @@ -523,7 +571,7 @@ public function testLazyCommandAreNotLoaded(): BlackBox\Proof return Str::of($output); }); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, ['script-name', 'help'], @@ -531,14 +579,20 @@ public function testLazyCommandAreNotLoaded(): BlackBox\Proof '/', ))->unwrap(); - $this->assertSame([" lazy \n", " lazy \n"], $env->outputs()); + $this->assertSame( + [" lazy \n", " lazy \n"], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, )); $this->assertFalse($loaded); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, ['script-name', 'lazy'], @@ -546,7 +600,13 @@ public function testLazyCommandAreNotLoaded(): BlackBox\Proof '/', ))->unwrap(); - $this->assertSame([$output], $env->outputs()); + $this->assertSame( + [$output], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, @@ -601,7 +661,7 @@ public function usage(): Usage } }); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, ['script-name'], @@ -609,7 +669,13 @@ public function usage(): Usage '/', ))->unwrap(); - $this->assertSame(['my command output', 'decorated'], $env->outputs()); + $this->assertSame( + ['my command output', 'decorated'], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, @@ -679,7 +745,7 @@ public function usage(): Usage } }); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, ['script-name', 'my-command-b'], @@ -687,7 +753,13 @@ public function usage(): Usage '/', ))->unwrap(); - $this->assertSame(['my command output B', (string) $testRuns], $env->outputs()); + $this->assertSame( + ['my command output B', (string) $testRuns], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, @@ -762,7 +834,7 @@ public function usage(): Usage } }); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, ['script-name'], @@ -770,7 +842,13 @@ public function usage(): Usage '/', ))->unwrap(); - $this->assertSame(['bar', 'baz', 'foo'], $env->outputs()); + $this->assertSame( + ['bar', 'baz', 'foo'], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, @@ -821,7 +899,7 @@ public function usage(): Usage } }); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, ['script-name'], @@ -829,7 +907,13 @@ public function usage(): Usage '/', ))->unwrap(); - $this->assertSame(['bar'], $env->outputs()); + $this->assertSame( + ['bar'], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, @@ -874,7 +958,7 @@ public function usage(): Usage } }); - $env = $app->run(InMemory::of( + $env = $app->run(CliEnv::inMemory( $inputs, $interactive, ['script-name'], @@ -882,7 +966,13 @@ public function usage(): Usage '/', ))->unwrap(); - $this->assertSame(['bar', 'foo=" \n watev; bar!'], $env->outputs()); + $this->assertSame( + ['bar', 'foo=" \n watev; bar!'], + $env + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertNull($env->exitCode()->match( static fn($exit) => $exit, static fn() => null, diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 5923313..58bc2b5 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -41,7 +41,7 @@ public function setUp(): void public function tearDown(): void { - $this->server->pid()->match( + $_ = $this->server->pid()->match( fn($pid) => $this->os->control()->processes()->kill( $pid, Signal::kill,