From 8a420e0bf4b0a6ff0c02297e406e46c37a36aaf7 Mon Sep 17 00:00:00 2001 From: Ash Allen Date: Mon, 11 Mar 2024 22:59:20 +0000 Subject: [PATCH 1/7] Added support for Laravel 11. --- .github/workflows/ci-phpstan.yml | 8 +++++++- .github/workflows/ci-tests.yml | 8 +++++++- composer.json | 6 +++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-phpstan.yml b/.github/workflows/ci-phpstan.yml index 0413bfb..63985b5 100644 --- a/.github/workflows/ci-phpstan.yml +++ b/.github/workflows/ci-phpstan.yml @@ -10,8 +10,10 @@ jobs: fail-fast: false matrix: php: [8.0, 8.1, 8.2, 8.3] - laravel: [9.*, 10.*] + laravel: [9.*, 10.*, 11.*] include: + - laravel: 11.* + testbench: 9.* - laravel: 10.* testbench: 8.* - laravel: 9.* @@ -19,6 +21,10 @@ jobs: exclude: - laravel: 10.* php: 8.0 + - laravel: 11.* + php: 8.0 + - laravel: 11.* + php: 8.1 name: PHP${{ matrix.php }} - Laravel ${{ matrix.laravel }} diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 687f783..1638253 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -10,8 +10,10 @@ jobs: fail-fast: false matrix: php: [8.0, 8.1, 8.2, 8.3] - laravel: [8.*, 9.*, 10.*] + laravel: [8.*, 9.*, 10.*, 11.*] include: + - laravel: 11.* + testbench: 9.* - laravel: 10.* testbench: 8.* - laravel: 9.* @@ -21,6 +23,10 @@ jobs: exclude: - laravel: 10.* php: 8.0 + - laravel: 11.* + php: 8.0 + - laravel: 11.* + php: 8.1 name: PHP${{ matrix.php }} - Laravel ${{ matrix.laravel }} diff --git a/composer.json b/composer.json index b060329..112b807 100644 --- a/composer.json +++ b/composer.json @@ -20,14 +20,14 @@ "require": { "php": "^8.0", "nesbot/carbon": "~2.0", - "illuminate/container": "^8.0|^9.0|^10.0", - "illuminate/database": "^8.0|^9.0|^10.0", + "illuminate/container": "^8.0|^9.0|^10.0|^11.0", + "illuminate/database": "^8.0|^9.0|^10.0|^11.0", "jenssegers/agent": "^2.6", "hashids/hashids": "^4.0|^5.0" }, "require-dev": { "mockery/mockery": "^1.0", - "orchestra/testbench": "^6.0|^7.0|^8.0", + "orchestra/testbench": "^6.0|^7.0|^8.0|^9.0", "phpunit/phpunit": "^8.2 || ^9.0", "nunomaduro/larastan": "^0.7.12 || ^1.0.0 || ^2.0" }, From 72c7284bb29e2c1d0364406632202d8d4c0e02af Mon Sep 17 00:00:00 2001 From: Ash Allen Date: Mon, 11 Mar 2024 23:03:40 +0000 Subject: [PATCH 2/7] Added compatibility for PHPUnit 10. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 112b807..81a0a54 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "require-dev": { "mockery/mockery": "^1.0", "orchestra/testbench": "^6.0|^7.0|^8.0|^9.0", - "phpunit/phpunit": "^8.2 || ^9.0", + "phpunit/phpunit": "^8.2|^9.0|^10.0", "nunomaduro/larastan": "^0.7.12 || ^1.0.0 || ^2.0" }, "autoload": { From 18e47033ba19d433333225b431ef47ca544f8dde Mon Sep 17 00:00:00 2001 From: Ash Allen Date: Mon, 11 Mar 2024 23:09:21 +0000 Subject: [PATCH 3/7] Updated docblock to match newer format. --- src/Models/ShortURL.php | 2 +- src/Models/ShortURLVisit.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Models/ShortURL.php b/src/Models/ShortURL.php index dd783f2..be5756f 100644 --- a/src/Models/ShortURL.php +++ b/src/Models/ShortURL.php @@ -46,7 +46,7 @@ class ShortURL extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'destination_url', diff --git a/src/Models/ShortURLVisit.php b/src/Models/ShortURLVisit.php index 0cfe1bb..21b1883 100644 --- a/src/Models/ShortURLVisit.php +++ b/src/Models/ShortURLVisit.php @@ -46,7 +46,7 @@ class ShortURLVisit extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'short_url_id', From fc736f2c82308acf996e2e15482807142e488c2c Mon Sep 17 00:00:00 2001 From: Ash Allen Date: Mon, 11 Mar 2024 23:17:18 +0000 Subject: [PATCH 4/7] Updated provider to be static. --- tests/Unit/Controllers/ShortURLControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Controllers/ShortURLControllerTest.php b/tests/Unit/Controllers/ShortURLControllerTest.php index 05cb8be..e721862 100644 --- a/tests/Unit/Controllers/ShortURLControllerTest.php +++ b/tests/Unit/Controllers/ShortURLControllerTest.php @@ -184,7 +184,7 @@ public function visitor_is_redirected_to_the_destination_with_source_query_param $this->get($requestUrl)->assertStatus(301)->assertRedirect($expectedDestinationUrl); } - public function forwardQueryParamsProvider(): array + public static function forwardQueryParamsProvider(): array { return [ [ From 0b097ac71bb32e1e504e2b7d82e4e02dfe91b004 Mon Sep 17 00:00:00 2001 From: Ash Allen Date: Mon, 11 Mar 2024 23:49:12 +0000 Subject: [PATCH 5/7] Define "LazilyRefreshDatabase" in the parent test case. --- tests/Unit/Classes/BuilderTest.php | 3 --- tests/Unit/Classes/ResolverTest.php | 3 --- tests/Unit/Controllers/ShortURLControllerTest.php | 3 --- tests/Unit/Controllers/ShortURLDisableRouteTest.php | 3 --- tests/Unit/Models/ShortURL/CastsTest.php | 3 --- tests/Unit/Models/ShortURL/ShortURLFactoryTest.php | 3 --- tests/Unit/Models/ShortURL/ShortURLTest.php | 3 --- tests/Unit/Models/ShortURL/TrackingEnabledTest.php | 3 --- tests/Unit/Models/ShortURL/TrackingFieldsTest.php | 3 --- tests/Unit/Models/ShortURLVisit/CastsTest.php | 3 --- tests/Unit/Models/ShortURLVisit/ShortURLTest.php | 3 --- tests/Unit/Models/ShortURLVisit/ShortURLVisitFactoryTest.php | 3 --- tests/Unit/Models/ShortURLVisit/ShortURLVisitTest.php | 3 --- tests/Unit/TestCase.php | 3 +++ 14 files changed, 3 insertions(+), 39 deletions(-) diff --git a/tests/Unit/Classes/BuilderTest.php b/tests/Unit/Classes/BuilderTest.php index 85c32f5..114de6c 100644 --- a/tests/Unit/Classes/BuilderTest.php +++ b/tests/Unit/Classes/BuilderTest.php @@ -7,14 +7,11 @@ use AshAllenDesign\ShortURL\Exceptions\ValidationException; use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Config; use ShortURL as ShortURLAlias; class BuilderTest extends TestCase { - use RefreshDatabase; - protected function setUp(): void { parent::setUp(); diff --git a/tests/Unit/Classes/ResolverTest.php b/tests/Unit/Classes/ResolverTest.php index 7ff7f22..e1096fa 100644 --- a/tests/Unit/Classes/ResolverTest.php +++ b/tests/Unit/Classes/ResolverTest.php @@ -7,7 +7,6 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Models\ShortURLVisit; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\Request; use Illuminate\Support\Facades\Config; use Jenssegers\Agent\Agent; @@ -16,8 +15,6 @@ class ResolverTest extends TestCase { - use RefreshDatabase; - /** @test */ public function exception_is_thrown_in_the_constructor_if_the_config_variables_are_invalid() { diff --git a/tests/Unit/Controllers/ShortURLControllerTest.php b/tests/Unit/Controllers/ShortURLControllerTest.php index e721862..b661c33 100644 --- a/tests/Unit/Controllers/ShortURLControllerTest.php +++ b/tests/Unit/Controllers/ShortURLControllerTest.php @@ -6,13 +6,10 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Models\ShortURLVisit; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Event; class ShortURLControllerTest extends TestCase { - use RefreshDatabase; - /** @test */ public function request_is_aborted_with_http_404_if_the_short_url_cannot_be_found() { diff --git a/tests/Unit/Controllers/ShortURLDisableRouteTest.php b/tests/Unit/Controllers/ShortURLDisableRouteTest.php index 1cd6429..ebd76d8 100644 --- a/tests/Unit/Controllers/ShortURLDisableRouteTest.php +++ b/tests/Unit/Controllers/ShortURLDisableRouteTest.php @@ -4,12 +4,9 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; -use Illuminate\Foundation\Testing\LazilyRefreshDatabase; class ShortURLDisableRouteTest extends TestCase { - use LazilyRefreshDatabase; - protected function getEnvironmentSetUp($app) { $app['config']->set('short-url.disable_default_route', true); diff --git a/tests/Unit/Models/ShortURL/CastsTest.php b/tests/Unit/Models/ShortURL/CastsTest.php index c38aba5..42e9666 100644 --- a/tests/Unit/Models/ShortURL/CastsTest.php +++ b/tests/Unit/Models/ShortURL/CastsTest.php @@ -7,12 +7,9 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; use Carbon\Carbon; -use Illuminate\Foundation\Testing\LazilyRefreshDatabase; final class CastsTest extends TestCase { - use LazilyRefreshDatabase; - /** @test */ public function carbon_date_objects_are_returned(): void { diff --git a/tests/Unit/Models/ShortURL/ShortURLFactoryTest.php b/tests/Unit/Models/ShortURL/ShortURLFactoryTest.php index 253cf16..9ec906d 100644 --- a/tests/Unit/Models/ShortURL/ShortURLFactoryTest.php +++ b/tests/Unit/Models/ShortURL/ShortURLFactoryTest.php @@ -4,12 +4,9 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; class ShortURLFactoryTest extends TestCase { - use RefreshDatabase; - public function test_that_the_short_url_model_factory_works_fine() { $shortURL = ShortURL::factory()->create(); diff --git a/tests/Unit/Models/ShortURL/ShortURLTest.php b/tests/Unit/Models/ShortURL/ShortURLTest.php index 544effa..8be9406 100644 --- a/tests/Unit/Models/ShortURL/ShortURLTest.php +++ b/tests/Unit/Models/ShortURL/ShortURLTest.php @@ -6,12 +6,9 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; -use Illuminate\Foundation\Testing\LazilyRefreshDatabase; final class ShortURLTest extends TestCase { - use LazilyRefreshDatabase; - /** @test */ public function connection_can_be_overridden(): void { diff --git a/tests/Unit/Models/ShortURL/TrackingEnabledTest.php b/tests/Unit/Models/ShortURL/TrackingEnabledTest.php index 15062f2..09ac8a8 100644 --- a/tests/Unit/Models/ShortURL/TrackingEnabledTest.php +++ b/tests/Unit/Models/ShortURL/TrackingEnabledTest.php @@ -4,12 +4,9 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; class TrackingEnabledTest extends TestCase { - use RefreshDatabase; - /** @test */ public function true_is_returned_if_tracking_is_enabled_for_the_short_url() { diff --git a/tests/Unit/Models/ShortURL/TrackingFieldsTest.php b/tests/Unit/Models/ShortURL/TrackingFieldsTest.php index b7056b6..3a4e0e7 100644 --- a/tests/Unit/Models/ShortURL/TrackingFieldsTest.php +++ b/tests/Unit/Models/ShortURL/TrackingFieldsTest.php @@ -4,12 +4,9 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; class TrackingFieldsTest extends TestCase { - use RefreshDatabase; - /** @test */ public function array_is_returned_with_tracked_fields() { diff --git a/tests/Unit/Models/ShortURLVisit/CastsTest.php b/tests/Unit/Models/ShortURLVisit/CastsTest.php index 9587191..f1b11ad 100644 --- a/tests/Unit/Models/ShortURLVisit/CastsTest.php +++ b/tests/Unit/Models/ShortURLVisit/CastsTest.php @@ -8,12 +8,9 @@ use AshAllenDesign\ShortURL\Models\ShortURLVisit; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; use Carbon\Carbon; -use Illuminate\Foundation\Testing\LazilyRefreshDatabase; final class CastsTest extends TestCase { - use LazilyRefreshDatabase; - /** @test */ public function carbon_date_objects_are_returned(): void { diff --git a/tests/Unit/Models/ShortURLVisit/ShortURLTest.php b/tests/Unit/Models/ShortURLVisit/ShortURLTest.php index 2af911f..ee3b614 100644 --- a/tests/Unit/Models/ShortURLVisit/ShortURLTest.php +++ b/tests/Unit/Models/ShortURLVisit/ShortURLTest.php @@ -5,12 +5,9 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Models\ShortURLVisit; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; -use Illuminate\Foundation\Testing\LazilyRefreshDatabase; class ShortURLTest extends TestCase { - use LazilyRefreshDatabase; - /** @test */ public function short_url_can_be_fetched_from_visit(): void { diff --git a/tests/Unit/Models/ShortURLVisit/ShortURLVisitFactoryTest.php b/tests/Unit/Models/ShortURLVisit/ShortURLVisitFactoryTest.php index 42881fb..01b06e5 100644 --- a/tests/Unit/Models/ShortURLVisit/ShortURLVisitFactoryTest.php +++ b/tests/Unit/Models/ShortURLVisit/ShortURLVisitFactoryTest.php @@ -5,12 +5,9 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Models\ShortURLVisit; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; -use Illuminate\Foundation\Testing\RefreshDatabase; class ShortURLVisitFactoryTest extends TestCase { - use RefreshDatabase; - /** @test */ public function test_that_short_url_visit_model_factory_works_fine(): void { diff --git a/tests/Unit/Models/ShortURLVisit/ShortURLVisitTest.php b/tests/Unit/Models/ShortURLVisit/ShortURLVisitTest.php index 2f80d0f..d05cf01 100644 --- a/tests/Unit/Models/ShortURLVisit/ShortURLVisitTest.php +++ b/tests/Unit/Models/ShortURLVisit/ShortURLVisitTest.php @@ -6,12 +6,9 @@ use AshAllenDesign\ShortURL\Models\ShortURLVisit; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; -use Illuminate\Foundation\Testing\LazilyRefreshDatabase; final class ShortURLVisitTest extends TestCase { - use LazilyRefreshDatabase; - /** @test */ public function connection_can_be_overridden(): void { diff --git a/tests/Unit/TestCase.php b/tests/Unit/TestCase.php index c066f32..59edb2b 100644 --- a/tests/Unit/TestCase.php +++ b/tests/Unit/TestCase.php @@ -5,10 +5,13 @@ use AshAllenDesign\ShortURL\Facades\ShortURL; use AshAllenDesign\ShortURL\Providers\ShortURLProvider; use Illuminate\Foundation\Application; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Orchestra\Testbench\TestCase as OrchestraTestCase; abstract class TestCase extends OrchestraTestCase { + use LazilyRefreshDatabase; + /** * Load package service provider. * From 34bc060c2ab0b1273c6ac34b93883c362c545eea Mon Sep 17 00:00:00 2001 From: Ash Allen Date: Mon, 11 Mar 2024 23:50:00 +0000 Subject: [PATCH 6/7] Run the migrations using Testbench. --- phpunit.xml | 4 +++- testbench.yaml | 5 +++++ tests/Unit/TestCase.php | 41 ++--------------------------------------- 3 files changed, 10 insertions(+), 40 deletions(-) create mode 100644 testbench.yaml diff --git a/phpunit.xml b/phpunit.xml index 54e69ac..3f035bb 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -21,5 +21,7 @@ + + - \ No newline at end of file + diff --git a/testbench.yaml b/testbench.yaml new file mode 100644 index 0000000..6f21dc2 --- /dev/null +++ b/testbench.yaml @@ -0,0 +1,5 @@ +migrations: + - database/migrations + +workbench: + install: false diff --git a/tests/Unit/TestCase.php b/tests/Unit/TestCase.php index 59edb2b..7bc867e 100644 --- a/tests/Unit/TestCase.php +++ b/tests/Unit/TestCase.php @@ -6,11 +6,13 @@ use AshAllenDesign\ShortURL\Providers\ShortURLProvider; use Illuminate\Foundation\Application; use Illuminate\Foundation\Testing\LazilyRefreshDatabase; +use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\TestCase as OrchestraTestCase; abstract class TestCase extends OrchestraTestCase { use LazilyRefreshDatabase; + use WithWorkbench; /** * Load package service provider. @@ -35,43 +37,4 @@ protected function getPackageAliases($app) 'ShortURL' => ShortURL::class, ]; } - - /** - * Define environment setup. - * - * @param Application $app - * @return void - */ - protected function getEnvironmentSetUp($app) - { - $app['config']->set('database.default', 'testdb'); - $app['config']->set('database.connections.testdb', [ - 'driver' => 'sqlite', - 'database' => ':memory:', - ]); - - $this->migrateDatabase(); - } - - /** - * Include each of the migrations and migrate them to - * finish preparing the database for running the - * tests. - */ - private function migrateDatabase(): void - { - include_once __DIR__.'/../../database/migrations/2019_12_22_015115_create_short_urls_table.php'; - include_once __DIR__.'/../../database/migrations/2019_12_22_015214_create_short_url_visits_table.php'; - include_once __DIR__.'/../../database/migrations/2020_02_11_224848_update_short_url_table_for_version_two_zero_zero.php'; - include_once __DIR__.'/../../database/migrations/2020_02_12_008432_update_short_url_visits_table_for_version_two_zero_zero.php'; - include_once __DIR__.'/../../database/migrations/2020_04_10_224546_update_short_url_table_for_version_three_zero_zero.php'; - include_once __DIR__.'/../../database/migrations/2020_04_20_009283_update_short_url_table_add_option_to_forward_query_params.php'; - - (new \CreateShortUrlsTable)->up(); - (new \CreateShortUrlVisitsTable)->up(); - (new \UpdateShortURLTableForVersionTwoZeroZero)->up(); - (new \UpdateShortURLVisitsTableForVersionTwoZeroZero)->up(); - (new \UpdateShortURLTableForVersionThreeZeroZero)->up(); - (new \UpdateShortUrlTableAddOptionToForwardQueryParams)->up(); - } } From f5b588d819afa1e0ee68ce0f9b03f7e870964e4e Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 11 Mar 2024 23:56:09 +0000 Subject: [PATCH 7/7] Apply fixes from StyleCI --- tests/Unit/TestCase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Unit/TestCase.php b/tests/Unit/TestCase.php index 7bc867e..1c78702 100644 --- a/tests/Unit/TestCase.php +++ b/tests/Unit/TestCase.php @@ -4,7 +4,6 @@ use AshAllenDesign\ShortURL\Facades\ShortURL; use AshAllenDesign\ShortURL\Providers\ShortURLProvider; -use Illuminate\Foundation\Application; use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\TestCase as OrchestraTestCase;