Skip to content

Commit

Permalink
Merge pull request #28 from Dropelikeit/feature/change_cache_path
Browse files Browse the repository at this point in the history
Change the cache path to write the serialization data to the Laravels…
  • Loading branch information
Dropelikeit committed Apr 12, 2023
2 parents 18d613d + b71d182 commit 29f739a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ Homestead.json

# Composer
composer.lock

/tmp
11 changes: 8 additions & 3 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Dropelikeit\LaravelJmsSerializer\Http\Responses\ResponseFactory;
use Dropelikeit\LaravelJmsSerializer\Serializer\Factory;
use Illuminate\Config\Repository;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use function sprintf;

Expand All @@ -30,7 +31,11 @@ public function register(): void
/** @var Repository $configRepository */
$configRepository = $this->app->get('config');

$path = $this->app->storagePath();
$cacheDir = $this->app->storagePath('framework/cache/data');
if (!Storage::exists($cacheDir)) {
Storage::makeDirectory($cacheDir);
}

$shouldSerializeNull = (bool) $configRepository
->get('laravel-jms-serializer.serialize_null', true);
$serializeType = $configRepository
Expand All @@ -46,7 +51,7 @@ public function register(): void

$config = Config::fromConfig([
'serialize_null' => $shouldSerializeNull,
'cache_dir' => $path,
'cache_dir' => $cacheDir,
'serialize_type' => $serializeType,
'debug' => $debug,
'add_default_handlers' => $addDefaultHandlers,
Expand Down Expand Up @@ -81,7 +86,7 @@ public function boot(): void
*
* @return string
*/
protected function getConfigPath(): string
private function getConfigPath(): string
{
return config_path('laravel-jms-serializer.php');
}
Expand Down
5 changes: 5 additions & 0 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Config\Repository;
use Illuminate\Container\Container;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Facades\Storage;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -81,8 +82,12 @@ public function canRegister(): void
$this->application
->expects(self::once())
->method('storagePath')
->with('framework/cache/data')
->willReturn('my-storage');

Storage::shouldReceive('exists')->once()->with('my-storage')->andReturn(false);
Storage::shouldReceive('makeDirectory')->with('my-storage')->andReturn(true);

$config = Config::fromConfig([
'serialize_null' => true,
'cache_dir' => 'tmp',
Expand Down

0 comments on commit 29f739a

Please sign in to comment.