From 6beb8f976f53d58d040dc295e1eededc4cba9890 Mon Sep 17 00:00:00 2001 From: Baptiste Langlade Date: Wed, 30 Jul 2025 17:09:11 +0200 Subject: [PATCH] replace phpunit by blackbox --- .github/workflows/ci.yml | 4 +- .gitignore | 1 - blackbox.php | 28 +++++ composer.json | 2 +- phpunit.xml.dist | 18 --- tests/Manager/NativeTest.php | 216 ----------------------------------- tests/Session/IdTest.php | 2 +- tests/Session/NameTest.php | 2 +- tests/SessionTest.php | 2 +- 9 files changed, 35 insertions(+), 240 deletions(-) create mode 100644 blackbox.php delete mode 100644 phpunit.xml.dist delete mode 100644 tests/Manager/NativeTest.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1286ef..0a4e6fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,9 @@ jobs: with: dependency-versions: ${{ matrix.dependencies }} - name: PHPUnit - run: vendor/bin/phpunit --coverage-clover=coverage.clover + run: php blackbox.php + env: + ENABLE_COVERAGE: 'true' - uses: codecov/codecov-action@v1 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index e96516b..987e2a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ composer.lock vendor -.phpunit.result.cache diff --git a/blackbox.php b/blackbox.php new file mode 100644 index 0000000..5c3ddce --- /dev/null +++ b/blackbox.php @@ -0,0 +1,28 @@ +disableMemoryLimit() + ->when( + \getenv('ENABLE_COVERAGE') !== false, + static fn(Application $app) => $app + ->codeCoverage( + CodeCoverage::of( + __DIR__.'/src/', + __DIR__.'/tests/', + ) + ->dumpTo('coverage.clover') + ->enableWhen(true), + ) + ->scenariiPerProof(1), + ) + ->tryToProve(Load::directory(__DIR__.'/tests/')) + ->exit(); diff --git a/composer.json b/composer.json index 74993ef..c9f3dbf 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ } }, "require-dev": { - "phpunit/phpunit": "~9.0", + "innmind/black-box": "^6.4.1", "vimeo/psalm": "~5.12", "innmind/coding-standard": "~2.0" } diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 01dbbc9..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,18 +0,0 @@ - - - - - . - - - ./tests - ./vendor - ./src/ViaSession.php - - - - - ./tests - - - diff --git a/tests/Manager/NativeTest.php b/tests/Manager/NativeTest.php deleted file mode 100644 index 395fae8..0000000 --- a/tests/Manager/NativeTest.php +++ /dev/null @@ -1,216 +0,0 @@ -assertInstanceOf(Manager::class, Native::of()); - } - - public function testStart() - { - $manager = Native::of(); - $request = ServerRequest::of( - Url::of('/'), - Method::get, - ProtocolVersion::v11, - ); - - $session = $manager->start($request)->match( - static fn($session) => $session, - static fn() => null, - ); - - $this->assertInstanceOf(Session::class, $session); - } - - public function testConfigureSessionIdFromCookieOnStart() - { - $manager = Native::of(); - $request = ServerRequest::of( - Url::of('/'), - Method::get, - ProtocolVersion::v11, - Headers::of( - new Cookie( - new CookieValue( - new Parameter('foo', 'bar'), - new Parameter('PHPSESSID', 'some unique id'), - new Parameter('bar', 'baz'), - ), - ), - ), - ); - - $session = $manager->start($request)->match( - static fn($session) => $session, - static fn() => null, - ); - - $this->assertInstanceOf(Session::class, $session); - } - - public function testReturnNothingWhenTryingToStartMultipleSessions() - { - $manager = Native::of(); - $request = ServerRequest::of( - Url::of('/'), - Method::get, - ProtocolVersion::v11, - ); - - $this->assertInstanceOf(Session::class, $manager->start($request)->match( - static fn($session) => $session, - static fn() => null, - )); - $this->assertNull($manager->start($request)->match( - static fn($session) => $session, - static fn() => null, - )); - } - - public function testReturnNothingWhenTryingToSaveUnknownSession() - { - $this->assertNull( - Native::of() - ->save(Session::of( - Session\Id::maybe('unknown')->match( - static fn($id) => $id, - static fn() => null, - ), - Session\Name::maybe('foo')->match( - static fn($name) => $name, - static fn() => null, - ), - Map::of(), - )) - ->match( - static fn($sideEffect) => $sideEffect, - static fn() => null, - ), - ); - } - - public function testReturnNothingWhenTryingToCloseUnknownSession() - { - $this->assertNull( - Native::of() - ->close(Session::of( - Session\Id::maybe('unknown')->match( - static fn($id) => $id, - static fn() => null, - ), - Session\Name::maybe('foo')->match( - static fn($name) => $name, - static fn() => null, - ), - Map::of(), - ))->match( - static fn($sideEffect) => $sideEffect, - static fn() => null, - ), - ); - } - - public function testSave() - { - $manager = Native::of(); - $request = ServerRequest::of( - Url::of('/'), - Method::get, - ProtocolVersion::v11, - ); - - $session = $manager->start($request)->match( - static fn($session) => $session->with('foo', 'bar'), - static fn() => null, - ); - - $this->assertFalse(isset($_SESSION['foo'])); - $this->assertInstanceOf( - SideEffect::class, - $manager->save($session)->match( - static fn($sideEffect) => $sideEffect, - static fn() => null, - ), - ); - $this->assertFalse(isset($_SESSION['foo'])); - $this->assertSame(\PHP_SESSION_NONE, \session_status()); - - $session2 = $manager->start($request)->match( - static fn($session) => $session, - static fn() => null, - ); - - $this->assertNotSame($session, $session2); - $this->assertTrue($session2->contains('foo')); - $this->assertSame('bar', $session2->get('foo')); - } - - public function testClose() - { - $manager = Native::of(); - $request = ServerRequest::of( - Url::of('/'), - Method::get, - ProtocolVersion::v11, - ); - - $session = $manager->start($request)->match( - static fn($session) => $session->with('foo', 'bar'), - static fn() => null, - ); - $manager->save($session); - - $session2 = $manager->start($request)->match( - static fn($session) => $session, - static fn() => null, - ); - $this->assertTrue($session2->contains('foo')); - $this->assertInstanceOf( - SideEffect::class, - $manager->close($session2)->match( - static fn($sideEffect) => $sideEffect, - static fn() => null, - ), - ); - - $session3 = $manager->start($request)->match( - static fn($session) => $session, - static fn() => null, - ); - - $this->assertNotSame($session, $session3); - $this->assertNotSame($session2, $session3); - $this->assertFalse($session3->contains('foo')); - $this->assertFalse(isset($_SESSION['foo'])); - } -} diff --git a/tests/Session/IdTest.php b/tests/Session/IdTest.php index fdf7649..4d3f3d5 100644 --- a/tests/Session/IdTest.php +++ b/tests/Session/IdTest.php @@ -4,7 +4,7 @@ namespace Tests\Innmind\HttpSession\Session; use Innmind\HttpSession\Session\Id; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class IdTest extends TestCase { diff --git a/tests/Session/NameTest.php b/tests/Session/NameTest.php index ce4cb1c..672cf09 100644 --- a/tests/Session/NameTest.php +++ b/tests/Session/NameTest.php @@ -4,7 +4,7 @@ namespace Tests\Innmind\HttpSession\Session; use Innmind\HttpSession\Session\Name; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class NameTest extends TestCase { diff --git a/tests/SessionTest.php b/tests/SessionTest.php index be16ba5..4764ee9 100644 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -9,7 +9,7 @@ Session\Name, }; use Innmind\Immutable\Map; -use PHPUnit\Framework\TestCase; +use Innmind\BlackBox\PHPUnit\Framework\TestCase; class SessionTest extends TestCase {