diff --git a/.gitignore b/.gitignore index 22f3c3f..e9da540 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ composer.lock /vendor # Tooling -/.phpunit.result.cache +/.phpunit.cache diff --git a/composer.json b/composer.json index ab9c42d..8812af0 100644 --- a/composer.json +++ b/composer.json @@ -17,14 +17,14 @@ } ], "require": { - "php" : "^8.1", + "php": "^8.1", "ext-json": "*", "laravel/framework": "^10.0" }, "require-dev": { "laravel/pint": "^1.15", "orchestra/testbench": "^8.0", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^10.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f869f5d..3b92943 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +1,25 @@ - + stopOnFailure="false" + cacheDirectory=".phpunit.cache"> ./tests - - + + ./src - - + + diff --git a/stubs/JsonSerializableStub.php b/stubs/JsonSerializableStub.php index 04a6ffe..4b0acb7 100644 --- a/stubs/JsonSerializableStub.php +++ b/stubs/JsonSerializableStub.php @@ -16,7 +16,7 @@ class JsonSerializableStub implements \JsonSerializable * * @since 5.4.0 */ - public function jsonSerialize() + public function jsonSerialize(): array { return ['foo' => 'bar']; } diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index d365ceb..853ddd7 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -2,17 +2,16 @@ namespace Swis\Laravel\JavaScriptData; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Swis\Laravel\JavaScriptData\Stub\ArrayableStub; use Swis\Laravel\JavaScriptData\Stub\JsonableStub; use Swis\Laravel\JavaScriptData\Stub\JsonSerializableStub; -class BuilderTest extends TestCase +final class BuilderTest extends TestCase { - /** - * @test - */ - public function itBuilds() + #[Test] + public function itBuilds(): void { $builder = new Builder(); $javascript = $builder->build('namespace', ['foo' => 'bar']); @@ -23,10 +22,8 @@ public function itBuilds() ); } - /** - * @test - */ - public function itBuildsANestedNamespace() + #[Test] + public function itBuildsANestedNamespace(): void { $builder = new Builder(); $javascript = $builder->build('name.space.string', ['foo' => 'bar']); @@ -37,10 +34,8 @@ public function itBuildsANestedNamespace() ); } - /** - * @test - */ - public function itBuildsWithExtraJsonEncodeOptions() + #[Test] + public function itBuildsWithExtraJsonEncodeOptions(): void { $builder = new Builder(); $javascript = $builder->build('namespace', ['test' => 'tést/tëst', 'foo' => []], JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE); @@ -51,10 +46,8 @@ public function itBuildsWithExtraJsonEncodeOptions() ); } - /** - * @test - */ - public function itBuildsPrettyPrinted() + #[Test] + public function itBuildsPrettyPrinted(): void { $builder = new Builder(); $javascript = $builder->build('name.space', ['foo' => 'bar'], JSON_PRETTY_PRINT); @@ -70,10 +63,8 @@ public function itBuildsPrettyPrinted() ); } - /** - * @test - */ - public function itBuildsWithArrayableData() + #[Test] + public function itBuildsWithArrayableData(): void { $builder = new Builder(); $javascript = $builder->build('namespace', new ArrayableStub()); @@ -84,10 +75,8 @@ public function itBuildsWithArrayableData() ); } - /** - * @test - */ - public function itBuildsWithJsonableData() + #[Test] + public function itBuildsWithJsonableData(): void { $builder = new Builder(); $javascript = $builder->build('namespace', new JsonableStub()); @@ -98,10 +87,8 @@ public function itBuildsWithJsonableData() ); } - /** - * @test - */ - public function itBuildsWithJsonSerializableData() + #[Test] + public function itBuildsWithJsonSerializableData(): void { $builder = new Builder(); $javascript = $builder->build('namespace', new JsonSerializableStub()); @@ -112,10 +99,8 @@ public function itBuildsWithJsonSerializableData() ); } - /** - * @test - */ - public function itThrowsWhenJsonEncodeFailed() + #[Test] + public function itThrowsWhenJsonEncodeFailed(): void { $this->expectExceptionObject(new \InvalidArgumentException('Malformed UTF-8 characters, possibly incorrectly encoded', 5)); diff --git a/tests/ResponseFactoryTest.php b/tests/ResponseFactoryTest.php index d375096..e353ad8 100644 --- a/tests/ResponseFactoryTest.php +++ b/tests/ResponseFactoryTest.php @@ -4,19 +4,18 @@ use Illuminate\Routing\ResponseFactory as IlluminateResponseFactory; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\Test; -class ResponseFactoryTest extends TestCase +final class ResponseFactoryTest extends TestCase { - /** - * @test - */ - public function itMakesAResponse() + #[Test] + public function itMakesAResponse(): void { /** @var \Illuminate\Routing\ResponseFactory $responseFactory */ $responseFactory = $this->app->make(IlluminateResponseFactory::class); /** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */ $builder = $this->getMockBuilder(Builder::class) - ->setMethods(['build']) + ->onlyMethods(['build']) ->getMock(); $builder ->expects($this->once()) @@ -30,10 +29,8 @@ public function itMakesAResponse() $this->assertSame('foo bar', $response->getContent()); } - /** - * @test - */ - public function itMakesAResponseWithDefaultNamespace() + #[Test] + public function itMakesAResponseWithDefaultNamespace(): void { $this->app['config']->set('javascript-data-response.namespace', 'foo.bar'); @@ -41,7 +38,7 @@ public function itMakesAResponseWithDefaultNamespace() $responseFactory = $this->app->make(IlluminateResponseFactory::class); /** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */ $builder = $this->getMockBuilder(Builder::class) - ->setMethods(['build']) + ->onlyMethods(['build']) ->getMock(); $builder ->expects($this->once()) @@ -52,10 +49,8 @@ public function itMakesAResponseWithDefaultNamespace() $factory->make('namespace'); } - /** - * @test - */ - public function itMakesAResponseWithPrettyPrintOption() + #[Test] + public function itMakesAResponseWithPrettyPrintOption(): void { $this->app['config']->set('javascript-data-response.pretty-print', true); @@ -63,7 +58,7 @@ public function itMakesAResponseWithPrettyPrintOption() $responseFactory = $this->app->make(IlluminateResponseFactory::class); /** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */ $builder = $this->getMockBuilder(Builder::class) - ->setMethods(['build']) + ->onlyMethods(['build']) ->getMock(); $builder ->expects($this->once()) @@ -74,16 +69,14 @@ public function itMakesAResponseWithPrettyPrintOption() $factory->make('namespace'); } - /** - * @test - */ - public function itMakesAResponseWithDefaultStatus() + #[Test] + public function itMakesAResponseWithDefaultStatus(): void { /** @var \Illuminate\Routing\ResponseFactory $responseFactory */ $responseFactory = $this->app->make(IlluminateResponseFactory::class); /** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */ $builder = $this->getMockBuilder(Builder::class) - ->setMethods(['build']) + ->onlyMethods(['build']) ->getMock(); $factory = new ResponseFactory($responseFactory, $builder); @@ -92,16 +85,14 @@ public function itMakesAResponseWithDefaultStatus() $this->assertSame(200, $response->getStatusCode()); } - /** - * @test - */ - public function itMakesAResponseWithCustomStatus() + #[Test] + public function itMakesAResponseWithCustomStatus(): void { /** @var \Illuminate\Routing\ResponseFactory $responseFactory */ $responseFactory = $this->app->make(IlluminateResponseFactory::class); /** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */ $builder = $this->getMockBuilder(Builder::class) - ->setMethods(['build']) + ->onlyMethods(['build']) ->getMock(); $factory = new ResponseFactory($responseFactory, $builder); @@ -110,16 +101,14 @@ public function itMakesAResponseWithCustomStatus() $this->assertSame(500, $response->getStatusCode()); } - /** - * @test - */ - public function itMakesAResponseWithDefaultHeaders() + #[Test] + public function itMakesAResponseWithDefaultHeaders(): void { /** @var \Illuminate\Routing\ResponseFactory $responseFactory */ $responseFactory = $this->app->make(IlluminateResponseFactory::class); /** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */ $builder = $this->getMockBuilder(Builder::class) - ->setMethods(['build']) + ->onlyMethods(['build']) ->getMock(); $factory = new ResponseFactory($responseFactory, $builder); @@ -146,10 +135,8 @@ public function itMakesAResponseWithDefaultHeaders() $this->assertSame('application/javascript; charset=utf-8', $response->headers->get('content-type')); } - /** - * @test - */ - public function itMakesAResponseWithCustomHeaders() + #[Test] + public function itMakesAResponseWithCustomHeaders(): void { $this->app['config']->set( 'javascript-data-response.headers', @@ -160,7 +147,7 @@ public function itMakesAResponseWithCustomHeaders() $responseFactory = $this->app->make(IlluminateResponseFactory::class); /** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */ $builder = $this->getMockBuilder(Builder::class) - ->setMethods(['build']) + ->onlyMethods(['build']) ->getMock(); $factory = new ResponseFactory($responseFactory, $builder); @@ -170,10 +157,8 @@ public function itMakesAResponseWithCustomHeaders() $this->assertSame('Bar', $response->headers->get('x-foo')); } - /** - * @test - */ - public function itMakesAResponseWithDefaultOptions() + #[Test] + public function itMakesAResponseWithDefaultOptions(): void { $this->app['config']->set('javascript-data-response.json_encode-options', JSON_UNESCAPED_UNICODE); @@ -181,7 +166,7 @@ public function itMakesAResponseWithDefaultOptions() $responseFactory = $this->app->make(IlluminateResponseFactory::class); /** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */ $builder = $this->getMockBuilder(Builder::class) - ->setMethods(['build']) + ->onlyMethods(['build']) ->getMock(); $builder ->expects($this->once()) @@ -192,16 +177,14 @@ public function itMakesAResponseWithDefaultOptions() $factory->make('namespace'); } - /** - * @test - */ - public function itMakesAResponseWithCustomOptions() + #[Test] + public function itMakesAResponseWithCustomOptions(): void { /** @var \Illuminate\Routing\ResponseFactory $responseFactory */ $responseFactory = $this->app->make(IlluminateResponseFactory::class); /** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */ $builder = $this->getMockBuilder(Builder::class) - ->setMethods(['build']) + ->onlyMethods(['build']) ->getMock(); $builder ->expects($this->once()) diff --git a/tests/ResponseMacroTest.php b/tests/ResponseMacroTest.php index 49c59a9..c554c58 100644 --- a/tests/ResponseMacroTest.php +++ b/tests/ResponseMacroTest.php @@ -4,8 +4,9 @@ use Illuminate\Support\Facades\Response; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\Test; -class ResponseMacroTest extends TestCase +final class ResponseMacroTest extends TestCase { protected function getPackageProviders($app) { @@ -17,10 +18,8 @@ protected function getEnvironmentSetUp($app) $app['config']->set('javascript-data-response.pretty-print', false); } - /** - * @test - */ - public function itMakesAResponse() + #[Test] + public function itMakesAResponse(): void { /** @var \Illuminate\Http\Response $response */ $response = Response::javascriptData('namespace', ['foo' => 'bar']); diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index ce10555..4c8f939 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -4,18 +4,17 @@ use Illuminate\Routing\ResponseFactory; use Orchestra\Testbench\TestCase; +use PHPUnit\Framework\Attributes\Test; -class ServiceProviderTest extends TestCase +final class ServiceProviderTest extends TestCase { protected function getPackageProviders($app) { return [ServiceProvider::class]; } - /** - * @test - */ - public function itMergesTheConfig() + #[Test] + public function itMergesTheConfig(): void { $this->assertSame( [ @@ -30,10 +29,8 @@ public function itMergesTheConfig() ); } - /** - * @test - */ - public function itRegistersAResponseMacro() + #[Test] + public function itRegistersAResponseMacro(): void { $this->assertTrue(ResponseFactory::hasMacro('javascriptData')); }