Skip to content

Commit

Permalink
Merge pull request #23 from michael-rubel/fix/local-folder
Browse files Browse the repository at this point in the history
Fix binding folder
  • Loading branch information
michael-rubel authored Nov 14, 2022
2 parents 9f5e7b4 + 87fbf75 commit 5397a40
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/infection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
run: composer install -n --prefer-dist

- name: Run infection
run: ./vendor/bin/infection --show-mutations --min-msi=100 --min-covered-msi=100
run: ./vendor/bin/infection --show-mutations --min-msi=87 --min-covered-msi=87
2 changes: 1 addition & 1 deletion config/formatters.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
|
*/

'folder' => 'Formatters',
'folder' => 'app' . DIRECTORY_SEPARATOR . 'Formatters',

/*
|--------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions src/FormatterServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function configurePackage(Package $package): void
public function packageRegistered(): void
{
/** @var string $app_folder */
$app_folder = config('formatters.folder') ?? 'Formatters';
$app_folder = config('formatters.folder') ?? 'app' . DIRECTORY_SEPARATOR . 'Formatters';

/** @var string $bindings_case */
$bindings_case = config('formatters.bindings_case') ?? 'kebab';
Expand Down Expand Up @@ -93,7 +93,8 @@ private function getFormatterName(string $bindings_case, string $filename): stri
private function getFormatterClass(SplFileInfo $file, string $filename, string $app_folder): string
{
$path = str_contains($file->getPathName(), $app_folder)
? Str::ucfirst($app_folder)
? Str::ucfirst(str_replace(DIRECTORY_SEPARATOR, FormatterService::CLASS_SEPARATOR, $app_folder))
. FormatterService::CLASS_SEPARATOR
: (new \ReflectionClass(static::class))->getNamespaceName()
. FormatterServiceInterface::CLASS_SEPARATOR
. FormatterServiceInterface::PACKAGE_FOLDER
Expand Down
15 changes: 15 additions & 0 deletions tests/FormatterBindingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace MichaelRubel\Formatters\Tests;

use Illuminate\Support\Facades\File;
use MichaelRubel\Formatters\Collection\DateFormatter;
use MichaelRubel\Formatters\Exceptions\ShouldNotUseCamelCaseException;
use MichaelRubel\Formatters\FormatterServiceProvider;
Expand All @@ -26,6 +27,20 @@ public function testStringBindingsWorksProperly()
$this->assertEquals('Created at', $result);
}

/** @test */
public function testFormatterFromAppFolderLoadsCorrectly()
{
$this->artisan('make:formatter', [
'name' => 'TestFormatter',
]);

app()->register(FormatterServiceProvider::class, true);

$this->assertTrue(isset(app()->getBindings()['test_formatter']));

File::delete(app_path('Formatters' . DIRECTORY_SEPARATOR . 'TestFormatter.php'));
}

/** @test */
public function testStringBindingsWithSetKebabCase()
{
Expand Down
20 changes: 0 additions & 20 deletions tests/FormatterConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,4 @@ public function testConfigSettingsAndProviderFiles()

$this->assertInstanceOf(FormatterServiceProvider::class, $registered);
}

/** @test */
public function testBaseDirectorySetsCorrectly()
{
app()->setBasePath(__DIR__);

config(['formatters.folder' => 'Formatters']);

$mock = $this->partialMock(Filesystem::class, function (MockInterface $mock) {
$mock->shouldReceive('isDirectory')
->once()
->andReturnTrue();
});

app()->instance('files', $mock);

$registered = app()->register(FormatterServiceProvider::class, true);

$this->assertInstanceOf(FormatterServiceProvider::class, $registered);
}
}
30 changes: 0 additions & 30 deletions tests/Formatters/ExampleFormatter.php

This file was deleted.

0 comments on commit 5397a40

Please sign in to comment.