diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index e031ee7..3badd79 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -68,7 +68,7 @@ 'whitespace_after_comma_in_array' => true, ]) ->setFinder(PhpCsFixer\Finder::create() - ->exclude(['vendor', 'tests/Http/Responses/metadata']) + ->exclude(['vendor', 'tests/Unit/Http/Responses/metadata']) ->in(__DIR__) ) ; diff --git a/composer.json b/composer.json index b9c0bca..7c9e3fc 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "require-dev": { "roave/security-advisories": "dev-latest", "friendsofphp/php-cs-fixer": "^3.52", - "phpunit/phpunit": "^10.0", + "phpunit/phpunit": "^10.5", "larastan/larastan": "^2.9", "orchestra/testbench": "^8.9|^9.0", "phpstan/phpstan-phpunit": "^1.3", @@ -47,7 +47,8 @@ "vimeo/psalm": "^5.23", "psalm/plugin-laravel": "^2.10", "psalm/plugin-phpunit": "^0.19", - "infection/infection": "^0.27.10" + "infection/infection": "^0.27.10", + "laravel/framework": "^10.48" }, "scripts": { "lint": "parallel-lint --exclude .git --exclude vendor .", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a8dd75f..cffad2a 100755 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -6,9 +6,14 @@ - - tests - + + + ./tests/Unit + + + tests/Feature + + src diff --git a/tests/Feature/ServiceProviderTest.php b/tests/Feature/ServiceProviderTest.php new file mode 100644 index 0000000..129b7de --- /dev/null +++ b/tests/Feature/ServiceProviderTest.php @@ -0,0 +1,72 @@ +getMockBuilder(Repository::class) + ->disableOriginalConstructor() + ->getMock(); + + $configRepository + ->expects(self::once()) + ->method('set') + ->with('laravel-jms-serializer', [ + 'serialize_null' => true, + 'serialize_type' => 'json', // Contracts\Config::SERIALIZE_TYPE_XML + 'debug' => false, + 'add_default_handlers' => true, + 'custom_handlers' => [], + ]); + + $configRepository + ->expects(self::exactly(6)) + ->method('get') + ->willReturnOnConsecutiveCalls([], true, 'json', false, true, []); + + Storage::shouldReceive('exists')->once()->with(__DIR__ . '/data/storage/framework/cache/data')->andReturn(true); + + $this->application = new Application(); + $this->application->useStoragePath(__DIR__ . '/data/storage'); + + $this->application->bind('config', fn () => $configRepository); + + $this->application->register(ServiceProvider::class); + } + + /** + * @test + */ + public function canBuildResponseFactoryByIdFromConfiguredServiceProvider(): void + { + $responseFactory = $this->application->get('ResponseFactory'); + + $this->assertInstanceOf(ResponseBuilder::class, $responseFactory); + } + + /** + * @test + */ + public function canBuildResponseFactoryByClassConfiguredServiceProvider(): void + { + $responseFactory = $this->application->get(ResponseFactory::class); + + $this->assertInstanceOf(ResponseBuilder::class, $responseFactory); + } +} diff --git a/tests/Feature/data/.gitkeep b/tests/Feature/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/Config/ConfigTest.php b/tests/Unit/Config/ConfigTest.php similarity index 99% rename from tests/Config/ConfigTest.php rename to tests/Unit/Config/ConfigTest.php index bd8b8c3..c5f5424 100644 --- a/tests/Config/ConfigTest.php +++ b/tests/Unit/Config/ConfigTest.php @@ -1,7 +1,7 @@ getSerializer($this->config), $this->config); - $response = $responseFactory->create(Response::create([new \Dropelikeit\LaravelJmsSerializer\Tests\data\ResponseFactory\Response\Item()])); + $response = $responseFactory->create(Response::create([new Response\Item()])); self::assertEquals(200, $response->getStatusCode()); self::assertEquals('[{"key":"magic_number","value":12}]', $response->getContent()); diff --git a/tests/Serializer/FactoryTest.php b/tests/Unit/Serializer/FactoryTest.php similarity index 98% rename from tests/Serializer/FactoryTest.php rename to tests/Unit/Serializer/FactoryTest.php index b8d2b04..3e4f0ce 100644 --- a/tests/Serializer/FactoryTest.php +++ b/tests/Unit/Serializer/FactoryTest.php @@ -1,13 +1,13 @@