Skip to content

Commit

Permalink
Fix an issue where the caching command would crash if an issue did no…
Browse files Browse the repository at this point in the history
…t exist
  • Loading branch information
rubenvanassche committed Oct 23, 2024
1 parent 0ff1fab commit 1486dd4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Support/Caching/DataClassFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DataClassFinder
public static function fromConfig(array $config): self
{
return new self(
directories: $config['directories'],
directories: array_filter($config['directories'], 'is_dir'),
useReflection: $config['reflection_discovery']['enabled'],
reflectionBasePath: $config['reflection_discovery']['base_path'],
reflectionRootNamespace: $config['reflection_discovery']['root_namespace'],
Expand Down
24 changes: 24 additions & 0 deletions tests/Commands/DataStructuresCacheCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,27 @@ function () {
expect(invade($config)->transformers)->toHaveCount(count(config('data.transformers')));
expect(invade($config)->casts)->toHaveCount(count(config('data.casts')));
});

it('will ignore non existing directories', function () {
// Ensure we cache
App::forgetInstance(DataConfig::class);

app()->singleton(
DataConfig::class,
function () {
return app()->make(DataStructureCache::class)->getConfig() ?? DataConfig::createFromConfig(config('data'));
}
);

config()->set('data.structure_caching.directories', [
__DIR__.'/../Fakes',
__DIR__.'/../NonExisting',
]);

config()->set('data.structure_caching.reflection_discovery.base_path', __DIR__.'/../Fakes');
config()->set('data.structure_caching.reflection_discovery.root_namespace', 'Spatie\LaravelData\Tests\Fakes');

$this->artisan('data:cache-structures')->assertExitCode(0);

expect(cache()->has('laravel-data.data-class.'. SimpleData::class))->toBeTrue();
});

0 comments on commit 1486dd4

Please sign in to comment.