From c530b3532efd4f441b3e7b8bbcf5846be792457f Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Sun, 15 Feb 2026 16:25:48 +0100 Subject: [PATCH] update dependencies --- .github/workflows/ci.yml | 2 - CHANGELOG.md | 7 ++ composer.json | 9 +-- src/Read.php | 2 +- tests/CrontabTest.php | 78 +++++++++++++--------- tests/ReadTest.php | 136 +++++++++++++++++++++++---------------- 6 files changed, 142 insertions(+), 92 deletions(-) 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/CHANGELOG.md b/CHANGELOG.md index b50c79b..4f7f3a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [Unreleased] + +### Changed + +- Requires PHP `8.4` +- Requires `innmind/foundation:~2.1` + ## 4.0.0 - 2025-08-07 ### Changed diff --git a/composer.json b/composer.json index 81b87fb..685bf31 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,8 @@ "issues": "http://github.com/Innmind/Cron/issues" }, "require": { - "php": "~8.2", - "innmind/foundation": "~1.5" + "php": "~8.4", + "innmind/foundation": "~2.1" }, "autoload": { "psr-4": { @@ -29,11 +29,8 @@ } }, "require-dev": { - "innmind/static-analysis": "^1.2.1", + "innmind/static-analysis": "~1.3", "innmind/black-box": "~6.5", "innmind/coding-standard": "~2.0" - }, - "suggest": { - "innmind/operating-system": "To easily access to a machine control mechanism" } } diff --git a/src/Read.php b/src/Read.php index 7120c12..de25d8d 100644 --- a/src/Read.php +++ b/src/Read.php @@ -40,7 +40,7 @@ public function __invoke(Server $server): Attempt static fn($success) => $success ->output() ->map(static fn($chunk) => $chunk->data()) - ->fold(new Concat) + ->fold(Concat::monoid) ->split("\n") ->filter(static fn($line) => !$line->startsWith('#') && !$line->trim()->empty()) ->map(static fn($line) => Job::attempt($line->toString())), diff --git a/tests/CrontabTest.php b/tests/CrontabTest.php index 31d3428..20a34fd 100644 --- a/tests/CrontabTest.php +++ b/tests/CrontabTest.php @@ -7,8 +7,14 @@ Crontab, Job, }; -use Innmind\Server\Control\Servers\Mock; -use Innmind\Immutable\SideEffect; +use Innmind\Server\Control\{ + Server, + Server\Process\Builder, +}; +use Innmind\Immutable\{ + Attempt, + SideEffect, +}; use Innmind\BlackBox\PHPUnit\Framework\TestCase; class CrontabTest extends TestCase @@ -16,13 +22,16 @@ class CrontabTest extends TestCase public function testInstallEmptyCrontabForConnectedUser() { $crontab = Crontab::forConnectedUser(); - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "crontab '-r'", $command->toString(), - ), - ); + ); + + return Attempt::result(Builder::foreground(2)->build()); + }, + ); $this->assertInstanceOf(SideEffect::class, $crontab($server)->unwrap()); } @@ -30,13 +39,16 @@ public function testInstallEmptyCrontabForConnectedUser() public function testInstallEmptyCrontabForSpecificUser() { $crontab = Crontab::forUser('admin'); - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "crontab '-u' 'admin' '-r'", $command->toString(), - ), - ); + ); + + return Attempt::result(Builder::foreground(2)->build()); + }, + ); $this->assertInstanceOf(SideEffect::class, $crontab($server)->unwrap()); } @@ -47,13 +59,16 @@ public function testInstallCrontabForConnectedUser() Job::of('1 2 3 4 5 echo foo'), Job::of('2 3 4 5 6 echo bar'), ); - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( - "echo '1 2 3 4 5 echo foo\n2 3 4 5 6 echo bar' | 'crontab'", + $server = Server::via( + function($command) { + $this->assertSame( + "echo '1 2 3 4 5 echo foo\n2 3 4 5 6 echo bar' | crontab", $command->toString(), - ), - ); + ); + + return Attempt::result(Builder::foreground(2)->build()); + }, + ); $this->assertInstanceOf(SideEffect::class, $crontab($server)->unwrap()); } @@ -65,13 +80,16 @@ public function testInstallCrontabForSpecificUser() Job::of('1 2 3 4 5 echo foo'), Job::of('2 3 4 5 6 echo bar'), ); - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( - "echo '1 2 3 4 5 echo foo\n2 3 4 5 6 echo bar' | 'crontab' '-u' 'admin'", + $server = Server::via( + function($command) { + $this->assertSame( + "echo '1 2 3 4 5 echo foo\n2 3 4 5 6 echo bar' | crontab '-u' 'admin'", $command->toString(), - ), - ); + ); + + return Attempt::result(Builder::foreground(2)->build()); + }, + ); $this->assertInstanceOf(SideEffect::class, $crontab($server)->unwrap()); } @@ -83,11 +101,13 @@ public function testReturnErrorWhenInstallFailed() Job::of('1 2 3 4 5 echo foo'), Job::of('2 3 4 5 6 echo bar'), ); - $server = Mock::new($this->assert()) - ->willExecute( - static fn() => null, - static fn($_, $builder) => $builder->failed(), - ); + $server = Server::via( + static fn() => Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ), + ); $error = $crontab($server)->match( static fn() => null, diff --git a/tests/ReadTest.php b/tests/ReadTest.php index b4ad799..836944e 100644 --- a/tests/ReadTest.php +++ b/tests/ReadTest.php @@ -4,8 +4,14 @@ namespace Tests\Innmind\Cron; use Innmind\Cron\Read; -use Innmind\Server\Control\Servers\Mock; -use Innmind\Immutable\Sequence; +use Innmind\Server\Control\{ + Server, + Server\Process\Builder, +}; +use Innmind\Immutable\{ + Sequence, + Attempt, +}; use Innmind\BlackBox\PHPUnit\Framework\TestCase; class ReadTest extends TestCase @@ -13,26 +19,32 @@ class ReadTest extends TestCase public function testReadCrontabForConnectedUser() { $read = Read::forConnectedUser(); - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "crontab '-l'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([ - [ - <<success([ + [ + <<build(), + ); + }, + ); $jobs = $read($server)->match( static fn($jobs) => $jobs, @@ -40,7 +52,7 @@ public function testReadCrontabForConnectedUser() ); $this->assertInstanceOf(Sequence::class, $jobs); - $this->assertCount(2, $jobs); + $this->assertSame(2, $jobs->size()); $this->assertSame('1 2 3 4 5 echo foo', $jobs->first()->match( static fn($job) => $job->toString(), static fn() => null, @@ -54,26 +66,32 @@ public function testReadCrontabForConnectedUser() public function testReadCrontabForSpecificUser() { $read = Read::forUser('admin'); - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "crontab '-u' 'admin' '-l'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([ - [ - <<success([ + [ + <<build(), + ); + }, + ); $jobs = $read($server)->match( static fn($jobs) => $jobs, @@ -81,7 +99,7 @@ public function testReadCrontabForSpecificUser() ); $this->assertInstanceOf(Sequence::class, $jobs); - $this->assertCount(2, $jobs); + $this->assertSame(2, $jobs->size()); $this->assertSame('1 2 3 4 5 echo foo', $jobs->first()->match( static fn($job) => $job->toString(), static fn() => null, @@ -95,16 +113,20 @@ public function testReadCrontabForSpecificUser() public function testReturnNothingWhenCrontabContainsInvalidJobs() { $read = Read::forUser('admin'); - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "crontab '-u' 'admin' '-l'", $command->toString(), - ), - static fn($_, $builder) => $builder->success([ - ['*', 'output'], - ]), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->success([['*', 'output']]) + ->build(), + ); + }, + ); $this->assertNull($read($server)->match( static fn($jobs) => $jobs, @@ -115,14 +137,20 @@ public function testReturnNothingWhenCrontabContainsInvalidJobs() public function testReturnNothingWhenProcessToReadTheCrontabFailed() { $read = Read::forUser('admin'); - $server = Mock::new($this->assert()) - ->willExecute( - fn($command) => $this->assertSame( + $server = Server::via( + function($command) { + $this->assertSame( "crontab '-u' 'admin' '-l'", $command->toString(), - ), - static fn($_, $builder) => $builder->failed(), - ); + ); + + return Attempt::result( + Builder::foreground(2) + ->failed() + ->build(), + ); + }, + ); $this->assertNull($read($server)->match( static fn($jobs) => $jobs,