diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml new file mode 100644 index 0000000..b584701 --- /dev/null +++ b/.github/workflows/quality.yml @@ -0,0 +1,36 @@ +name: Quality + +on: + pull_request: + +jobs: + tests: + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + php: [ 8.2, 8.3 ] + + name: Testing on PHP ${{ matrix.php }} + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite + coverage: none + tools: composer:v2 + + - name: Install Composer dependencies + run: composer install --prefer-dist --no-interaction --no-progress + + - name: Checks Code styles via PHPCsFixer + run: composer test:lint + + - name: Execute tests + run: vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index a46201a..084a52f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ Thumbs.db /.idea /.vscode .phpunit.result.cache +.phpunit.cache +build diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 0285f17..0000000 --- a/.styleci.yml +++ /dev/null @@ -1 +0,0 @@ -preset: laravel diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8c1272b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -dist: xenial -language: php - -env: - global: - - SETUP=stable - -matrix: - fast_finish: true - include: - - php: 7.3 - - php: 7.3 - env: SETUP=lowest - - php: 7.4 - - php: 7.4 - env: SETUP=lowest - - php: 8.0 - - php: 8.0 - env: SETUP=lowest - -cache: - directories: - - $HOME/.composer/cache - -install: - - if [[ $SETUP = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --no-suggest; fi - - if [[ $SETUP = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable --no-suggest; fi - -script: vendor/bin/phpunit --verbose diff --git a/README.md b/README.md index e755a91..f64bd38 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Laravel Dev Booter is open-sourced software licensed under the [MIT license](htt 8.x | 3.0.x 9.x | 3.0.x 10.x | 4.0.x + 11.x | 5.0.x ### Installation Install Laravel Dev Booter as you would with any other dependency managed by Composer: diff --git a/composer.json b/composer.json index 66c2e81..c044f1c 100644 --- a/composer.json +++ b/composer.json @@ -14,12 +14,13 @@ } ], "require": { - "php": "^8.1|^8.2", + "php": "^8.2", "illuminate/support": "^11.0" }, "require-dev": { "orchestra/testbench": "^9.0", - "phpunit/phpunit": "^10.0" + "phpunit/phpunit": "^10.0", + "laravel/pint": "^1.16" }, "autoload": { "psr-4": { @@ -31,9 +32,13 @@ "PercyMamedy\\LaravelDevBooter\\Tests\\": "tests/" } }, + "scripts": { + "lint": "vendor/bin/pint -v", + "test:lint": "vendor/bin/pint --test" + }, "extra": { "branch-alias": { - "dev-master": "develop" + "dev-main": "develop" }, "laravel": { "providers": [ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3394d98..df9be87 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,11 +1,31 @@ - + - - ./tests + + tests - - - + + + + + + ./src + + diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..02b0834 --- /dev/null +++ b/pint.json @@ -0,0 +1,3 @@ +{ + "preset": "laravel" +} diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php deleted file mode 100644 index c01d62c..0000000 --- a/tests/AbstractTestCase.php +++ /dev/null @@ -1,60 +0,0 @@ -resolveApplication(); - - $this->resolveApplicationExceptionHandler($app); - $this->resolveApplicationCore($app, $env); - $this->resolveApplicationConfiguration($app); - $this->resolveApplicationHttpKernel($app); - $this->resolveApplicationConsoleKernel($app); - - if ($app->version() >= 5.3 && $app->version() < 5.4) { - $app->make('Illuminate\Foundation\Bootstrap\ConfigureLogging')->bootstrap($app); - } - - $app->make('Illuminate\Foundation\Bootstrap\HandleExceptions')->bootstrap($app); - $app->make('Illuminate\Foundation\Bootstrap\RegisterFacades')->bootstrap($app); - $app->make('Illuminate\Foundation\Bootstrap\SetRequestForConsole')->bootstrap($app); - $app->make('Illuminate\Foundation\Bootstrap\RegisterProviders')->bootstrap($app); - - $this->getEnvironmentSetUp($app); - - $app->make('Illuminate\Foundation\Bootstrap\BootProviders')->bootstrap($app); - - $app['router']->getRoutes()->refreshNameLookups(); - - return $app; - } - - /** - * Resolve application core implementation. - * - * @param \Illuminate\Foundation\Application $app - * @param string $env - * @return void - */ - protected function resolveApplicationCore($app, $env = 'testing') - { - Facade::clearResolvedInstances(); - Facade::setFacadeApplication($app); - - $app->detectEnvironment(function () use ($env) { - return $env; - }); - } -} diff --git a/tests/Fixtures/Providers/ADevProvider.php b/tests/Fixtures/Providers/ADevProvider.php index c3e49b9..8281001 100644 --- a/tests/Fixtures/Providers/ADevProvider.php +++ b/tests/Fixtures/Providers/ADevProvider.php @@ -12,9 +12,7 @@ class ADevProvider extends ServiceProvider /** * Boot Application Services. */ - public function boot(): void - { - } + public function boot(): void {} /** * Register Application Services. diff --git a/tests/Fixtures/Providers/AnotherDevProvider.php b/tests/Fixtures/Providers/AnotherDevProvider.php index 289ede7..8212ddd 100644 --- a/tests/Fixtures/Providers/AnotherDevProvider.php +++ b/tests/Fixtures/Providers/AnotherDevProvider.php @@ -12,9 +12,7 @@ class AnotherDevProvider extends ServiceProvider /** * Boot Application Services. */ - public function boot(): void - { - } + public function boot(): void {} /** * Register Application Services. diff --git a/tests/RegistrationMultipleTest.php b/tests/RegistrationMultipleTest.php index bbac5b3..f087bba 100644 --- a/tests/RegistrationMultipleTest.php +++ b/tests/RegistrationMultipleTest.php @@ -6,56 +6,53 @@ namespace PercyMamedy\LaravelDevBooter\Tests; +use Illuminate\Config\Repository; +use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Foundation\AliasLoader; -use PercyMamedy\LaravelDevBooter\ServiceProvider as DevBooterProvider; -class RegistrationMultipleTest extends AbstractTestCase +class RegistrationMultipleTest extends TestCase { /** - * Get package providers. + * {@inheritDoc} * - * @param \Illuminate\Foundation\Application $app - * @return array + * @throws BindingResolutionException */ - public function getPackageProviders($app): array + protected function getPackageProviders($app): array { - config(['dev-booter.dev_providers_config_keys.dev' => ['app.dev_providers', 'app.local_providers']]); - config(['dev-booter.dev_aliases_config_keys.dev' => ['app.dev_aliases', 'app.local_aliases']]); - config(['app.dev_providers' => [\PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\ADevProvider::class]]); - config(['app.local_providers' => [\PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\AnotherDevProvider::class]]); - config(['app.dev_aliases' => ['Bar' => \PercyMamedy\LaravelDevBooter\Tests\Fixtures\Facades\ADevFacade::class]]); - config(['app.local_aliases' => ['Foo' => \PercyMamedy\LaravelDevBooter\Tests\Fixtures\Facades\AnotherDevFacade::class]]); - - return [ - DevBooterProvider::class, - ]; + /** @var Repository $config */ + $config = $app->make('config'); + + $config->set(['dev-booter.dev_providers_config_keys.testing' => ['app.dev_providers', 'app.local_providers']]); + $config->set(['dev-booter.dev_aliases_config_keys.testing' => ['app.dev_aliases', 'app.local_aliases']]); + $config->set(['app.dev_providers' => [\PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\ADevProvider::class]]); + $config->set(['app.local_providers' => [\PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\AnotherDevProvider::class]]); + $config->set(['app.dev_aliases' => ['Bar' => \PercyMamedy\LaravelDevBooter\Tests\Fixtures\Facades\ADevFacade::class]]); + $config->set(['app.local_aliases' => ['Foo' => \PercyMamedy\LaravelDevBooter\Tests\Fixtures\Facades\AnotherDevFacade::class]]); + + return parent::getPackageProviders($app); } /** - * Test that when we specify multiple providers by assingning array - * for config location all of the providers are loaded. + * Test that when we specify multiple providers by assigning array + * for config location all the providers are loaded. */ - public function testMultipleProvidersByEnvironmentAreLoadedCorrectly(): void + public function test_multiple_providers_by_environment_are_loaded_correctly(): void { - $app = $this->createApplication('dev'); + $this->assertArrayHasKey('PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\ADevProvider', app()->getLoadedProviders()); + $this->assertEquals('dummy.value', $this->app->make('dummy.key')); + $this->assertInstanceOf(\PercyMamedy\LaravelDevBooter\Tests\Fixtures\Foo\Bar::class, $this->app->make('bar')); - $this->assertArrayHasKey('PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\ADevProvider', $app->getLoadedProviders()); - $this->assertEquals('dummy.value', $app->make('dummy.key')); - $this->assertInstanceOf(\PercyMamedy\LaravelDevBooter\Tests\Fixtures\Foo\Bar::class, $app->make('bar')); - - $this->assertArrayHasKey('PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\AnotherDevProvider', $app->getLoadedProviders()); - $this->assertEquals('another-dummy.value', $app->make('another-dummy.key')); - $this->assertInstanceOf(\PercyMamedy\LaravelDevBooter\Tests\Fixtures\Foo\Foo::class, $app->make('foo')); + $this->assertArrayHasKey('PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\AnotherDevProvider', $this->app->getLoadedProviders()); + $this->assertEquals('another-dummy.value', $this->app->make('another-dummy.key')); + $this->assertInstanceOf(\PercyMamedy\LaravelDevBooter\Tests\Fixtures\Foo\Foo::class, $this->app->make('foo')); } /** * Test that when we specify multiple aliases config location * per environment all aliases are booted correctly. */ - public function testMultipleAliasesAreLoadedCorrectly(): void + public function test_multiple_aliases_are_loaded_correctly(): void { - $this->createApplication('dev'); - $this->assertArrayHasKey('Bar', AliasLoader::getInstance()->getAliases()); $this->assertArrayHasKey('Foo', AliasLoader::getInstance()->getAliases()); } diff --git a/tests/RegistrationTest.php b/tests/RegistrationTest.php index 145c2d7..b904038 100644 --- a/tests/RegistrationTest.php +++ b/tests/RegistrationTest.php @@ -6,57 +6,45 @@ namespace PercyMamedy\LaravelDevBooter\Tests; +use Illuminate\Config\Repository; +use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Foundation\AliasLoader; -use PercyMamedy\LaravelDevBooter\ServiceProvider as DevBooterProvider; -class RegistrationTest extends AbstractTestCase +class RegistrationTest extends TestCase { /** - * Get package providers. + * {@inheritDoc} * - * @param \Illuminate\Foundation\Application $app - * @return array + * @throws BindingResolutionException */ public function getPackageProviders($app): array { - config(['app.dev_providers' => [\PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\ADevProvider::class]]); - config(['app.dev_aliases' => ['Bar' => \PercyMamedy\LaravelDevBooter\Tests\Fixtures\Facades\ADevFacade::class]]); + /** @var Repository $config */ + $config = $app->make('config'); - return [ - DevBooterProvider::class, - ]; + $config->set(['app.testing_providers' => [\PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\ADevProvider::class]]); + $config->set(['app.testing_aliases' => ['Bar' => \PercyMamedy\LaravelDevBooter\Tests\Fixtures\Facades\ADevFacade::class]]); + + return parent::getPackageProviders($app); } /** * Test that dev providers are registered when on dev env. + * + * @throws BindingResolutionException */ - public function testThatDevProvidersAreRegisteredCorrectly(): void + public function test_that_dev_providers_are_registered_correctly(): void { - $app = $this->createApplication('dev'); - - $this->assertArrayHasKey('PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\ADevProvider', $app->getLoadedProviders()); - $this->assertEquals('dummy.value', $app->make('dummy.key')); - $this->assertInstanceOf(\PercyMamedy\LaravelDevBooter\Tests\Fixtures\Foo\Bar::class, $app->make('bar')); + $this->assertArrayHasKey('PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\ADevProvider', $this->app->getLoadedProviders()); + $this->assertEquals('dummy.value', $this->app->make('dummy.key')); + $this->assertInstanceOf(\PercyMamedy\LaravelDevBooter\Tests\Fixtures\Foo\Bar::class, $this->app->make('bar')); } /** * Test that dev class aliases are properly booter. */ - public function testThatClassAliasesAreBootedCorrectly(): void + public function test_that_class_aliases_are_booted_correctly(): void { - $this->createApplication('dev'); - $this->assertArrayHasKey('Bar', AliasLoader::getInstance()->getAliases()); } - - /** - * Test that when we are on production dev providers are - * not registered. - */ - public function testThatDevProvidersAreNotRegisteredOnProd(): void - { - $app = $this->createApplication('production'); - - $this->assertArrayNotHasKey('PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\ADevProvider', $app->getLoadedProviders()); - } } diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index 06061f9..23d58fa 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -6,40 +6,24 @@ namespace PercyMamedy\LaravelDevBooter\Tests; -use Orchestra\Testbench\TestCase; -use PercyMamedy\LaravelDevBooter\ServiceProvider as DevBooterProvider; - class ServiceProviderTest extends TestCase { - /** - * Get package providers. - * - * @param \Illuminate\Foundation\Application $app - * @return array - */ - public function getPackageProviders($app): array - { - return [ - DevBooterProvider::class, - ]; - } - /** * Test that our config works properly * and that we can get desired values * from them. */ - public function testConfigCanGetValues(): void + public function test_config_can_get_values(): void { $this->assertEquals([ - 'dev' => 'app.dev_providers', - 'local' => 'app.local_providers', + 'dev' => 'app.dev_providers', + 'local' => 'app.local_providers', 'testing' => 'app.testing_providers', ], config('dev-booter.dev_providers_config_keys')); $this->assertEquals([ - 'dev' => 'app.dev_aliases', - 'local' => 'app.local_aliases', + 'dev' => 'app.dev_aliases', + 'local' => 'app.local_aliases', 'testing' => 'app.testing_aliases', ], config('dev-booter.dev_aliases_config_keys')); } @@ -47,7 +31,7 @@ public function testConfigCanGetValues(): void /** * Test that our config files are being published correctly. */ - public function testPublishingOfConfigFile(): void + public function test_publishing_of_config_file(): void { $this->artisan('vendor:publish', ['--tag' => 'config']); diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..6efc13a --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,21 @@ +assertArrayNotHasKey('PercyMamedy\LaravelDevBooter\Tests\Fixtures\Providers\ADevProvider', $this->app->getLoadedProviders()); + } +}