diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9a1746..9f6e6d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: CI -on: [push] +on: [push, pull_request] jobs: phpunit: @@ -8,7 +8,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macOS-latest] - php-version: ['8.2', '8.3'] + php-version: ['8.4', '8.5'] dependencies: ['lowest', 'highest'] name: 'PHPUnit' steps: @@ -31,41 +31,6 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} psalm: - runs-on: ubuntu-latest - strategy: - matrix: - php-version: ['8.2', '8.3'] - dependencies: ['lowest', 'highest'] - name: 'Psalm' - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, intl - - name: Composer - uses: "ramsey/composer-install@v3" - with: - dependency-versions: ${{ matrix.dependencies }} - - name: Psalm - run: vendor/bin/psalm --shepherd + uses: innmind/github-workflows/.github/workflows/psalm-matrix.yml@main cs: - runs-on: ubuntu-latest - strategy: - matrix: - php-version: ['8.2'] - name: 'CS' - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - extensions: mbstring, intl - - name: Composer - uses: "ramsey/composer-install@v3" - - name: CS - run: vendor/bin/php-cs-fixer fix --diff --dry-run + uses: innmind/github-workflows/.github/workflows/cs.yml@main diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cf6d52..50f7f8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [Unreleased] + +### Changed + +- Requires PHP `8.4` +- Requires `innmind/foundation:~2.1` +- Requires `innmind/framework:~4.0` + ## 3.8.0 - 2024-11-11 ### Changed diff --git a/composer.json b/composer.json index 4abe58f..ed351d5 100644 --- a/composer.json +++ b/composer.json @@ -15,15 +15,11 @@ "issues": "http://github.com/Innmind/DependencyGraph/issues" }, "require": { - "php": "~8.2", - "innmind/immutable": "~5.10", - "innmind/url": "~4.1", - "innmind/operating-system": "~4.1|~5.0", - "innmind/json": "^1.1", - "innmind/graphviz": "~3.1", + "php": "~8.4", + "innmind/foundation": "~2.1", + "innmind/graphviz": "~5.0", "composer/semver": "^3.4.4", - "innmind/framework": "~2.0", - "innmind/validation": "~1.7" + "innmind/framework": "~4.0" }, "autoload": { "psr-4": { @@ -36,9 +32,9 @@ } }, "require-dev": { - "phpunit/phpunit": "~10.2", - "vimeo/psalm": "~5.15", - "innmind/black-box": "~5.5", + "phpunit/phpunit": "~12.0", + "innmind/static-analysis": "~1.3", + "innmind/black-box": "~6.5", "innmind/coding-standard": "~2.0" }, "bin": ["dependency-graph"] diff --git a/src/Command/CheckDotInstalled.php b/src/Command/CheckDotInstalled.php index b938acd..91a4fa8 100644 --- a/src/Command/CheckDotInstalled.php +++ b/src/Command/CheckDotInstalled.php @@ -6,12 +6,16 @@ use Innmind\CLI\{ Console, Command, + Command\Usage, }; use Innmind\Server\Control\Server\{ Processes, Command as Process }; -use Innmind\Immutable\Str; +use Innmind\Immutable\{ + Str, + Attempt, +}; final class CheckDotInstalled implements Command { @@ -24,7 +28,8 @@ public function __construct(Command $command, Processes $processes) $this->processes = $processes; } - public function __invoke(Console $console): Console + #[\Override] + public function __invoke(Console $console): Attempt { /** @psalm-suppress ArgumentTypeCoercion Due to the environment variables */ return $this @@ -36,19 +41,24 @@ public function __invoke(Console $console): Console static fn($name) => $name === 'PATH', )), ) - ->wait() + ->flatMap( + static fn($process) => $process + ->wait() + ->attempt(static fn() => new \Exception), + ) ->match( fn() => ($this->command)($console), static fn() => $console - ->output(Str::of("Graphviz needs to be installed first\n")) - ->exit(1), + ->exit(1) + ->output(Str::of("Graphviz needs to be installed first\n")), ); } /** * @psalm-mutation-free */ - public function usage(): string + #[\Override] + public function usage(): Usage { return $this->command->usage(); } diff --git a/src/Command/DependsOn.php b/src/Command/DependsOn.php index 9005999..f196f10 100644 --- a/src/Command/DependsOn.php +++ b/src/Command/DependsOn.php @@ -12,11 +12,13 @@ }; use Innmind\CLI\{ Command, + Command\Usage, Console, }; use Innmind\Immutable\{ Set, Str, + Attempt, }; final class DependsOn implements Command @@ -32,7 +34,8 @@ public function __construct(Dependents $load, Save $save, Display $display) $this->display = $display; } - public function __invoke(Console $console): Console + #[\Override] + public function __invoke(Console $console): Attempt { /** @psalm-suppress MixedArgumentTypeCoercion Due to the reduce */ $vendors = $console @@ -63,21 +66,24 @@ public function __invoke(Console $console): Console $fileName = $fileName->prepend('direct_'); } - return $console - ->options() - ->maybe('output') - ->match( - fn() => ($this->display)($console, $packages), - fn() => ($this->save)($console, $fileName, $packages), - ); + return Attempt::result( + $console + ->options() + ->maybe('output') + ->match( + fn() => ($this->display)($console, $packages), + fn() => ($this->save)($console, $fileName, $packages), + ), + ); } /** * @psalm-pure */ - public function usage(): string + #[\Override] + public function usage(): Usage { - return <<display = $display; } - public function __invoke(Console $console): Console + #[\Override] + public function __invoke(Console $console): Attempt { $packages = ($this->load)($console->workingDirectory()); if ($packages->empty()) { return $console - ->error(Str::of("No packages found\n")) - ->exit(1); + ->exit(1) + ->error(Str::of("No packages found\n")); } $fileName = Str::of('dependencies.svg'); - return $console - ->options() - ->maybe('output') - ->match( - fn() => ($this->display)($console, $packages), - fn() => ($this->save)($console, $fileName, $packages), - ); + return Attempt::result( + $console + ->options() + ->maybe('output') + ->match( + fn() => ($this->display)($console, $packages), + fn() => ($this->save)($console, $fileName, $packages), + ), + ); } /** * @psalm-pure */ - public function usage(): string + #[\Override] + public function usage(): Usage { - return <<display = $display; } - public function __invoke(Console $console): Console + #[\Override] + public function __invoke(Console $console): Attempt { $packages = ($this->load)(Name::of($console->arguments()->get('package'))); $fileName = Str::of($console->arguments()->get('package')) ->replace('/', '_') ->append('_dependencies.svg'); - return $console - ->options() - ->maybe('output') - ->match( - fn() => ($this->display)($console, $packages), - fn() => ($this->save)($console, $fileName, $packages), - ); + return Attempt::result( + $console + ->options() + ->maybe('output') + ->match( + fn() => ($this->display)($console, $packages), + fn() => ($this->save)($console, $fileName, $packages), + ), + ); } /** * @psalm-pure */ - public function usage(): string + #[\Override] + public function usage(): Usage { - return <<display = $display; } - public function __invoke(Console $console): Console + #[\Override] + public function __invoke(Console $console): Attempt { $packages = ($this->load)($vendor = Name::of($console->arguments()->get('vendor'))); $fileName = Str::of("{$vendor->toString()}.svg"); - return $console - ->options() - ->maybe('output') - ->match( - fn() => ($this->display)($console, $packages), - fn() => ($this->save)($console, $fileName, $packages), - ); + return Attempt::result( + $console + ->options() + ->maybe('output') + ->match( + fn() => ($this->display)($console, $packages), + fn() => ($this->save)($console, $fileName, $packages), + ), + ); } /** * @psalm-pure */ - public function usage(): string + #[\Override] + public function usage(): Usage { - return <<withShortOption('Tsvg') ->withWorkingDirectory($console->workingDirectory()) ->withInput(($this->render)($packages)), - ); + ) + ->unwrap(); $console = $process ->output() - ->reduce( - $console, - static fn(Console $console, $output) => $console->output($output), - ); + ->map(static fn($chunk) => $chunk->data()) + ->sink($console) + ->attempt(static fn($console, $output) => $console->output($output)) + ->unwrap(); return $process ->wait() diff --git a/src/Exception/DomainException.php b/src/Exception/DomainException.php index c834c71..c9a8eae 100644 --- a/src/Exception/DomainException.php +++ b/src/Exception/DomainException.php @@ -3,6 +3,6 @@ namespace Innmind\DependencyGraph\Exception; -class DomainException extends \DomainException implements Exception +final class DomainException extends \DomainException implements Exception { } diff --git a/src/Kernel.php b/src/Kernel.php index a55d669..b98e020 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -10,47 +10,53 @@ final class Kernel implements Middleware { + #[\Override] public function __invoke(Application $app): Application { /** @psalm-suppress ArgumentTypeCoercion */ return $app - ->service('render', static fn() => new Render) - ->service('save', static fn($get, $os) => new Save( - $get('render'), + ->service(Services::render, static fn() => new Render) + ->service(Services::save, static fn($get, $os) => new Save( + $get(Services::render), $os->control()->processes(), )) - ->service('display', static fn($get, $os) => new Display( - $get('render'), + ->service(Services::display, static fn($get, $os) => new Display( + $get(Services::render), $os->control()->processes(), )) - ->service('package', static fn($_, $os) => new Loader\Package($os->remote()->http())) - ->service('vendor', static fn($get, $os) => new Loader\Vendor( + ->service(Services::package, static fn($_, $os) => new Loader\Package($os->remote()->http())) + ->service(Services::vendor, static fn($get, $os) => new Loader\Vendor( $os->remote()->http(), - $get('package'), + $get(Services::package()), )) - ->mapCommand(static fn($command, $_, $os) => new Command\CheckDotInstalled( + ->service(Services::filesystem, static fn($_, $os) => $os->filesystem()) + ->service(Services::processes, static fn($_, $os) => $os->control()->processes()) + ->mapCommand(static fn($command, $get) => new Command\CheckDotInstalled( $command, - $os->control()->processes(), + $get(Services::processes()), )) - ->command(static fn($get, $os) => new Command\FromLock( - new Loader\ComposerLock($os->filesystem()), - $get('save'), - $get('display'), + ->command(static fn($get) => new Command\FromLock( + new Loader\ComposerLock($get(Services::filesystem())), + $get(Services::save()), + $get(Services::display()), )) ->command(static fn($get) => new Command\DependsOn( - new Loader\Dependents($get('vendor')), - $get('save'), - $get('display'), + new Loader\Dependents($get(Services::vendor())), + $get(Services::save()), + $get(Services::display()), )) ->command(static fn($get) => new Command\Of( - new Loader\Dependencies($get('package')), - $get('save'), - $get('display'), + new Loader\Dependencies($get(Services::package())), + $get(Services::save()), + $get(Services::display()), )) ->command(static fn($get) => new Command\Vendor( - new Loader\VendorDependencies($get('vendor'), $get('package')), - $get('save'), - $get('display'), + new Loader\VendorDependencies( + $get(Services::vendor()), + $get(Services::package()), + ), + $get(Services::save()), + $get(Services::display()), )); } } diff --git a/src/Loader/ComposerLock.php b/src/Loader/ComposerLock.php index 5db4f7c..ac4ea08 100644 --- a/src/Loader/ComposerLock.php +++ b/src/Loader/ComposerLock.php @@ -26,6 +26,7 @@ }; use Innmind\Immutable\{ Set, + Map, Maybe, Predicate\Instance, }; @@ -79,11 +80,15 @@ public function __invoke(Path $path): Set ->optional( 'require', Is::associativeArray( - Is::string()->map(Name::maybe(...)), + Is::string(), Is::string()->map(Constraint::maybe(...)), ) ->map( static fn($requires) => $requires + ->flatMap(static fn($name, $constraint) => Map::of([ + Name::maybe($name), + $constraint, + ])) ->map(Maybe::all(...)) ->values() ->flatMap( @@ -130,7 +135,8 @@ public function __invoke(Path $path): Set return $this ->filesystem ->mount($path) - ->get(FileName::of('composer.lock')) + ->maybe() + ->flatMap(static fn($adapter) => $adapter->get(FileName::of('composer.lock'))) ->keep(Instance::of(File::class)) ->map(static fn($file) => $file->content()->toString()) ->map(Json::decode(...)) diff --git a/src/Package/Constraint.php b/src/Package/Constraint.php index 49edb6d..043f7e9 100644 --- a/src/Package/Constraint.php +++ b/src/Package/Constraint.php @@ -15,6 +15,7 @@ */ final class Constraint { + /** @var non-empty-string */ private string $value; public function __construct(string $value) @@ -23,6 +24,7 @@ public function __construct(string $value) throw new DomainException; } + /** @var non-empty-string */ $this->value = $value; } @@ -44,6 +46,9 @@ public function satisfiedBy(Version $version): bool return Semver::satisfies($version->toString(), $this->value); } + /** + * @return non-empty-string + */ public function toString(): string { return $this->value; diff --git a/src/Package/Name.php b/src/Package/Name.php index 2ef2674..6c9c13d 100644 --- a/src/Package/Name.php +++ b/src/Package/Name.php @@ -18,6 +18,7 @@ final class Name { private Vendor\Name $vendor; + /** @var non-empty-string */ private string $package; private function __construct(Vendor\Name $vendor, string $package) @@ -27,6 +28,7 @@ private function __construct(Vendor\Name $vendor, string $package) } $this->vendor = $vendor; + /** @var non-empty-string */ $this->package = $package; } @@ -71,6 +73,9 @@ public function vendor(): Vendor\Name return $this->vendor; } + /** + * @return non-empty-string + */ public function package(): string { return $this->package; @@ -81,6 +86,9 @@ public function equals(self $self): bool return $this->toString() === $self->toString(); } + /** + * @return non-empty-string + */ public function toString(): string { return $this->vendor->toString().'/'.$this->package; diff --git a/src/Render.php b/src/Render.php index d9ce541..0913829 100644 --- a/src/Render.php +++ b/src/Render.php @@ -30,6 +30,7 @@ public function __construct(?Locate $locate = null) /** * @psalm-pure */ + #[\Override] public function __invoke(Package $package): Url { return $package->packagist()->withFragment(Fragment::of( diff --git a/src/Render/Cluster.php b/src/Render/Cluster.php index ca40df6..ded8b29 100644 --- a/src/Render/Cluster.php +++ b/src/Render/Cluster.php @@ -21,9 +21,9 @@ private function __construct() public static function of(Vendor $vendor): Graph { $name = $vendor->name()->toString(); - $cluster = Graph::directed( - Str::of($name)->replace('-', '_')->toString(), - ) + /** @var non-empty-string */ + $cluster = Str::of($name)->replace('-', '_')->toString(); + $cluster = Graph::directed($cluster) ->displayAs($name) ->target($vendor->packagist()); diff --git a/src/Render/PackageNode.php b/src/Render/PackageNode.php index 3f80f7d..3ec011a 100644 --- a/src/Render/PackageNode.php +++ b/src/Render/PackageNode.php @@ -46,6 +46,7 @@ public static function graph(Locate $locate, Set $packages): Set */ public static function of(Name $name): Node { + /** @var non-empty-string */ $name = Str::of($name->toString()) ->replace('-', '_') ->replace('.', '_') diff --git a/src/Save.php b/src/Save.php index 3587c9c..1355f81 100644 --- a/src/Save.php +++ b/src/Save.php @@ -44,18 +44,21 @@ public function __invoke( ->withShortOption('o', $file->toString()) ->withWorkingDirectory($console->workingDirectory()) ->withInput(($this->render)($packages)), - ); + ) + ->unwrap(); return $process ->wait() ->match( - static fn() => $console->output($file->append("\n")), + static fn() => $console + ->output($file->append("\n")) + ->unwrap(), static fn() => $process ->output() - ->reduce( - $console, - static fn(Console $console, $output) => $console->error($output), - ) + ->map(static fn($chunk) => $chunk->data()) + ->sink($console) + ->attempt(static fn($console, $output) => $console->error($output)) + ->unwrap() ->exit(1), ); } diff --git a/src/Services.php b/src/Services.php new file mode 100644 index 0000000..faed736 --- /dev/null +++ b/src/Services.php @@ -0,0 +1,85 @@ + + */ +enum Services implements Service +{ + case render; + case save; + case display; + case package; + case vendor; + case filesystem; + case processes; + + /** + * @return Service + */ + public static function render(): Service + { + /** @var Service */ + return self::render; + } + + /** + * @return Service + */ + public static function save(): Service + { + /** @var Service */ + return self::save; + } + + /** + * @return Service + */ + public static function display(): Service + { + /** @var Service */ + return self::display; + } + + /** + * @return Service + */ + public static function package(): Service + { + /** @var Service */ + return self::package; + } + + /** + * @return Service + */ + public static function vendor(): Service + { + /** @var Service */ + return self::vendor; + } + + /** + * @return Service + */ + public static function filesystem(): Service + { + /** @var Service */ + return self::filesystem; + } + + /** + * @return Service + */ + public static function processes(): Service + { + /** @var Service */ + return self::processes; + } +} diff --git a/src/Vendor/Name.php b/src/Vendor/Name.php index 53ea4eb..65bfcac 100644 --- a/src/Vendor/Name.php +++ b/src/Vendor/Name.php @@ -14,6 +14,7 @@ */ final class Name { + /** @var non-empty-string */ private string $value; private function __construct(string $value) @@ -22,6 +23,7 @@ private function __construct(string $value) throw new DomainException; } + /** @var non-empty-string */ $this->value = $value; } @@ -50,6 +52,9 @@ public function equals(self $self): bool return $this->toString() === $self->toString(); } + /** + * @return non-empty-string + */ public function toString(): string { return $this->value; diff --git a/tests/Command/CheckDotInstalledTest.php b/tests/Command/CheckDotInstalledTest.php index d9edaa2..1e53872 100644 --- a/tests/Command/CheckDotInstalledTest.php +++ b/tests/Command/CheckDotInstalledTest.php @@ -9,20 +9,16 @@ Command, Command\Arguments, Command\Options, + Command\Usage, Environment, }; -use Innmind\Server\Control\Server\{ - Processes, - Process, - Process\ExitCode, - Process\Failed, - Process\Output\Output, +use Innmind\Server\Control\{ + Server, + Server\Process\Builder, }; use Innmind\Immutable\{ Str, - Either, - SideEffect, - Sequence, + Attempt, }; use PHPUnit\Framework\TestCase; use Innmind\BlackBox\{ @@ -37,38 +33,35 @@ class CheckDotInstalledTest extends TestCase public function testCallCommandIfInstalled() { $this - ->forAll(Set\Strings::any()) + ->forAll(Set::of('some', 'command', 'name')) ->then(function($usage) { $inner = new class($usage) implements Command { public function __construct(private string $usage) { } - public function __invoke(Console $console): Console + public function __invoke(Console $console): Attempt { return $console->output(Str::of('all good')); } - public function usage(): string + public function usage(): Usage { - return $this->usage; + return Usage::parse($this->usage); } }; - $processes = $this->createMock(Processes::class); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command) { - return $command->toString() === "dot '--help'"; - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::right(new SideEffect)); - $command = new CheckDotInstalled($inner, $processes); + $server = Server::via( + function($command) { + $this->assertSame("dot '--help'", $command->toString()); + + return Attempt::result( + Builder::foreground(2)->build(), + ); + }, + ); + $command = new CheckDotInstalled($inner, $server->processes()); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, [], @@ -79,11 +72,15 @@ public function usage(): string new Options, ); - $console = $command($console); + $console = $command($console)->unwrap(); $this->assertSame( ['all good'], - $console->environment()->outputs(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); }); } @@ -91,41 +88,37 @@ public function usage(): string public function testReturnErrorWhenNotInstalled() { $this - ->forAll(Set\Strings::any()) + ->forAll(Set::of('some', 'command', 'name')) ->then(function($usage) { $inner = new class($usage) implements Command { public function __construct(private string $usage) { } - public function __invoke(Console $console): Console + public function __invoke(Console $console): Attempt { return $console->output(Str::of('all good')); } - public function usage(): string + public function usage(): Usage { - return $this->usage; + return Usage::parse($this->usage); } }; - $processes = $this->createMock(Processes::class); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command) { - return $command->toString() === "dot '--help'"; - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::left(new Failed( - new ExitCode(127), - new Output(Sequence::of()), - ))); - $command = new CheckDotInstalled($inner, $processes); + $server = Server::via( + function($command) { + $this->assertSame("dot '--help'", $command->toString()); + + return Attempt::result( + Builder::foreground(2) + ->failed(127) + ->build(), + ); + }, + ); + $command = new CheckDotInstalled($inner, $server->processes()); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, [], @@ -136,7 +129,7 @@ public function usage(): string new Options, ); - $console = $command($console); + $console = $command($console)->unwrap(); $this->assertSame( 1, @@ -147,7 +140,11 @@ public function usage(): string ); $this->assertSame( ["Graphviz needs to be installed first\n"], - $console->environment()->outputs(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); }); } @@ -155,29 +152,33 @@ public function usage(): string public function testUsage() { $this - ->forAll(Set\Strings::any()) + ->forAll(Set::of('some', 'command', 'name')) ->then(function($usage) { $inner = new class($usage) implements Command { public function __construct(private string $usage) { } - public function __invoke(Console $console): Console + public function __invoke(Console $console): Attempt { return $console; } - public function usage(): string + public function usage(): Usage { - return $this->usage; + return Usage::parse($this->usage); } }; - $processes = $this->createMock(Processes::class); - $command = new CheckDotInstalled($inner, $processes); + $server = Server::via( + static fn() => Attempt::result( + Builder::foreground(2)->build(), + ), + ); + $command = new CheckDotInstalled($inner, $server->processes()); $this->assertSame( - $usage, - $command->usage(), + "$usage --help --no-interaction", + $command->usage()->toString(), ); }); } diff --git a/tests/Command/DependsOnTest.php b/tests/Command/DependsOnTest.php index 09d217a..5248ffb 100644 --- a/tests/Command/DependsOnTest.php +++ b/tests/Command/DependsOnTest.php @@ -19,20 +19,15 @@ Environment, Console, }; -use Innmind\Server\Control\Server\{ - Processes, - Process, - Process\ExitCode, - Process\Output, +use Innmind\Server\Control\{ + Server, + Server\Process\Builder, }; -use Innmind\HttpTransport\Curl; -use Innmind\TimeContinuum\Earth\Clock; +use Innmind\HttpTransport\Transport; +use Innmind\Time\Clock; use Innmind\Immutable\{ Map, - Sequence, - Str, - Either, - SideEffect, + Attempt, }; use PHPUnit\Framework\TestCase; @@ -42,7 +37,9 @@ class DependsOnTest extends TestCase public function setUp(): void { - $this->http = Curl::of(new Clock)->maxConcurrency(20); + $this->http = Transport::curl(Clock::live())->map( + static fn($config) => $config->limitConcurrencyTo(20), + ); } public function testInterface() @@ -55,11 +52,11 @@ public function testInterface() ), new Save( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), ), ); @@ -68,7 +65,7 @@ public function testInterface() public function testUsage() { $expected = <<createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), - ))->usage(), + ))->usage()->toString(), ); } public function testInvokation() { + $server = Server::via( + function($command) { + $this->assertSame( + "dot '-Tsvg' '-o' 'innmind_immutable_dependents.svg'", + $command->toString(), + ); + $this->assertSame( + __DIR__.'/../../fixtures/', + $command->workingDirectory()->match( + static fn($path) => $path->toString(), + static fn() => null, + ), + ); + $this->assertNotNull($command->input()->match( + static fn($input) => $input->toString(), + static fn() => null, + )); + + return Attempt::result( + Builder::foreground(2)->build(), + ); + }, + ); $command = new DependsOn( new Dependents( new Vendor( @@ -109,34 +129,15 @@ public function testInvokation() ), new Save( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command): bool { - return $command->toString() === "dot '-Tsvg' '-o' 'innmind_immutable_dependents.svg'" && - __DIR__.'/../../fixtures/' === $command->workingDirectory()->match( - static fn($path) => $path->toString(), - static fn() => null, - ) && - null !== $command->input()->match( - static fn($input) => $input->toString(), - static fn() => null, - ); - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::right(new SideEffect)); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, ['innmind/immutable', 'innmind'], @@ -147,10 +148,14 @@ public function testInvokation() new Options, ); - $console = $command($console); + $console = $command($console)->unwrap(); $this->assertSame( ["innmind_immutable_dependents.svg\n"], - $console->environment()->outputs(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); $this->assertNull($console->environment()->exitCode()->match( static fn($code) => $code, @@ -160,6 +165,29 @@ public function testInvokation() public function testGenerateOnlyDirectDependents() { + $server = Server::via( + function($command) { + $this->assertSame( + "dot '-Tsvg' '-o' 'direct_innmind_immutable_dependents.svg'", + $command->toString(), + ); + $this->assertSame( + __DIR__.'/../../fixtures/', + $command->workingDirectory()->match( + static fn($path) => $path->toString(), + static fn() => null, + ), + ); + $this->assertNotNull($command->input()->match( + static fn($input) => $input->toString(), + static fn() => null, + )); + + return Attempt::result( + Builder::foreground(2)->build(), + ); + }, + ); $command = new DependsOn( new Dependents( new Vendor( @@ -169,34 +197,15 @@ public function testGenerateOnlyDirectDependents() ), new Save( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command): bool { - return $command->toString() === "dot '-Tsvg' '-o' 'direct_innmind_immutable_dependents.svg'" && - __DIR__.'/../../fixtures/' === $command->workingDirectory()->match( - static fn($path) => $path->toString(), - static fn() => null, - ) && - null !== $command->input()->match( - static fn($input) => $input->toString(), - static fn() => null, - ); - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::right(new SideEffect)); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, ['innmind/immutable', 'innmind', '--direct'], @@ -207,10 +216,14 @@ public function testGenerateOnlyDirectDependents() new Options(Map::of(['direct', ''])), ); - $console = $command($console); + $console = $command($console)->unwrap(); $this->assertSame( ["direct_innmind_immutable_dependents.svg\n"], - $console->environment()->outputs(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); $this->assertNull($console->environment()->exitCode()->match( static fn($code) => $code, @@ -220,6 +233,31 @@ public function testGenerateOnlyDirectDependents() public function testExitWithProcessOutputWhenItFails() { + $server = Server::via( + function($command) { + $this->assertSame( + "dot '-Tsvg' '-o' 'innmind_immutable_dependents.svg'", + $command->toString(), + ); + $this->assertSame( + __DIR__.'/../../fixtures/', + $command->workingDirectory()->match( + static fn($path) => $path->toString(), + static fn() => null, + ), + ); + $this->assertNotNull($command->input()->match( + static fn($input) => $input->toString(), + static fn() => null, + )); + + return Attempt::result( + Builder::foreground(2) + ->failed(1, [['foo', 'output']]) + ->build(), + ); + }, + ); $command = new DependsOn( new Dependents( new Vendor( @@ -229,40 +267,15 @@ public function testExitWithProcessOutputWhenItFails() ), new Save( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command): bool { - return $command->toString() === "dot '-Tsvg' '-o' 'innmind_immutable_dependents.svg'" && - __DIR__.'/../../fixtures/' === $command->workingDirectory()->match( - static fn($path) => $path->toString(), - static fn() => null, - ) && - null !== $command->input()->match( - static fn($input) => $input->toString(), - static fn() => null, - ); - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::left(new ExitCode(1))); - $process - ->expects($this->once()) - ->method('output') - ->willReturn(new Output\Output(Sequence::of( - [Str::of('foo'), Output\Type::output], - ))); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, ['innmind/immutable', 'innmind'], @@ -273,9 +286,15 @@ public function testExitWithProcessOutputWhenItFails() new Options, ); - $console = $command($console); - $this->assertSame([], $console->environment()->outputs()); - $this->assertSame(['foo'], $console->environment()->errors()); + $console = $command($console)->unwrap(); + $this->assertSame( + ['foo'], + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertSame(1, $console->environment()->exitCode()->match( static fn($code) => $code->toInt(), static fn() => null, @@ -284,6 +303,34 @@ public function testExitWithProcessOutputWhenItFails() public function testOutputSvg() { + $server = Server::via( + function($command) { + $this->assertSame( + "dot '-Tsvg'", + $command->toString(), + ); + $this->assertSame( + __DIR__.'/../../fixtures/', + $command->workingDirectory()->match( + static fn($path) => $path->toString(), + static fn() => null, + ), + ); + $this->assertNotNull($command->input()->match( + static fn($input) => $input->toString(), + static fn() => null, + )); + + return Attempt::result( + Builder::foreground(2) + ->success([ + ['', 'output'], + ['', 'output'], + ]) + ->build(), + ); + }, + ); $command = new DependsOn( new Dependents( new Vendor( @@ -293,41 +340,15 @@ public function testOutputSvg() ), new Save( new Render, - $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command): bool { - return $command->toString() === "dot '-Tsvg'" && - __DIR__.'/../../fixtures/' === $command->workingDirectory()->match( - static fn($path) => $path->toString(), - static fn() => null, - ) && - null !== $command->input()->match( - static fn($input) => $input->toString(), - static fn() => null, - ); - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::right(new SideEffect)); - $process - ->expects($this->once()) - ->method('output') - ->willReturn(new Output\Output(Sequence::of( - [Str::of(''), Output\Type::output], - [Str::of(''), Output\Type::output], - ))); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, ['innmind/immutable', 'innmind', '--output'], @@ -338,10 +359,14 @@ public function testOutputSvg() new Options(Map::of(['output', ''])), ); - $console = $command($console); + $console = $command($console)->unwrap(); $this->assertSame( ['', ''], - $console->environment()->outputs(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); $this->assertNull($console->environment()->exitCode()->match( static fn($code) => $code, diff --git a/tests/Command/FromLockTest.php b/tests/Command/FromLockTest.php index 04dea7a..66adfb0 100644 --- a/tests/Command/FromLockTest.php +++ b/tests/Command/FromLockTest.php @@ -18,17 +18,12 @@ Console, }; use Innmind\OperatingSystem\Factory; -use Innmind\Server\Control\Server\{ - Processes, - Process, - Process\ExitCode, - Process\Output, +use Innmind\Server\Control\{ + Server, + Server\Process\Builder, }; use Innmind\Immutable\{ - Str, - Either, - SideEffect, - Sequence, + Attempt, Map, }; use PHPUnit\Framework\TestCase; @@ -50,11 +45,11 @@ public function testInterface() new ComposerLock($this->filesystem), new Save( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), ), ); @@ -63,7 +58,7 @@ public function testInterface() public function testUsage() { $expected = <<filesystem), new Save( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), - ))->usage(), + ))->usage()->toString(), ); } public function testExitWhenFileNotFound() { + $server = Server::via(static fn() => null); $command = new FromLock( new ComposerLock($this->filesystem), new Save( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->never()) - ->method('execute'); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, [], @@ -114,9 +107,15 @@ public function testExitWhenFileNotFound() new Options, ); - $console = $command($console); - $this->assertSame([], $console->environment()->outputs()); - $this->assertSame(["No packages found\n"], $console->environment()->errors()); + $console = $command($console)->unwrap(); + $this->assertSame( + ["No packages found\n"], + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), + ); $this->assertSame(1, $console->environment()->exitCode()->match( static fn($code) => $code->toInt(), static fn() => null, @@ -125,38 +124,42 @@ public function testExitWhenFileNotFound() public function testInvokation() { + $server = Server::via( + function($command) { + $this->assertSame( + "dot '-Tsvg' '-o' 'dependencies.svg'", + $command->toString(), + ); + $this->assertSame( + __DIR__.'/../../fixtures/', + $command->workingDirectory()->match( + static fn($path) => $path->toString(), + static fn() => null, + ), + ); + $this->assertNotNull($command->input()->match( + static fn($input) => $input->toString(), + static fn() => null, + )); + + return Attempt::result( + Builder::foreground(2)->build(), + ); + }, + ); $command = new FromLock( new ComposerLock($this->filesystem), new Save( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command): bool { - return $command->toString() === "dot '-Tsvg' '-o' 'dependencies.svg'" && - __DIR__.'/../../fixtures/' === $command->workingDirectory()->match( - static fn($path) => $path->toString(), - static fn() => null, - ) && - null !== $command->input()->match( - static fn($input) => $input->toString(), - static fn() => null, - ); - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::right(new SideEffect)); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, [], @@ -167,53 +170,57 @@ public function testInvokation() new Options, ); - $console = $command($console); + $console = $command($console)->unwrap(); $this->assertSame( ["dependencies.svg\n"], - $console->environment()->outputs(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); } public function testExitWithProcessOutputWhenItFails() { + $server = Server::via( + function($command) { + $this->assertSame( + "dot '-Tsvg' '-o' 'dependencies.svg'", + $command->toString(), + ); + $this->assertSame( + __DIR__.'/../../fixtures/', + $command->workingDirectory()->match( + static fn($path) => $path->toString(), + static fn() => null, + ), + ); + $this->assertNotNull($command->input()->match( + static fn($input) => $input->toString(), + static fn() => null, + )); + + return Attempt::result( + Builder::foreground(2) + ->failed(1, [['foo', 'output']]) + ->build(), + ); + }, + ); $command = new FromLock( new ComposerLock($this->filesystem), new Save( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command): bool { - return $command->toString() === "dot '-Tsvg' '-o' 'dependencies.svg'" && - __DIR__.'/../../fixtures/' === $command->workingDirectory()->match( - static fn($path) => $path->toString(), - static fn() => null, - ) && - null !== $command->input()->match( - static fn($input) => $input->toString(), - static fn() => null, - ); - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::left(new ExitCode(1))); - $process - ->expects($this->once()) - ->method('output') - ->willReturn(new Output\Output(Sequence::of( - [Str::of('foo'), Output\Type::output], - ))); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, [], @@ -224,10 +231,14 @@ public function testExitWithProcessOutputWhenItFails() new Options, ); - $console = $command($console); + $console = $command($console)->unwrap(); $this->assertSame( ['foo'], - $console->environment()->errors(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); $this->assertSame(1, $console->environment()->exitCode()->match( static fn($code) => $code->toInt(), @@ -237,45 +248,47 @@ public function testExitWithProcessOutputWhenItFails() public function testOutputSvg() { + $server = Server::via( + function($command) { + $this->assertSame( + "dot '-Tsvg'", + $command->toString(), + ); + $this->assertSame( + __DIR__.'/../../fixtures/', + $command->workingDirectory()->match( + static fn($path) => $path->toString(), + static fn() => null, + ), + ); + $this->assertNotNull($command->input()->match( + static fn($input) => $input->toString(), + static fn() => null, + )); + + return Attempt::result( + Builder::foreground(2) + ->success([ + ['', 'output'], + ['', 'output'], + ]) + ->build(), + ); + }, + ); $command = new FromLock( new ComposerLock($this->filesystem), new Save( new Render, - $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command): bool { - return $command->toString() === "dot '-Tsvg'" && - __DIR__.'/../../fixtures/' === $command->workingDirectory()->match( - static fn($path) => $path->toString(), - static fn() => null, - ) && - null !== $command->input()->match( - static fn($input) => $input->toString(), - static fn() => null, - ); - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::right(new SideEffect)); - $process - ->expects($this->once()) - ->method('output') - ->willReturn(new Output\Output(Sequence::of( - [Str::of(''), Output\Type::output], - [Str::of(''), Output\Type::output], - ))); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, ['--output'], @@ -286,10 +299,14 @@ public function testOutputSvg() new Options(Map::of(['output', ''])), ); - $console = $command($console); + $console = $command($console)->unwrap(); $this->assertSame( ['', ''], - $console->environment()->outputs(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); } } diff --git a/tests/Command/OfTest.php b/tests/Command/OfTest.php index 7c624df..371015e 100644 --- a/tests/Command/OfTest.php +++ b/tests/Command/OfTest.php @@ -18,20 +18,15 @@ Environment, Console, }; -use Innmind\Server\Control\Server\{ - Processes, - Process, - Process\ExitCode, - Process\Output, +use Innmind\Server\Control\{ + Server, + Server\Process\Builder, }; -use Innmind\HttpTransport\Curl; -use Innmind\TimeContinuum\Earth\Clock; +use Innmind\HttpTransport\Transport; +use Innmind\Time\Clock; use Innmind\Immutable\{ Map, - Str, - Either, - SideEffect, - Sequence, + Attempt, }; use PHPUnit\Framework\TestCase; @@ -41,7 +36,9 @@ class OfTest extends TestCase public function setUp(): void { - $this->http = Curl::of(new Clock)->maxConcurrency(20); + $this->http = Transport::curl(Clock::live())->map( + static fn($config) => $config->limitConcurrencyTo(20), + ); } public function testInterface() @@ -54,11 +51,11 @@ public function testInterface() ), new Save( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), ), ); @@ -67,7 +64,7 @@ public function testInterface() public function testUsage() { $expected = <<createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), - ))->usage(), + ))->usage()->toString(), ); } public function testInvokation() { + $server = Server::via( + function($command) { + $this->assertSame( + "dot '-Tsvg' '-o' 'innmind_cli_dependencies.svg'", + $command->toString(), + ); + $this->assertSame( + __DIR__.'/../../fixtures/', + $command->workingDirectory()->match( + static fn($path) => $path->toString(), + static fn() => null, + ), + ); + $this->assertNotNull($command->input()->match( + static fn($input) => $input->toString(), + static fn() => null, + )); + + return Attempt::result( + Builder::foreground(2)->build(), + ); + }, + ); $command = new Of( new Dependencies( new Package($this->http), ), new Save( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command): bool { - return $command->toString() === "dot '-Tsvg' '-o' 'innmind_cli_dependencies.svg'" && - __DIR__.'/../../fixtures/' === $command->workingDirectory()->match( - static fn($path) => $path->toString(), - static fn() => null, - ) && - null !== $command->input()->match( - static fn($input) => $input->toString(), - static fn() => null, - ); - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::right(new SideEffect)); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, ['innmind/cli'], @@ -136,10 +137,14 @@ public function testInvokation() new Options, ); - $console = $command($console); + $console = $command($console)->unwrap(); $this->assertSame( ["innmind_cli_dependencies.svg\n"], - $console->environment()->outputs(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); $this->assertNull($console->environment()->exitCode()->match( static fn($code) => $code, @@ -149,46 +154,46 @@ public function testInvokation() public function testExitWithProcessOutputWhenItFails() { + $server = Server::via( + function($command) { + $this->assertSame( + "dot '-Tsvg' '-o' 'innmind_cli_dependencies.svg'", + $command->toString(), + ); + $this->assertSame( + __DIR__.'/../../fixtures/', + $command->workingDirectory()->match( + static fn($path) => $path->toString(), + static fn() => null, + ), + ); + $this->assertNotNull($command->input()->match( + static fn($input) => $input->toString(), + static fn() => null, + )); + + return Attempt::result( + Builder::foreground(2) + ->failed(1, [['foo', 'output']]) + ->build(), + ); + }, + ); $command = new Of( new Dependencies( new Package($this->http), ), new Save( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command): bool { - return $command->toString() === "dot '-Tsvg' '-o' 'innmind_cli_dependencies.svg'" && - __DIR__.'/../../fixtures/' === $command->workingDirectory()->match( - static fn($path) => $path->toString(), - static fn() => null, - ) && - null !== $command->input()->match( - static fn($input) => $input->toString(), - static fn() => null, - ); - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::left(new ExitCode(1))); - $process - ->expects($this->once()) - ->method('output') - ->willReturn(new Output\Output(Sequence::of( - [Str::of('foo'), Output\Type::output], - ))); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, ['innmind/cli'], @@ -199,11 +204,14 @@ public function testExitWithProcessOutputWhenItFails() new Options, ); - $console = $command($console); - $this->assertSame([], $console->environment()->outputs()); + $console = $command($console)->unwrap(); $this->assertSame( ['foo'], - $console->environment()->errors(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); $this->assertSame(1, $console->environment()->exitCode()->match( static fn($code) => $code->toInt(), @@ -213,47 +221,49 @@ public function testExitWithProcessOutputWhenItFails() public function testOutputSvg() { + $server = Server::via( + function($command) { + $this->assertSame( + "dot '-Tsvg'", + $command->toString(), + ); + $this->assertSame( + __DIR__.'/../../fixtures/', + $command->workingDirectory()->match( + static fn($path) => $path->toString(), + static fn() => null, + ), + ); + $this->assertNotNull($command->input()->match( + static fn($input) => $input->toString(), + static fn() => null, + )); + + return Attempt::result( + Builder::foreground(2) + ->success([ + ['', 'output'], + ['', 'output'], + ]) + ->build(), + ); + }, + ); $command = new Of( new Dependencies( new Package($this->http), ), new Save( new Render, - $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command): bool { - return $command->toString() === "dot '-Tsvg'" && - __DIR__.'/../../fixtures/' === $command->workingDirectory()->match( - static fn($path) => $path->toString(), - static fn() => null, - ) && - null !== $command->input()->match( - static fn($input) => $input->toString(), - static fn() => null, - ); - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::right(new SideEffect)); - $process - ->expects($this->once()) - ->method('output') - ->willReturn(new Output\Output(Sequence::of( - [Str::of(''), Output\Type::output], - [Str::of(''), Output\Type::output], - ))); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, ['innmind/cli', '--output'], @@ -264,10 +274,14 @@ public function testOutputSvg() new Options(Map::of(['output', ''])), ); - $console = $command($console); + $console = $command($console)->unwrap(); $this->assertSame( ['', ''], - $console->environment()->outputs(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); $this->assertNull($console->environment()->exitCode()->match( static fn($code) => $code, diff --git a/tests/Command/VendorTest.php b/tests/Command/VendorTest.php index 83aba48..10bc03c 100644 --- a/tests/Command/VendorTest.php +++ b/tests/Command/VendorTest.php @@ -19,20 +19,15 @@ Environment, Console, }; -use Innmind\Server\Control\Server\{ - Processes, - Process, - Process\ExitCode, - Process\Output, +use Innmind\Server\Control\{ + Server, + Server\Process\Builder, }; -use Innmind\HttpTransport\Curl; -use Innmind\TimeContinuum\Earth\Clock; +use Innmind\HttpTransport\Transport; +use Innmind\Time\Clock; use Innmind\Immutable\{ Map, - Str, - Either, - SideEffect, - Sequence, + Attempt, }; use PHPUnit\Framework\TestCase; @@ -42,7 +37,9 @@ class VendorTest extends TestCase public function setUp(): void { - $http = Curl::of(new Clock)->maxConcurrency(20); + $http = Transport::curl(Clock::live())->map( + static fn($config) => $config->limitConcurrencyTo(20), + ); $this->loader = new VendorDependencies( new VendorLoader($http, new Package($http)), new Package($http), @@ -57,11 +54,11 @@ public function testInterface() $this->loader, new Save( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), ), ); @@ -70,7 +67,7 @@ public function testInterface() public function testUsage() { $expected = <<loader, new Save( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + Server::via(static fn() => null)->processes(), ), - ))->usage(), + ))->usage()->toString(), ); } public function testInvokation() { + $server = Server::via( + function($command) { + $this->assertSame( + "dot '-Tsvg' '-o' 'innmind.svg'", + $command->toString(), + ); + $this->assertSame( + __DIR__.'/../../fixtures/', + $command->workingDirectory()->match( + static fn($path) => $path->toString(), + static fn() => null, + ), + ); + $this->assertNotNull($command->input()->match( + static fn($input) => $input->toString(), + static fn() => null, + )); + + return Attempt::result( + Builder::foreground(2)->build(), + ); + }, + ); $command = new Vendor( $this->loader, new Save( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command): bool { - return $command->toString() === "dot '-Tsvg' '-o' 'innmind.svg'" && - __DIR__.'/../../fixtures/' === $command->workingDirectory()->match( - static fn($path) => $path->toString(), - static fn() => null, - ) && - null !== $command->input()->match( - static fn($input) => $input->toString(), - static fn() => null, - ); - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::right(new SideEffect)); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, ['innmind'], @@ -135,10 +136,14 @@ public function testInvokation() new Options, ); - $console = $command($console); + $console = $command($console)->unwrap(); $this->assertSame( ["innmind.svg\n"], - $console->environment()->outputs(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); $this->assertNull($console->environment()->exitCode()->match( static fn($code) => $code, @@ -148,44 +153,44 @@ public function testInvokation() public function testExitWithProcessOutputWhenItFails() { + $server = Server::via( + function($command) { + $this->assertSame( + "dot '-Tsvg' '-o' 'innmind.svg'", + $command->toString(), + ); + $this->assertSame( + __DIR__.'/../../fixtures/', + $command->workingDirectory()->match( + static fn($path) => $path->toString(), + static fn() => null, + ), + ); + $this->assertNotNull($command->input()->match( + static fn($input) => $input->toString(), + static fn() => null, + )); + + return Attempt::result( + Builder::foreground(2) + ->failed(1, [['foo', 'output']]) + ->build(), + ); + }, + ); $command = new Vendor( $this->loader, new Save( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command): bool { - return $command->toString() === "dot '-Tsvg' '-o' 'innmind.svg'" && - __DIR__.'/../../fixtures/' === $command->workingDirectory()->match( - static fn($path) => $path->toString(), - static fn() => null, - ) && - null !== $command->input()->match( - static fn($input) => $input->toString(), - static fn() => null, - ); - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::left(new ExitCode(1))); - $process - ->expects($this->once()) - ->method('output') - ->willReturn(new Output\Output(Sequence::of( - [Str::of('foo'), Output\Type::output], - ))); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, ['innmind'], @@ -196,11 +201,14 @@ public function testExitWithProcessOutputWhenItFails() new Options, ); - $console = $command($console); - $this->assertSame([], $console->environment()->outputs()); + $console = $command($console)->unwrap(); $this->assertSame( ['foo'], - $console->environment()->errors(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); $this->assertSame(1, $console->environment()->exitCode()->match( static fn($code) => $code->toInt(), @@ -210,45 +218,47 @@ public function testExitWithProcessOutputWhenItFails() public function testOutputSvg() { + $server = Server::via( + function($command) { + $this->assertSame( + "dot '-Tsvg'", + $command->toString(), + ); + $this->assertSame( + __DIR__.'/../../fixtures/', + $command->workingDirectory()->match( + static fn($path) => $path->toString(), + static fn() => null, + ), + ); + $this->assertNotNull($command->input()->match( + static fn($input) => $input->toString(), + static fn() => null, + )); + + return Attempt::result( + Builder::foreground(2) + ->success([ + ['', 'output'], + ['', 'output'], + ]) + ->build(), + ); + }, + ); $command = new Vendor( $this->loader, new Save( new Render, - $this->createMock(Processes::class), + $server->processes(), ), new Display( new Render, - $processes = $this->createMock(Processes::class), + $server->processes(), ), ); - $processes - ->expects($this->once()) - ->method('execute') - ->with($this->callback(static function($command): bool { - return $command->toString() === "dot '-Tsvg'" && - __DIR__.'/../../fixtures/' === $command->workingDirectory()->match( - static fn($path) => $path->toString(), - static fn() => null, - ) && - null !== $command->input()->match( - static fn($input) => $input->toString(), - static fn() => null, - ); - })) - ->willReturn($process = $this->createMock(Process::class)); - $process - ->expects($this->once()) - ->method('wait') - ->willReturn(Either::right(new SideEffect)); - $process - ->expects($this->once()) - ->method('output') - ->willReturn(new Output\Output(Sequence::of( - [Str::of(''), Output\Type::output], - [Str::of(''), Output\Type::output], - ))); $console = Console::of( - Environment\InMemory::of( + Environment::inMemory( [], true, ['innmind', '--output'], @@ -259,10 +269,14 @@ public function testOutputSvg() new Options(Map::of(['output', ''])), ); - $console = $command($console); + $console = $command($console)->unwrap(); $this->assertSame( ['', ''], - $console->environment()->outputs(), + $console + ->environment() + ->outputted() + ->map(static fn($chunk) => $chunk[0]->toString()) + ->toList(), ); $this->assertNull($console->environment()->exitCode()->match( static fn($code) => $code, diff --git a/tests/Loader/ComposerLockTest.php b/tests/Loader/ComposerLockTest.php index 64c264d..2c51a38 100644 --- a/tests/Loader/ComposerLockTest.php +++ b/tests/Loader/ComposerLockTest.php @@ -21,7 +21,7 @@ public function testInterface() $packages = $load(Path::of(__DIR__.'/../../fixtures/')); $this->assertInstanceOf(Set::class, $packages); - $this->assertCount(19, $packages); + $this->assertSame(19, $packages->size()); $expected = <<maxConcurrency(20)), + new Package( + Transport::curl(Clock::live())->map( + static fn($config) => $config->limitConcurrencyTo(20), + ), + ), ); $packages = $load(PackageModel\Name::of('innmind/url')); $this->assertInstanceOf(Set::class, $packages); - $this->assertCount(8, $packages); + $this->assertSame(2, $packages->size()); $expected = << psr__http_message [color="#8ac267", label="^1.0 || ^2.0"]; - league__uri_interfaces -> psr__http_message [color="#22ca7d", label="^1.1 || ^2.0"]; - league__uri_interfaces -> psr__http_factory [color="#22ca7d", label="^1"]; - league__uri -> league__uri_interfaces [color="#ef36b1", label="^7.5"]; - league__uri_components -> league__uri [color="#de64b9", label="^7.5"]; - innmind__url -> innmind__immutable [color="#085cd3", label="~4.15|~5.0"]; - innmind__url -> league__uri_parser [color="#085cd3", style="dotted", label="~1.2"]; - innmind__url -> league__uri_components [color="#ff0000", style="bold", label="~2.0"]; - innmind__immutable [shape="ellipse", width="0.75", height="0.5", color="#a7e599", URL="https://packagist.org/packages/innmind/immutable#5.20.0"]; - league__uri_parser [shape="ellipse", width="0.75", height="0.5", color="#bcf2f6", URL="https://packagist.org/packages/league/uri-parser#1.4.1"]; - psr__http_message [shape="ellipse", width="0.75", height="0.5", color="#8da3f1", URL="https://packagist.org/packages/psr/http-message#2.0"]; - psr__http_factory [shape="ellipse", width="0.75", height="0.5", color="#8ac267", URL="https://packagist.org/packages/psr/http-factory#1.1.0"]; - league__uri_interfaces [shape="ellipse", width="0.75", height="0.5", color="#22ca7d", URL="https://packagist.org/packages/league/uri-interfaces#7.5.0"]; - league__uri [shape="ellipse", width="0.75", height="0.5", color="#ef36b1", URL="https://packagist.org/packages/league/uri#7.5.1"]; - league__uri_components [shape="ellipse", width="0.75", height="0.5", color="#de64b9", URL="https://packagist.org/packages/league/uri-components#7.5.1"]; - innmind__url [shape="ellipse", width="0.75", height="0.5", color="#085cd3", URL="https://packagist.org/packages/innmind/url#4.4.0"]; + innmind__url -> innmind__immutable [color="#085cd3", label="~6.0"]; + innmind__immutable [shape="ellipse", width="0.75", height="0.5", color="#a7e599", URL="https://packagist.org/packages/innmind/immutable#6.0.0"]; + innmind__url [shape="ellipse", width="0.75", height="0.5", color="#085cd3", URL="https://packagist.org/packages/innmind/url#5.1.0"]; } DOT; @@ -73,7 +50,11 @@ public function testInvokation() public function testDuplicatedRelationsRegression() { $load = new Dependencies( - new Package(Curl::of(new Clock)->maxConcurrency(20)), + new Package( + Transport::curl(Clock::live())->map( + static fn($config) => $config->limitConcurrencyTo(20), + ), + ), ); $packages = $load(PackageModel\Name::of('innmind/http-transport')); @@ -89,22 +70,13 @@ public function testDuplicatedRelationsRegression() 'innmind/io', 'innmind/ip', 'innmind/media-type', - 'innmind/time-continuum', - 'innmind/time-warp', + 'innmind/mutable', + 'innmind/time', 'innmind/url', 'innmind/validation', - 'league/uri', - 'league/uri-components', - 'league/uri-interfaces', - 'league/uri-parser', - 'psr/http-factory', - 'psr/http-message', 'psr/log', 'ramsey/collection', 'ramsey/uuid', - 'symfony/filesystem', - 'symfony/polyfill-ctype', - 'symfony/polyfill-mbstring', ], $packages ->map(static fn($package) => $package->name()->toString()) @@ -116,12 +88,16 @@ public function testDuplicatedRelationsRegression() public function testCircularDependencyRegression() { $load = new Dependencies( - new Package(Curl::of(new Clock)->maxConcurrency(20)), + new Package( + Transport::curl(Clock::live())->map( + static fn($config) => $config->limitConcurrencyTo(20), + ), + ), ); $packages = $load(PackageModel\Name::of('laravel/browser-kit-testing')); $this->assertInstanceOf(Set::class, $packages); - $this->assertCount(105, $packages); + $this->assertSame(102, $packages->size()); } } diff --git a/tests/Loader/Dependents/GraphTest.php b/tests/Loader/Dependents/GraphTest.php index 50cfdc8..1fdfdb9 100644 --- a/tests/Loader/Dependents/GraphTest.php +++ b/tests/Loader/Dependents/GraphTest.php @@ -24,8 +24,8 @@ public function testKeepPathsLeadingToTheRootPackage() new Package( Name::of('vendor/root'), Version::of('1.0.0'), - Url::of('http://example.com'), - Url::of('http://example.com'), + Url::of('http://example.com/'), + Url::of('http://example.com/'), Set::of(new Relation( Name::of('rand/om'), new Constraint('~1.0'), @@ -35,8 +35,8 @@ public function testKeepPathsLeadingToTheRootPackage() new Package( Name::of('vendor/libA'), Version::of('1.0.0'), - Url::of('http://example.com'), - Url::of('http://example.com'), + Url::of('http://example.com/'), + Url::of('http://example.com/'), Set::of( new Relation( Name::of('vendor/root'), @@ -51,8 +51,8 @@ public function testKeepPathsLeadingToTheRootPackage() new Package( Name::of('vendor/libB'), Version::of('1.0.0'), - Url::of('http://example.com'), - Url::of('http://example.com'), + Url::of('http://example.com/'), + Url::of('http://example.com/'), Set::of( new Relation( Name::of('vendor/root'), @@ -67,8 +67,8 @@ public function testKeepPathsLeadingToTheRootPackage() new Package( Name::of('watev/foo'), Version::of('1.0.0'), - Url::of('http://example.com'), - Url::of('http://example.com'), + Url::of('http://example.com/'), + Url::of('http://example.com/'), Set::of( new Relation( Name::of('vendor/libA'), @@ -87,15 +87,15 @@ public function testKeepPathsLeadingToTheRootPackage() new Package( Name::of('vendor/libC'), Version::of('1.0.0'), - Url::of('http://example.com'), - Url::of('http://example.com'), + Url::of('http://example.com/'), + Url::of('http://example.com/'), Set::of(), ), ), ); $this->assertInstanceOf(Set::class, $packages); - $this->assertCount(4, $packages); + $this->assertSame(4, $packages->size()); $expected = << vendor__root [color="#f76ead", label="~1.0"]; watev__foo -> vendor__libA [color="#416be8", label="~1.0"]; watev__foo -> vendor__libB [color="#416be8", label="~1.0"]; - vendor__libA [shape="ellipse", width="0.75", height="0.5", color="#c34ca0", URL="http://example.com#1.0.0"]; - vendor__libB [shape="ellipse", width="0.75", height="0.5", color="#f76ead", URL="http://example.com#1.0.0"]; - watev__foo [shape="ellipse", width="0.75", height="0.5", color="#416be8", URL="http://example.com#1.0.0"]; - vendor__root [shape="ellipse", width="0.75", height="0.5", color="#39b791", URL="http://example.com#1.0.0"]; + vendor__libA [shape="ellipse", width="0.75", height="0.5", color="#c34ca0", URL="http://example.com/#1.0.0"]; + vendor__libB [shape="ellipse", width="0.75", height="0.5", color="#f76ead", URL="http://example.com/#1.0.0"]; + watev__foo [shape="ellipse", width="0.75", height="0.5", color="#416be8", URL="http://example.com/#1.0.0"]; + vendor__root [shape="ellipse", width="0.75", height="0.5", color="#39b791", URL="http://example.com/#1.0.0"]; } DOT; diff --git a/tests/Loader/DependentsTest.php b/tests/Loader/DependentsTest.php index ed52003..a7b3c9e 100644 --- a/tests/Loader/DependentsTest.php +++ b/tests/Loader/DependentsTest.php @@ -10,8 +10,8 @@ Package as PackageModel, Vendor as VendorModel, }; -use Innmind\HttpTransport\Curl; -use Innmind\TimeContinuum\Earth\Clock; +use Innmind\HttpTransport\Transport; +use Innmind\Time\Clock; use Innmind\Immutable\Set; use PHPUnit\Framework\TestCase; @@ -19,7 +19,9 @@ class DependentsTest extends TestCase { public function testInvokation() { - $http = Curl::of(new Clock)->maxConcurrency(20); + $http = Transport::curl(Clock::live())->map( + static fn($config) => $config->limitConcurrencyTo(20), + ); $load = new Dependents( new Vendor( @@ -34,19 +36,17 @@ public function testInvokation() ); $this->assertInstanceOf(Set::class, $packages); - $this->assertCount(64, $packages); + $this->assertSame(61, $packages->size()); $this->assertSame( [ 'innmind/acl', 'innmind/amqp', 'innmind/async', 'innmind/async-http-server', - 'innmind/black-box', 'innmind/black-box-symfony', 'innmind/cli', 'innmind/colour', 'innmind/crawler', - 'innmind/crawler-app', 'innmind/cron', 'innmind/debug', 'innmind/dependency-graph', @@ -74,11 +74,11 @@ public function testInvokation() 'innmind/json', 'innmind/kalmiya', 'innmind/lab-station', - 'innmind/library', 'innmind/log-reader', 'innmind/logger', 'innmind/math', 'innmind/media-type', + 'innmind/mutable', 'innmind/object-graph', 'innmind/operating-system', 'innmind/profiler', @@ -91,8 +91,7 @@ public function testInvokation() 'innmind/server-status', 'innmind/signals', 'innmind/stack-trace', - 'innmind/time-continuum', - 'innmind/time-warp', + 'innmind/time', 'innmind/ui', 'innmind/url', 'innmind/url-resolver', @@ -110,7 +109,9 @@ public function testInvokation() } public function testCircularDependencyRegression() { - $http = Curl::of(new Clock)->maxConcurrency(20); + $http = Transport::curl(Clock::live())->map( + static fn($config) => $config->limitConcurrencyTo(20), + ); $load = new Dependents( new Vendor( @@ -125,6 +126,6 @@ public function testCircularDependencyRegression() ); $this->assertInstanceOf(Set::class, $packages); - $this->assertCount(1, $packages); + $this->assertSame(1, $packages->size()); } } diff --git a/tests/Loader/PackageTest.php b/tests/Loader/PackageTest.php index 08e2637..e3ff01e 100644 --- a/tests/Loader/PackageTest.php +++ b/tests/Loader/PackageTest.php @@ -7,15 +7,15 @@ Loader\Package, Package as Model, }; -use Innmind\HttpTransport\Curl; -use Innmind\TimeContinuum\Earth\Clock; +use Innmind\HttpTransport\Transport; +use Innmind\Time\Clock; use PHPUnit\Framework\TestCase; class PackageTest extends TestCase { public function testInvokation() { - $load = new Package(Curl::of(new Clock)); + $load = new Package(Transport::curl(Clock::live())); $package = $load(Model\Name::of('innmind/url'))->match( static fn($package) => $package, @@ -24,17 +24,17 @@ public function testInvokation() $this->assertInstanceOf(Model::class, $package); $this->assertSame('innmind/url', $package->name()->toString()); - $this->assertSame('4.4.0', $package->version()->toString()); + $this->assertSame('5.1.0', $package->version()->toString()); $this->assertSame( 'https://packagist.org/packages/innmind/url', $package->packagist()->toString(), ); - $this->assertCount(3, $package->relations()); + $this->assertSame(1, $package->relations()->size()); } public function testMostRecentVersionIsLoaded() { - $load = new Package(Curl::of(new Clock)); + $load = new Package(Transport::curl(Clock::live())); $package = $load(Model\Name::of('guzzlehttp/guzzle'))->match( static fn($package) => $package, @@ -47,7 +47,7 @@ public function testMostRecentVersionIsLoaded() public function testReturnNothingWhenThePackageDoesNotExist() { - $load = new Package(Curl::of(new Clock)); + $load = new Package(Transport::curl(Clock::live())); $package = $load(Model\Name::of('psr/http-message-implementation'))->match( static fn($package) => $package, diff --git a/tests/Loader/VendorDependenciesTest.php b/tests/Loader/VendorDependenciesTest.php index 56650f5..2100240 100644 --- a/tests/Loader/VendorDependenciesTest.php +++ b/tests/Loader/VendorDependenciesTest.php @@ -9,8 +9,8 @@ Loader\Package, Vendor\Name, }; -use Innmind\HttpTransport\Curl; -use Innmind\TimeContinuum\Earth\Clock; +use Innmind\HttpTransport\Transport; +use Innmind\Time\Clock; use Innmind\Immutable\Set; use PHPUnit\Framework\TestCase; @@ -18,7 +18,9 @@ class VendorDependenciesTest extends TestCase { public function testInvokation() { - $http = Curl::of(new Clock)->maxConcurrency(20); + $http = Transport::curl(Clock::live())->map( + static fn($config) => $config->limitConcurrencyTo(20), + ); $package = new Package($http); $load = new VendorDependencies( new Vendor($http, $package), @@ -46,15 +48,12 @@ public function testInvokation() 'innmind/cli-framework', 'innmind/coding-standard', 'innmind/colour', - 'innmind/command-bus', 'innmind/crawler', - 'innmind/crawler-app', 'innmind/cron', 'innmind/debug', 'innmind/dependency-graph', 'innmind/di', 'innmind/encoding', - 'innmind/event-bus', 'innmind/file-watch', 'innmind/filesystem', 'innmind/foundation', @@ -64,51 +63,42 @@ public function testInvokation() 'innmind/git-release', 'innmind/graphviz', 'innmind/hash', - 'innmind/homeostasis', 'innmind/html', 'innmind/http', 'innmind/http-authentication', - 'innmind/http-framework', 'innmind/http-parser', 'innmind/http-server', 'innmind/http-session', 'innmind/http-transport', 'innmind/immutable', - 'innmind/installation-monitor', 'innmind/io', 'innmind/ip', 'innmind/ipc', 'innmind/json', 'innmind/kalmiya', 'innmind/lab-station', - 'innmind/library', 'innmind/log-reader', 'innmind/logger', - 'innmind/mantle', 'innmind/math', 'innmind/media-type', - 'innmind/neo4j-onm', + 'innmind/mutable', 'innmind/object-graph', 'innmind/operating-system', 'innmind/profiler', 'innmind/rabbitmq-management', 'innmind/reflection', - 'innmind/rest-client', - 'innmind/rest-server', 'innmind/robots-txt', 'innmind/router', 'innmind/s3', 'innmind/server-control', 'innmind/server-status', 'innmind/signals', - 'innmind/silent-cartographer', 'innmind/socket', 'innmind/specification', - 'innmind/stack', 'innmind/stack-trace', 'innmind/static-analysis', + 'innmind/time', 'innmind/time-continuum', - 'innmind/time-warp', 'innmind/type', 'innmind/ui', 'innmind/url', @@ -118,9 +108,6 @@ public function testInvokation() 'innmind/virtual-machine', 'innmind/warden', 'innmind/xml', - 'jeremykendall/php-domain-parser', - 'league/uri-components', - 'league/uri-parser', 'monolog/monolog', 'music-companion/apple-music', 'phpunit/php-code-coverage', @@ -129,9 +116,6 @@ public function testInvokation() 'psr/log', 'ramsey/uuid', 'symfony/browser-kit', - 'symfony/dom-crawler', - 'symfony/dotenv', - 'symfony/filesystem', 'symfony/framework-bundle', 'symfony/http-foundation', 'symfony/http-kernel', diff --git a/tests/Loader/VendorTest.php b/tests/Loader/VendorTest.php index 1e3cf92..19cb490 100644 --- a/tests/Loader/VendorTest.php +++ b/tests/Loader/VendorTest.php @@ -8,15 +8,17 @@ Loader\Package, Vendor as Model, }; -use Innmind\HttpTransport\Curl; -use Innmind\TimeContinuum\Earth\Clock; +use Innmind\HttpTransport\Transport; +use Innmind\Time\Clock; use PHPUnit\Framework\TestCase; class VendorTest extends TestCase { public function testInvokation() { - $http = Curl::of(new Clock)->maxConcurrency(20); + $http = Transport::curl(Clock::live())->map( + static fn($config) => $config->limitConcurrencyTo(20), + ); $load = new Vendor($http, new Package($http)); $vendor = $load(Model\Name::of('innmind')); @@ -35,7 +37,6 @@ public function testInvokation() 'innmind/coding-standard', 'innmind/colour', 'innmind/crawler', - 'innmind/crawler-app', 'innmind/cron', 'innmind/debug', 'innmind/dependency-graph', @@ -63,11 +64,11 @@ public function testInvokation() 'innmind/json', 'innmind/kalmiya', 'innmind/lab-station', - 'innmind/library', 'innmind/log-reader', 'innmind/logger', 'innmind/math', 'innmind/media-type', + 'innmind/mutable', 'innmind/object-graph', 'innmind/operating-system', 'innmind/profiler', @@ -82,8 +83,7 @@ public function testInvokation() 'innmind/specification', 'innmind/stack-trace', 'innmind/static-analysis', - 'innmind/time-continuum', - 'innmind/time-warp', + 'innmind/time', 'innmind/type', 'innmind/ui', 'innmind/url', @@ -104,12 +104,14 @@ public function testInvokation() public function testMaxOpenedFilesRegression() { - $http = Curl::of(new Clock)->maxConcurrency(20); + $http = Transport::curl(Clock::live())->map( + static fn($config) => $config->limitConcurrencyTo(20), + ); $load = new Vendor($http, new Package($http)); $vendor = $load(Model\Name::of('symfony')); $this->assertInstanceOf(Model::class, $vendor); - $this->assertCount(264, $vendor->packages()); + $this->assertSame(350, $vendor->packages()->size()); } } diff --git a/tests/PackageTest.php b/tests/PackageTest.php index c5b9d14..002a184 100644 --- a/tests/PackageTest.php +++ b/tests/PackageTest.php @@ -71,8 +71,8 @@ public function testKeep() $this->assertInstanceOf(Package::class, $package2); $this->assertNotSame($package, $package2); - $this->assertCount(3, $package->relations()); - $this->assertCount(2, $package2->relations()); + $this->assertSame(3, $package->relations()->size()); + $this->assertSame(2, $package2->relations()->size()); $this->assertSame([$bar, $foo], $package2->relations()->toList()); } @@ -94,7 +94,7 @@ public function testRemoveRelations() $this->assertInstanceOf(Package::class, $package2); $this->assertNotSame($package, $package2); - $this->assertCount(3, $package->relations()); - $this->assertCount(0, $package2->relations()); + $this->assertSame(3, $package->relations()->size()); + $this->assertSame(0, $package2->relations()->size()); } } diff --git a/tests/VendorTest.php b/tests/VendorTest.php index 4ca570f..823d295 100644 --- a/tests/VendorTest.php +++ b/tests/VendorTest.php @@ -93,7 +93,7 @@ public function testGroup() ); $this->assertInstanceOf(Set::class, $vendors); - $this->assertCount(2, $vendors); + $this->assertSame(2, $vendors->size()); $vendors = $vendors->toList(); $this->assertSame([$foo], \current($vendors)->packages()->toList()); \next($vendors);