Skip to content

Commit 29f739a

Browse files
authored
Merge pull request #28 from Dropelikeit/feature/change_cache_path
Change the cache path to write the serialization data to the Laravels…
2 parents 18d613d + b71d182 commit 29f739a

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ Homestead.json
2424

2525
# Composer
2626
composer.lock
27+
28+
/tmp

src/ServiceProvider.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Dropelikeit\LaravelJmsSerializer\Http\Responses\ResponseFactory;
1010
use Dropelikeit\LaravelJmsSerializer\Serializer\Factory;
1111
use Illuminate\Config\Repository;
12+
use Illuminate\Support\Facades\Storage;
1213
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
1314
use function sprintf;
1415

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

33-
$path = $this->app->storagePath();
34+
$cacheDir = $this->app->storagePath('framework/cache/data');
35+
if (!Storage::exists($cacheDir)) {
36+
Storage::makeDirectory($cacheDir);
37+
}
38+
3439
$shouldSerializeNull = (bool) $configRepository
3540
->get('laravel-jms-serializer.serialize_null', true);
3641
$serializeType = $configRepository
@@ -46,7 +51,7 @@ public function register(): void
4651

4752
$config = Config::fromConfig([
4853
'serialize_null' => $shouldSerializeNull,
49-
'cache_dir' => $path,
54+
'cache_dir' => $cacheDir,
5055
'serialize_type' => $serializeType,
5156
'debug' => $debug,
5257
'add_default_handlers' => $addDefaultHandlers,
@@ -81,7 +86,7 @@ public function boot(): void
8186
*
8287
* @return string
8388
*/
84-
protected function getConfigPath(): string
89+
private function getConfigPath(): string
8590
{
8691
return config_path('laravel-jms-serializer.php');
8792
}

tests/ServiceProviderTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Config\Repository;
1212
use Illuminate\Container\Container;
1313
use Illuminate\Contracts\Foundation\Application;
14+
use Illuminate\Support\Facades\Storage;
1415
use PHPUnit\Framework\MockObject\MockObject;
1516
use PHPUnit\Framework\TestCase;
1617

@@ -81,8 +82,12 @@ public function canRegister(): void
8182
$this->application
8283
->expects(self::once())
8384
->method('storagePath')
85+
->with('framework/cache/data')
8486
->willReturn('my-storage');
8587

88+
Storage::shouldReceive('exists')->once()->with('my-storage')->andReturn(false);
89+
Storage::shouldReceive('makeDirectory')->with('my-storage')->andReturn(true);
90+
8691
$config = Config::fromConfig([
8792
'serialize_null' => true,
8893
'cache_dir' => 'tmp',

0 commit comments

Comments
 (0)