-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Unit test to "Unit" dir and add a Feature test. (#37)
* Move Unit test to "Unit" dir and add a Feature test. * Add Laravel framework to composer and update ServiceProviderTest This commit adds the Laravel framework to the composer.json dependencies and modifies the ServiceProviderTest. Specifically, it binds a mock of the Repository class to the 'config' service within the application object. This will aid in creating a more controlled and dependable testing environment. * Update access modifier for setUp in ServiceProviderTest Changed the access modifier for setUp method from "protected" to "public" in ServiceProviderTest. This change ensures correct accessibility as per defined rules. * Remove static from closure in ServiceProviderTest Removed the 'static' keyword from the closure used in the 'bind' method within the ServiceProviderTest file. This allows the closure, which is used in testing, to have access to the context it's created in. * Add orchestra/testbench dependency to composer.json The "orchestra/testbench" package has been added as a requirement in composer.json to enhance testing capabilities. This package provides a solid base to conduct Laravel package unit tests, further improving code quality and stability. * Update ServiceProviderTest with mocked configRepository Implemented mock of the Repository class in the ServiceProviderTest file. This will allow testing of the configRepository's set and get methods, enhancing the reliability and efficiency of our software testing phase. * Add storage functionality to ServiceProviderTest This update introduces a mock for the 'exists' and 'makeDirectory' methods from the Storage facade within the ServiceProviderTest. This change allows us to simulate the creation of a cache data directory in the test environment and enhance the overall test coverage. * Update paths for storage calls in ServiceProviderTest This commit updates the storage paths used for 'exists' and 'makeDirectory' methods in ServiceProviderTest to be absolute rather than relative. Also, it sets the 'useStoragePath' for the application to the updated path, ensuring consistency between tests and application storage paths. * Update ServiceProviderTest to assume cache directory exists The test method in ServiceProviderTest for cache directory existence was modified. Previously, the test assumed that the cache directory doesn't exist and hence it made a directory. Now, the test has been updated to assume that the cache directory already exists. * Update storage path in ServiceProviderTest The storage path defined in ServiceProviderTest.php has been updated. This change is reflected in the 'useStoragePath' method which now points to the 'data/storage' directory instead of just 'data'. * Refactor spaces in string paths in ServiceProviderTest In the ServiceProviderTest, the paths used in the 'shouldReceive' and 'useStoragePath' methods are slightly refactored. Spaces have been added after the concatenation dot in the directories for increased clarity and consistency according to coding standards. * Update path in .php-cs-fixer.dist.php file The commit revises the excluded directory in the .php-cs-fixer.dist.php configuration file. It now properly ignores the 'tests/Unit/Http/Responses/metadata' directory instead of 'tests/Http/Responses/metadata'. * Update psalm annotations for function parameters The commit modifies psalm annotations in the Response class for the $items parameters in the functions present. It changes the type from 'Item' to 'list<Item>', thus giving a clearer representation of the expected input.
- Loading branch information
1 parent
7be1765
commit 2c682c5
Showing
17 changed files
with
103 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Dropelikeit\LaravelJmsSerializer\Tests\Feature; | ||
|
||
use Dropelikeit\LaravelJmsSerializer\Contracts\ResponseBuilder; | ||
use Dropelikeit\LaravelJmsSerializer\Http\Responses\ResponseFactory; | ||
use Dropelikeit\LaravelJmsSerializer\ServiceProvider; | ||
use Illuminate\Config\Repository; | ||
use Illuminate\Foundation\Application; | ||
use Illuminate\Support\Facades\Storage; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ServiceProviderTest extends TestCase | ||
{ | ||
private readonly Application $application; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$configRepository = $this | ||
->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); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/Facades/ResponseFactoryFacadeTest.php → ...nit/Facades/ResponseFactoryFacadeTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
tests/Serializer/FactoryTest.php → tests/Unit/Serializer/FactoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/Serializer/data/CustomHandler.php → tests/Unit/Serializer/data/CustomHandler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/ServiceProviderTest.php → tests/Unit/ServiceProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
tests/data/ResponseFactory/Dummy.php → tests/Unit/data/ResponseFactory/Dummy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/data/ResponseFactory/JsonDummy.php → ...s/Unit/data/ResponseFactory/JsonDummy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
tests/data/ResponseFactory/Response.php → tests/Unit/data/ResponseFactory/Response.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/data/ResponseFactory/Response/Item.php → ...it/data/ResponseFactory/Response/Item.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/data/ResponseFactory/XmlDummy.php → tests/Unit/data/ResponseFactory/XmlDummy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.