Skip to content

Commit

Permalink
Merge pull request #22 from percymamedy/feat/laravel-11
Browse files Browse the repository at this point in the history
Add tests with github actions
  • Loading branch information
percymamedy authored Jul 11, 2024
2 parents 1dfc31f + b763ae0 commit 92f4523
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 187 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ Thumbs.db
/.idea
/.vscode
.phpunit.result.cache
.phpunit.cache
build
1 change: 0 additions & 1 deletion .styleci.yml

This file was deleted.

29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": [
Expand Down
32 changes: 26 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="LaraveDevBooter Test Suite">
<directory suffix=".php">./tests</directory>
<testsuite name="Laravel dev booter Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
</php>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
3 changes: 3 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"preset": "laravel"
}
60 changes: 0 additions & 60 deletions tests/AbstractTestCase.php

This file was deleted.

4 changes: 1 addition & 3 deletions tests/Fixtures/Providers/ADevProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class ADevProvider extends ServiceProvider
/**
* Boot Application Services.
*/
public function boot(): void
{
}
public function boot(): void {}

/**
* Register Application Services.
Expand Down
4 changes: 1 addition & 3 deletions tests/Fixtures/Providers/AnotherDevProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class AnotherDevProvider extends ServiceProvider
/**
* Boot Application Services.
*/
public function boot(): void
{
}
public function boot(): void {}

/**
* Register Application Services.
Expand Down
57 changes: 27 additions & 30 deletions tests/RegistrationMultipleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, class-string>
* @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());
}
Expand Down
48 changes: 18 additions & 30 deletions tests/RegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, class-string>
* @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());
}
}
Loading

0 comments on commit 92f4523

Please sign in to comment.