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..81a0a54 100644 --- a/composer.json +++ b/composer.json @@ -20,15 +20,15 @@ "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", - "phpunit/phpunit": "^8.2 || ^9.0", + "orchestra/testbench": "^6.0|^7.0|^8.0|^9.0", + "phpunit/phpunit": "^8.2|^9.0|^10.0", "nunomaduro/larastan": "^0.7.12 || ^1.0.0 || ^2.0" }, "autoload": { 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/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', 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/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 05cb8be..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() { @@ -184,7 +181,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 [ [ 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..1c78702 100644 --- a/tests/Unit/TestCase.php +++ b/tests/Unit/TestCase.php @@ -4,11 +4,15 @@ 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; abstract class TestCase extends OrchestraTestCase { + use LazilyRefreshDatabase; + use WithWorkbench; + /** * Load package service provider. * @@ -32,43 +36,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(); - } }