diff --git a/.gitignore b/.gitignore index 1778774..b9bd329 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .idea/ vendor/ composer.lock -.phpunit.result.cache \ No newline at end of file +/.phpunit.cache \ No newline at end of file diff --git a/composer.json b/composer.json index 0f3e98f..c2a5af7 100644 --- a/composer.json +++ b/composer.json @@ -1,59 +1,59 @@ { - "name": "ashallendesign/short-url", - "description": "A Laravel package for creating shortened URLs for your web apps.", - "type": "library", - "homepage": "https://github.com/ash-jc-allen/short-url", - "license": "MIT", - "authors": [ - { - "name": "Ash Allen", - "email": "mail@ashallendesign.co.uk" - } - ], - "keywords": [ - "ashallendesign", - "short-urls", - "url-shortener", - "laravel", - "laravel-package" - ], - "require": { - "php": "^8.1", - "nesbot/carbon": "^2.0|^3.0", - "illuminate/container": "^10.0|^11.0", - "illuminate/database": "^10.0|^11.0", - "hashids/hashids": "^4.0|^5.0", - "whichbrowser/parser": "^2.1" - }, - "require-dev": { - "mockery/mockery": "^1.0", - "orchestra/testbench": "^8.0|^9.0", - "phpunit/phpunit": "^8.2|^9.0|^10.0", - "larastan/larastan": "^2.0" - }, - "autoload": { - "psr-4": { - "AshAllenDesign\\ShortURL\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "AshAllenDesign\\ShortURL\\Tests\\": "tests/" - } - }, - "extra": { - "laravel": { - "providers": [ - "AshAllenDesign\\ShortURL\\Providers\\ShortURLProvider" - ], - "aliases": { - "ShortURL": "AshAllenDesign\\ShortURL\\Facades\\ShortURL" - } - } - }, - "scripts": { - "test": "vendor/bin/phpunit" - }, - "minimum-stability": "dev", - "prefer-stable": true + "name": "ashallendesign/short-url", + "description": "A Laravel package for creating shortened URLs for your web apps.", + "type": "library", + "homepage": "https://github.com/ash-jc-allen/short-url", + "license": "MIT", + "authors": [ + { + "name": "Ash Allen", + "email": "mail@ashallendesign.co.uk" + } + ], + "keywords": [ + "ashallendesign", + "short-urls", + "url-shortener", + "laravel", + "laravel-package" + ], + "require": { + "php": "^8.1", + "nesbot/carbon": "^2.0|^3.0", + "illuminate/container": "^10.0|^11.0", + "illuminate/database": "^10.0|^11.0", + "hashids/hashids": "^4.0|^5.0", + "whichbrowser/parser": "^2.1" + }, + "require-dev": { + "mockery/mockery": "^1.0", + "orchestra/testbench": "^8.0|^9.0", + "phpunit/phpunit": "^10.0|^11.0", + "larastan/larastan": "^2.0" + }, + "autoload": { + "psr-4": { + "AshAllenDesign\\ShortURL\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "AshAllenDesign\\ShortURL\\Tests\\": "tests/" + } + }, + "extra": { + "laravel": { + "providers": [ + "AshAllenDesign\\ShortURL\\Providers\\ShortURLProvider" + ], + "aliases": { + "ShortURL": "AshAllenDesign\\ShortURL\\Facades\\ShortURL" + } + } + }, + "scripts": { + "test": "vendor/bin/phpunit" + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/phpunit.xml b/phpunit.xml index 3f035bb..8b1ce01 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,27 +1,18 @@ - - - - tests - - - - - src/ - - - - - - - + + + + tests + + + + + + + + + + src/ + + diff --git a/tests/Unit/Classes/BuilderTest.php b/tests/Unit/Classes/BuilderTest.php index bd4daea..4d6281e 100644 --- a/tests/Unit/Classes/BuilderTest.php +++ b/tests/Unit/Classes/BuilderTest.php @@ -11,9 +11,11 @@ use AshAllenDesign\ShortURL\Tests\Unit\TestCase; use Hashids\Hashids; use Illuminate\Support\Facades\Config; +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\TestWith; use ShortURL as ShortURLAlias; -class BuilderTest extends TestCase +final class BuilderTest extends TestCase { protected function setUp(): void { @@ -23,8 +25,8 @@ protected function setUp(): void Config::set('app.url', 'https://app-url.com'); } - /** @test */ - public function exception_is_thrown_in_the_constructor_if_the_config_variables_are_invalid() + #[Test] + public function exception_is_thrown_in_the_constructor_if_the_config_variables_are_invalid(): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('The config URL length is not a valid integer.'); @@ -34,8 +36,8 @@ public function exception_is_thrown_in_the_constructor_if_the_config_variables_a app(Builder::class); } - /** @test */ - public function exception_is_thrown_if_the_destination_url_does_not_begin_with_http_or_https() + #[Test] + public function exception_is_thrown_if_the_destination_url_does_not_begin_with_http_or_https(): void { $this->expectException(ShortURLException::class); $this->expectExceptionMessage('The destination URL must begin with http:// or https://'); @@ -44,8 +46,8 @@ public function exception_is_thrown_if_the_destination_url_does_not_begin_with_h $builder->destinationUrl('INVALID'); } - /** @test */ - public function exception_is_thrown_if_no_destination_url_is_set() + #[Test] + public function exception_is_thrown_if_no_destination_url_is_set(): void { $this->expectException(ShortURLException::class); $this->expectExceptionMessage('No destination URL has been set.'); @@ -54,24 +56,24 @@ public function exception_is_thrown_if_no_destination_url_is_set() $builder->make(); } - /** @test */ - public function destination_url_is_changed_to_https_if_secure_flag_has_been_set() + #[Test] + public function destination_url_is_changed_to_https_if_secure_flag_has_been_set(): void { $builder = app(Builder::class); $shortUrl = $builder->destinationUrl('http://domain.com')->secure()->make(); $this->assertSame('https://domain.com', $shortUrl->destination_url); } - /** @test */ - public function destination_url_is_not_changed_to_https_if_secure_flag_has_been_set_to_false() + #[Test] + public function destination_url_is_not_changed_to_https_if_secure_flag_has_been_set_to_false(): void { $builder = app(Builder::class); $shortUrl = $builder->destinationUrl('http://domain.com')->secure(false)->make(); $this->assertSame('http://domain.com', $shortUrl->destination_url); } - /** @test */ - public function destination_url_is_changed_to_https_if_enforce_https_flag_is_set_to_true_from_the_config() + #[Test] + public function destination_url_is_changed_to_https_if_enforce_https_flag_is_set_to_true_from_the_config(): void { Config::set('short-url.enforce_https', true); $builder = app(Builder::class); @@ -79,8 +81,8 @@ public function destination_url_is_changed_to_https_if_enforce_https_flag_is_set $this->assertSame('https://domain.com', $shortUrl->destination_url); } - /** @test */ - public function destination_url_is_not_changed_to_https_if_enforce_https_flag_is_set_to_false_from_the_config() + #[Test] + public function destination_url_is_not_changed_to_https_if_enforce_https_flag_is_set_to_false_from_the_config(): void { Config::set('short-url.enforce_https', false); $builder = new Builder(new Validation(), new KeyGenerator(new Hashids())); @@ -88,8 +90,8 @@ public function destination_url_is_not_changed_to_https_if_enforce_https_flag_is $this->assertSame('http://domain.com', $shortUrl->destination_url); } - /** @test */ - public function destination_url_is_changed_to_https_if_enforce_https_flag_is_set_to_false_in_the_config_but_set_when_creating_url() + #[Test] + public function destination_url_is_changed_to_https_if_enforce_https_flag_is_set_to_false_in_the_config_but_set_when_creating_url(): void { Config::set('short-url.enforce_https', false); $builder = app(Builder::class); @@ -97,8 +99,8 @@ public function destination_url_is_changed_to_https_if_enforce_https_flag_is_set $this->assertSame('https://domain.com', $shortUrl->destination_url); } - /** @test */ - public function forward_query_params_is_set_from_the_config_if_it_is_not_explicitly_set() + #[Test] + public function forward_query_params_is_set_from_the_config_if_it_is_not_explicitly_set(): void { Config::set('short-url.forward_query_params', true); @@ -112,8 +114,8 @@ public function forward_query_params_is_set_from_the_config_if_it_is_not_explici $this->assertFalse($shortUrl->forward_query_params); } - /** @test */ - public function forward_query_params_is_not_set_from_the_config_if_it_is_explicitly_set() + #[Test] + public function forward_query_params_is_not_set_from_the_config_if_it_is_explicitly_set(): void { Config::set('short-url.forward_query_params', true); @@ -127,8 +129,8 @@ public function forward_query_params_is_not_set_from_the_config_if_it_is_explici $this->assertTrue($shortUrl->forward_query_params); } - /** @test */ - public function track_visits_flag_is_set_from_the_config_if_it_is_not_explicitly_set() + #[Test] + public function track_visits_flag_is_set_from_the_config_if_it_is_not_explicitly_set(): void { Config::set('short-url.tracking.default_enabled', true); @@ -142,8 +144,8 @@ public function track_visits_flag_is_set_from_the_config_if_it_is_not_explicitly $this->assertFalse($shortUrl->track_visits); } - /** @test */ - public function track_visits_flag_is_not_set_from_the_config_if_it_is_explicitly_set() + #[Test] + public function track_visits_flag_is_not_set_from_the_config_if_it_is_explicitly_set(): void { Config::set('short-url.tracking.default_enabled', true); @@ -157,8 +159,8 @@ public function track_visits_flag_is_not_set_from_the_config_if_it_is_explicitly $this->assertTrue($shortUrl->track_visits); } - /** @test */ - public function track_ip_address_flag_is_not_set_from_the_config_if_it_is_explicitly_set() + #[Test] + public function track_ip_address_flag_is_not_set_from_the_config_if_it_is_explicitly_set(): void { Config::set('short-url.tracking.fields.ip_address', true); @@ -172,8 +174,8 @@ public function track_ip_address_flag_is_not_set_from_the_config_if_it_is_explic $this->assertTrue($shortUrl->track_ip_address); } - /** @test */ - public function track_browser_flag_is_not_set_from_the_config_if_it_is_explicitly_set() + #[Test] + public function track_browser_flag_is_not_set_from_the_config_if_it_is_explicitly_set(): void { Config::set('short-url.tracking.fields.browser', true); @@ -187,8 +189,8 @@ public function track_browser_flag_is_not_set_from_the_config_if_it_is_explicitl $this->assertTrue($shortUrl->track_browser); } - /** @test */ - public function track_browser_version_flag_is_not_set_from_the_config_if_it_is_explicitly_set() + #[Test] + public function track_browser_version_flag_is_not_set_from_the_config_if_it_is_explicitly_set(): void { Config::set('short-url.tracking.fields.browser_version', true); @@ -202,8 +204,8 @@ public function track_browser_version_flag_is_not_set_from_the_config_if_it_is_e $this->assertTrue($shortUrl->track_browser_version); } - /** @test */ - public function track_operating_system_flag_is_not_set_from_the_config_if_it_is_explicitly_set() + #[Test] + public function track_operating_system_flag_is_not_set_from_the_config_if_it_is_explicitly_set(): void { Config::set('short-url.tracking.fields.operating_system', true); @@ -217,8 +219,8 @@ public function track_operating_system_flag_is_not_set_from_the_config_if_it_is_ $this->assertTrue($shortUrl->track_operating_system); } - /** @test */ - public function track_operating_system_version_flag_is_not_set_from_the_config_if_it_is_explicitly_set() + #[Test] + public function track_operating_system_version_flag_is_not_set_from_the_config_if_it_is_explicitly_set(): void { Config::set('short-url.tracking.fields.operating_system_version', true); @@ -232,8 +234,8 @@ public function track_operating_system_version_flag_is_not_set_from_the_config_i $this->assertTrue($shortUrl->track_operating_system_version); } - /** @test */ - public function track_referer_url_flag_is_not_set_from_the_config_if_it_is_explicitly_set() + #[Test] + public function track_referer_url_flag_is_not_set_from_the_config_if_it_is_explicitly_set(): void { Config::set('short-url.tracking.fields.referer_url', true); @@ -247,8 +249,8 @@ public function track_referer_url_flag_is_not_set_from_the_config_if_it_is_expli $this->assertTrue($shortUrl->track_referer_url); } - /** @test */ - public function track_device_type_flag_is_not_set_from_the_config_if_it_is_explicitly_set() + #[Test] + public function track_device_type_flag_is_not_set_from_the_config_if_it_is_explicitly_set(): void { Config::set('short-url.tracking.fields.device_type', true); @@ -262,8 +264,8 @@ public function track_device_type_flag_is_not_set_from_the_config_if_it_is_expli $this->assertTrue($shortUrl->track_device_type); } - /** @test */ - public function exception_is_thrown_if_the_url_key_is_explicitly_set_and_already_exists_in_the_db() + #[Test] + public function exception_is_thrown_if_the_url_key_is_explicitly_set_and_already_exists_in_the_db(): void { ShortURL::create([ 'default_short_url' => 'https://short.com/urlkey123', @@ -280,8 +282,8 @@ public function exception_is_thrown_if_the_url_key_is_explicitly_set_and_already $builder->destinationUrl('https://domain.com')->urlKey('urlkey123')->make(); } - /** @test */ - public function explicitly_defined_url_key_can_be_used_if_it_does_not_exist_in_the_db() + #[Test] + public function explicitly_defined_url_key_can_be_used_if_it_does_not_exist_in_the_db(): void { $builder = app(Builder::class); $builder->destinationUrl('https://domain.com')->urlKey('urlkey123')->make(); @@ -289,8 +291,8 @@ public function explicitly_defined_url_key_can_be_used_if_it_does_not_exist_in_t $this->assertDatabaseHas('short_urls', ['url_key' => 'urlkey123']); } - /** @test */ - public function random_url_key_is_generated_if_one_is_not_explicitly_defined() + #[Test] + public function random_url_key_is_generated_if_one_is_not_explicitly_defined(): void { $builder = app(Builder::class); $shortURL = $builder->destinationUrl('https://domain.com')->make(); @@ -299,8 +301,8 @@ public function random_url_key_is_generated_if_one_is_not_explicitly_defined() $this->assertSame(5, strlen($shortURL->url_key)); } - /** @test */ - public function short_url_can_be_created_and_stored_in_the_database() + #[Test] + public function short_url_can_be_created_and_stored_in_the_database(): void { $builder = app(Builder::class); $shortURL = $builder->destinationUrl('http://domain.com') @@ -332,8 +334,8 @@ public function short_url_can_be_created_and_stored_in_the_database() ]); } - /** @test */ - public function short_url_can_be_created_and_stored_in_the_database_using_the_facade() + #[Test] + public function short_url_can_be_created_and_stored_in_the_database_using_the_facade(): void { ShortURLAlias::destinationUrl('http://domain.com') ->urlKey('customKey') @@ -351,8 +353,8 @@ public function short_url_can_be_created_and_stored_in_the_database_using_the_fa ]); } - /** @test */ - public function correct_redirect_status_code_is_stored_if_explicitly_set() + #[Test] + public function correct_redirect_status_code_is_stored_if_explicitly_set(): void { ShortURLAlias::destinationUrl('http://domain.com') ->urlKey('customKey') @@ -371,8 +373,8 @@ public function correct_redirect_status_code_is_stored_if_explicitly_set() ]); } - /** @test */ - public function exception_is_thrown_if_the_redirect_status_code_is_not_valid() + #[Test] + public function exception_is_thrown_if_the_redirect_status_code_is_not_valid(): void { $this->expectException(ShortURLException::class); $this->expectExceptionMessage('The redirect status code must be a valid redirect HTTP status code.'); @@ -389,8 +391,8 @@ public function exception_is_thrown_if_the_redirect_status_code_is_not_valid() ]); } - /** @test */ - public function exception_is_thrown_if_the_activation_date_is_in_the_past() + #[Test] + public function exception_is_thrown_if_the_activation_date_is_in_the_past(): void { $this->expectException(ShortURLException::class); $this->expectExceptionMessage('The activation date must not be in the past.'); @@ -401,8 +403,8 @@ public function exception_is_thrown_if_the_activation_date_is_in_the_past() ->make(); } - /** @test */ - public function exception_is_thrown_if_the_deactivation_date_is_in_the_past() + #[Test] + public function exception_is_thrown_if_the_deactivation_date_is_in_the_past(): void { $this->expectException(ShortURLException::class); $this->expectExceptionMessage('The deactivation date must not be in the past.'); @@ -413,8 +415,8 @@ public function exception_is_thrown_if_the_deactivation_date_is_in_the_past() ->make(); } - /** @test */ - public function exception_is_thrown_if_the_deactivation_date_is_before_the_activation_date() + #[Test] + public function exception_is_thrown_if_the_deactivation_date_is_before_the_activation_date(): void { $this->expectException(ShortURLException::class); $this->expectExceptionMessage('The deactivation date must not be before the activation date.'); @@ -426,8 +428,8 @@ public function exception_is_thrown_if_the_deactivation_date_is_before_the_activ ->make(); } - /** @test */ - public function short_url_can_be_created_with_an_explicit_activation_date() + #[Test] + public function short_url_can_be_created_with_an_explicit_activation_date(): void { $activateTime = now()->addHour(); @@ -444,8 +446,8 @@ public function short_url_can_be_created_with_an_explicit_activation_date() ]); } - /** @test */ - public function short_url_can_be_created_with_an_explicit_activation_date_and_deactivation_date() + #[Test] + public function short_url_can_be_created_with_an_explicit_activation_date_and_deactivation_date(): void { $activateTime = now()->addHour(); $deactivateTime = now()->addHours(2); @@ -464,8 +466,8 @@ public function short_url_can_be_created_with_an_explicit_activation_date_and_de ]); } - /** @test */ - public function short_url_can_be_created_with_an_explicit_deactivation_date() + #[Test] + public function short_url_can_be_created_with_an_explicit_deactivation_date(): void { $deactivateTime = now()->addHours(2); @@ -482,8 +484,8 @@ public function short_url_can_be_created_with_an_explicit_deactivation_date() ]); } - /** @test */ - public function short_url_prefix_can_be_changed_via_configuration() + #[Test] + public function short_url_prefix_can_be_changed_via_configuration(): void { Config::set('short-url.prefix', '/s'); @@ -496,23 +498,20 @@ public function short_url_prefix_can_be_changed_via_configuration() ]); } - /** - * @test - * - * @testWith ["s", "s"] - * ["/s", "s"] - * ["/s/", "s"] - * ["s/", "s"] - * [null, null] - */ - public function correct_prefix_is_returned(?string $prefix, ?string $expected) + #[Test] + #[TestWith(['s', 's'])] + #[TestWith(['/s', 's'])] + #[TestWith(['/s/', 's'])] + #[TestWith(['s/', 's'])] + #[TestWith([null, null])] + public function correct_prefix_is_returned(?string $prefix, ?string $expected): void { Config::set('short-url.prefix', $prefix); self::assertSame($expected, ShortURLAlias::prefix()); } - /** @test */ + #[Test] public function short_url_can_be_created_with_a_null_prefix(): void { $deactivateTime = now()->addHours(2); @@ -530,12 +529,9 @@ public function short_url_can_be_created_with_a_null_prefix(): void ]); } - /** - * @test - * - * @testWith [true, "https://domain.com"] - * [false, "https://fallback.com"] - */ + #[Test] + #[TestWith([true, 'https://domain.com'])] + #[TestWith([false, 'https://fallback.com'])] public function data_can_be_set_on_the_builder_using_when(bool $flag, string $destination): void { $shortUrl = app(Builder::class) @@ -549,7 +545,7 @@ public function data_can_be_set_on_the_builder_using_when(bool $flag, string $de $this->assertSame($destination, $shortUrl->destination_url); } - /** @test */ + #[Test] public function data_can_be_overridden_on_model_using_make_callback(): void { $shortUrl = app(Builder::class) @@ -562,7 +558,7 @@ public function data_can_be_overridden_on_model_using_make_callback(): void $this->assertSame('https://bar.com', $shortUrl->destination_url); } - /** @test */ + #[Test] public function app_url_is_set_if_the_default_url_config_value_is_not_set(): void { Config::set('short-url.default_url', null); @@ -575,7 +571,7 @@ public function app_url_is_set_if_the_default_url_config_value_is_not_set(): voi $this->assertSame('https://app-url.com/short/abc123', $shortUrl->default_short_url); } - /** @test */ + #[Test] public function short_url_can_be_created_with_a_custom_integer_seed(): void { $shortUrlOne = app(Builder::class) @@ -586,7 +582,7 @@ public function short_url_can_be_created_with_a_custom_integer_seed(): void $this->assertSame('https://short-url.com/short/4ZRw4', $shortUrlOne->default_short_url); } - /** @test */ + #[Test] public function short_url_can_be_created_using_the_url_key_if_the_key_and_seeder_are_both_set(): void { $shortUrl = app(Builder::class) diff --git a/tests/Unit/Classes/ResolverTest.php b/tests/Unit/Classes/ResolverTest.php index f8b6321..4abcba3 100644 --- a/tests/Unit/Classes/ResolverTest.php +++ b/tests/Unit/Classes/ResolverTest.php @@ -11,9 +11,11 @@ use AshAllenDesign\ShortURL\Tests\Unit\TestCase; use Illuminate\Http\Request; use Illuminate\Support\Facades\Config; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -class ResolverTest extends TestCase +final class ResolverTest extends TestCase { public static function trackingFieldsProvider(): array { @@ -85,8 +87,8 @@ public static function trackingFieldsProvider(): array ]; } - /** @test */ - public function exception_is_thrown_in_the_constructor_if_the_config_variables_are_invalid() + #[Test] + public function exception_is_thrown_in_the_constructor_if_the_config_variables_are_invalid(): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('The config URL length is not a valid integer.'); @@ -96,8 +98,8 @@ public function exception_is_thrown_in_the_constructor_if_the_config_variables_a app(Resolver::class); } - /** @test */ - public function request_is_aborted_if_url_is_single_use_and_has_already_been_visited() + #[Test] + public function request_is_aborted_if_url_is_single_use_and_has_already_been_visited(): void { $this->expectException(NotFoundHttpException::class); @@ -117,8 +119,8 @@ public function request_is_aborted_if_url_is_single_use_and_has_already_been_vis $resolver->handleVisit($request, $shortURL); } - /** @test */ - public function request_is_not_aborted_if_url_is_single_use_and_has_not_been_visited() + #[Test] + public function request_is_not_aborted_if_url_is_single_use_and_has_not_been_visited(): void { $shortURL = ShortURL::create([ 'destination_url' => 'https://google.com', @@ -137,8 +139,8 @@ public function request_is_not_aborted_if_url_is_single_use_and_has_not_been_vis $this->assertTrue($result); } - /** @test */ - public function request_is_not_aborted_if_url_is_not_single_use_and_has_been_visited() + #[Test] + public function request_is_not_aborted_if_url_is_not_single_use_and_has_been_visited(): void { $shortURL = ShortURL::create([ 'destination_url' => 'https://google.com', @@ -158,8 +160,8 @@ public function request_is_not_aborted_if_url_is_not_single_use_and_has_been_vis $this->assertTrue($result); } - /** @test */ - public function visit_details_are_not_recorded_if_url_does_not_have_tracking_enabled() + #[Test] + public function visit_details_are_not_recorded_if_url_does_not_have_tracking_enabled(): void { $shortURL = ShortURL::create([ 'destination_url' => 'https://google.com', @@ -187,11 +189,8 @@ public function visit_details_are_not_recorded_if_url_does_not_have_tracking_ena ]); } - /** - * @test - * - * @dataProvider trackingFieldsProvider - */ + #[Test] + #[DataProvider('trackingFieldsProvider')] public function visit_is_recorded_if_url_has_tracking_enabled(string $userAgent, array $expectedTrackingData): void { $shortURL = ShortURL::create([ @@ -229,7 +228,7 @@ public function visit_is_recorded_if_url_has_tracking_enabled(string $userAgent, ]); } - /** @test */ + #[Test] public function visit_is_recorded_if_url_has_tracking_enabled_and_the_user_agent_is_invalid(): void { $shortURL = ShortURL::create([ @@ -271,7 +270,7 @@ public function visit_is_recorded_if_url_has_tracking_enabled_and_the_user_agent ]); } - /** @test */ + #[Test] public function visit_is_recorded_if_url_has_tracking_enabled_and_the_user_agent_is_empty(): void { $shortURL = ShortURL::create([ @@ -313,8 +312,8 @@ public function visit_is_recorded_if_url_has_tracking_enabled_and_the_user_agent ]); } - /** @test */ - public function only_specific_fields_are_recorded_if_enabled() + #[Test] + public function only_specific_fields_are_recorded_if_enabled(): void { // Disable default tracking for the IP address, browser // version and referer URL. @@ -360,8 +359,8 @@ public function only_specific_fields_are_recorded_if_enabled() ]); } - /** @test */ - public function request_is_aborted_if_url_is_single_use_and_the_tracking_is_not_enabled() + #[Test] + public function request_is_aborted_if_url_is_single_use_and_the_tracking_is_not_enabled(): void { $shortURL = ShortURL::create([ 'destination_url' => 'https://google.com', @@ -385,8 +384,8 @@ public function request_is_aborted_if_url_is_single_use_and_the_tracking_is_not_ $resolver->handleVisit($request, $shortURL); } - /** @test */ - public function referer_url_is_stored_if_it_is_enabled() + #[Test] + public function referer_url_is_stored_if_it_is_enabled(): void { $shortURL = ShortURL::create([ 'destination_url' => 'https://google.com', @@ -421,7 +420,7 @@ public function referer_url_is_stored_if_it_is_enabled() ]); } - /** @test */ + #[Test] public function fields_are_not_recorded_if_all_are_true_but_track_visits_is_disabled(): void { $shortURL = ShortURL::create([ diff --git a/tests/Unit/Classes/ValidationTest.php b/tests/Unit/Classes/ValidationTest.php index d84b5f4..45c726b 100644 --- a/tests/Unit/Classes/ValidationTest.php +++ b/tests/Unit/Classes/ValidationTest.php @@ -6,11 +6,12 @@ use AshAllenDesign\ShortURL\Exceptions\ValidationException; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; use Illuminate\Support\Facades\Config; +use PHPUnit\Framework\Attributes\Test; -class ValidationTest extends TestCase +final class ValidationTest extends TestCase { - /** @test */ - public function exception_is_thrown_if_the_key_length_is_not_an_integer() + #[Test] + public function exception_is_thrown_if_the_key_length_is_not_an_integer(): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('The config URL length is not a valid integer.'); @@ -21,8 +22,8 @@ public function exception_is_thrown_if_the_key_length_is_not_an_integer() $validation->validateConfig(); } - /** @test */ - public function exception_is_thrown_if_the_key_length_is_below_3() + #[Test] + public function exception_is_thrown_if_the_key_length_is_below_3(): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('The config URL length must be 3 or above.'); @@ -33,8 +34,8 @@ public function exception_is_thrown_if_the_key_length_is_below_3() $validation->validateConfig(); } - /** @test */ - public function exception_is_thrown_if_the_default_enabled_variable_is_not_a_boolean() + #[Test] + public function exception_is_thrown_if_the_default_enabled_variable_is_not_a_boolean(): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('The default_enabled config variable must be a boolean.'); @@ -45,8 +46,8 @@ public function exception_is_thrown_if_the_default_enabled_variable_is_not_a_boo $validation->validateConfig(); } - /** @test */ - public function exception_is_thrown_if_any_of_the_tracking_options_are_not_null() + #[Test] + public function exception_is_thrown_if_any_of_the_tracking_options_are_not_null(): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('The ip_address config variable must be a boolean.'); @@ -57,8 +58,8 @@ public function exception_is_thrown_if_any_of_the_tracking_options_are_not_null( $validation->validateConfig(); } - /** @test */ - public function exception_is_thrown_if_the_disable_default_route_option_is_not_a_boolean() + #[Test] + public function exception_is_thrown_if_the_disable_default_route_option_is_not_a_boolean(): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('The disable_default_route config variable must be a boolean.'); @@ -69,8 +70,8 @@ public function exception_is_thrown_if_the_disable_default_route_option_is_not_a $validation->validateConfig(); } - /** @test */ - public function exception_is_thrown_if_the_key_salt_is_not_a_string() + #[Test] + public function exception_is_thrown_if_the_key_salt_is_not_a_string(): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('The config key salt must be a string.'); @@ -81,8 +82,8 @@ public function exception_is_thrown_if_the_key_salt_is_not_a_string() $validation->validateConfig(); } - /** @test */ - public function exception_is_thrown_if_the_key_salt_is_less_than_one_character_long() + #[Test] + public function exception_is_thrown_if_the_key_salt_is_less_than_one_character_long(): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('The config key salt must be at least 1 character long.'); @@ -93,8 +94,8 @@ public function exception_is_thrown_if_the_key_salt_is_less_than_one_character_l $validation->validateConfig(); } - /** @test */ - public function exception_is_thrown_if_the_enforce_https_variable_is_not_a_boolean() + #[Test] + public function exception_is_thrown_if_the_enforce_https_variable_is_not_a_boolean(): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('The enforce_https config variable must be a boolean.'); @@ -105,8 +106,8 @@ public function exception_is_thrown_if_the_enforce_https_variable_is_not_a_boole $validation->validateConfig(); } - /** @test */ - public function exception_is_thrown_if_the_forward_query_params_variable_is_not_a_boolean() + #[Test] + public function exception_is_thrown_if_the_forward_query_params_variable_is_not_a_boolean(): void { $this->expectException(ValidationException::class); $this->expectExceptionMessage('The forward_query_params config variable must be a boolean.'); @@ -117,7 +118,7 @@ public function exception_is_thrown_if_the_forward_query_params_variable_is_not_ $validation->validateConfig(); } - /** @test */ + #[Test] public function exception_is_thrown_if_the_default_url_is_not_a_string(): void { $this->expectException(ValidationException::class); diff --git a/tests/Unit/Controllers/ShortURLControllerEmptyPrefixTest.php b/tests/Unit/Controllers/ShortURLControllerEmptyPrefixTest.php index cd965a3..a9fa149 100644 --- a/tests/Unit/Controllers/ShortURLControllerEmptyPrefixTest.php +++ b/tests/Unit/Controllers/ShortURLControllerEmptyPrefixTest.php @@ -4,8 +4,9 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; +use PHPUnit\Framework\Attributes\Test; -class ShortURLControllerEmptyPrefixTest extends TestCase +final class ShortURLControllerEmptyPrefixTest extends TestCase { protected function getEnvironmentSetUp($app) { @@ -14,8 +15,8 @@ protected function getEnvironmentSetUp($app) parent::getEnvironmentSetUp($app); } - /** @test */ - public function visitor_is_redirected_to_the_destination_url_with_null_prefix() + #[Test] + public function visitor_is_redirected_to_the_destination_url_with_null_prefix(): void { ShortURL::create([ 'destination_url' => 'https://google.com', diff --git a/tests/Unit/Controllers/ShortURLControllerPrefixTest.php b/tests/Unit/Controllers/ShortURLControllerPrefixTest.php index 8b49e91..085d91d 100644 --- a/tests/Unit/Controllers/ShortURLControllerPrefixTest.php +++ b/tests/Unit/Controllers/ShortURLControllerPrefixTest.php @@ -4,8 +4,9 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; +use PHPUnit\Framework\Attributes\Test; -class ShortURLControllerPrefixTest extends TestCase +final class ShortURLControllerPrefixTest extends TestCase { protected function getEnvironmentSetUp($app) { @@ -14,8 +15,8 @@ protected function getEnvironmentSetUp($app) parent::getEnvironmentSetUp($app); } - /** @test */ - public function visitor_is_redirected_to_the_destination_url_with_custom_prefix() + #[Test] + public function visitor_is_redirected_to_the_destination_url_with_custom_prefix(): void { ShortURL::create([ 'destination_url' => 'https://google.com', diff --git a/tests/Unit/Controllers/ShortURLControllerTest.php b/tests/Unit/Controllers/ShortURLControllerTest.php index b661c33..6f8fca4 100644 --- a/tests/Unit/Controllers/ShortURLControllerTest.php +++ b/tests/Unit/Controllers/ShortURLControllerTest.php @@ -7,17 +7,19 @@ use AshAllenDesign\ShortURL\Models\ShortURLVisit; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; use Illuminate\Support\Facades\Event; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; -class ShortURLControllerTest extends TestCase +final class ShortURLControllerTest extends TestCase { - /** @test */ - public function request_is_aborted_with_http_404_if_the_short_url_cannot_be_found() + #[Test] + public function request_is_aborted_with_http_404_if_the_short_url_cannot_be_found(): void { $this->get('/short/INVALID')->assertNotFound(); } - /** @test */ - public function visitor_is_redirected_to_the_destination_url() + #[Test] + public function visitor_is_redirected_to_the_destination_url(): void { ShortURL::create([ 'destination_url' => 'https://google.com', @@ -32,8 +34,8 @@ public function visitor_is_redirected_to_the_destination_url() $this->get('/short/12345')->assertStatus(301)->assertRedirect('https://google.com'); } - /** @test */ - public function event_is_dispatched_when_the_short_url_is_visited() + #[Test] + public function event_is_dispatched_when_the_short_url_is_visited(): void { Event::fake(); @@ -74,8 +76,8 @@ public function event_is_dispatched_when_the_short_url_is_visited() }); } - /** @test */ - public function visitor_is_redirected_with_correct_status_code() + #[Test] + public function visitor_is_redirected_with_correct_status_code(): void { ShortURL::create([ 'destination_url' => 'https://google.com', @@ -90,8 +92,8 @@ public function visitor_is_redirected_with_correct_status_code() $this->get('/short/12345')->assertStatus(302)->assertRedirect('https://google.com'); } - /** @test */ - public function request_is_aborted_if_the_activation_date_is_in_the_future() + #[Test] + public function request_is_aborted_if_the_activation_date_is_in_the_future(): void { ShortURL::create([ 'destination_url' => 'https://google.com', @@ -107,8 +109,8 @@ public function request_is_aborted_if_the_activation_date_is_in_the_future() $this->get('/short/12345')->assertNotFound(); } - /** @test */ - public function request_is_aborted_if_the_deactivation_date_is_in_the_past() + #[Test] + public function request_is_aborted_if_the_deactivation_date_is_in_the_past(): void { ShortURL::create([ 'destination_url' => 'https://google.com', @@ -124,8 +126,8 @@ public function request_is_aborted_if_the_deactivation_date_is_in_the_past() $this->get('/short/12345')->assertNotFound(); } - /** @test */ - public function visitor_is_redirected_to_the_destination_url_if_the_deactivation_date_is_in_the_future() + #[Test] + public function visitor_is_redirected_to_the_destination_url_if_the_deactivation_date_is_in_the_future(): void { ShortURL::create([ 'destination_url' => 'https://google.com', @@ -141,8 +143,8 @@ public function visitor_is_redirected_to_the_destination_url_if_the_deactivation $this->get('/short/12345')->assertStatus(302)->assertRedirect('https://google.com'); } - /** @test */ - public function visitor_is_redirected_to_the_destination_without_source_query_parameters_if_option_set_to_false() + #[Test] + public function visitor_is_redirected_to_the_destination_without_source_query_parameters_if_option_set_to_false(): void { ShortURL::create([ 'destination_url' => 'https://google.com?param1=abc', @@ -157,11 +159,8 @@ public function visitor_is_redirected_to_the_destination_without_source_query_pa $this->get('/short/12345?param1=test¶m2=test2')->assertStatus(301)->assertRedirect('https://google.com?param1=abc'); } - /** - * @test - * - * @dataProvider forwardQueryParamsProvider - */ + #[Test] + #[DataProvider('forwardQueryParamsProvider')] public function visitor_is_redirected_to_the_destination_with_source_query_parameters_if_option_set_to_true( string $shortUrl, string $requestUrl, diff --git a/tests/Unit/Controllers/ShortURLDisableRouteTest.php b/tests/Unit/Controllers/ShortURLDisableRouteTest.php index ebd76d8..2f78bfd 100644 --- a/tests/Unit/Controllers/ShortURLDisableRouteTest.php +++ b/tests/Unit/Controllers/ShortURLDisableRouteTest.php @@ -4,8 +4,9 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; +use PHPUnit\Framework\Attributes\Test; -class ShortURLDisableRouteTest extends TestCase +final class ShortURLDisableRouteTest extends TestCase { protected function getEnvironmentSetUp($app) { @@ -14,7 +15,7 @@ protected function getEnvironmentSetUp($app) parent::getEnvironmentSetUp($app); } - /** @test */ + #[Test] public function request_is_aborted_if_custom_routing_is_enabled_but_the_default_route_has_been_used(): void { ShortURL::create([ diff --git a/tests/Unit/Models/ShortURL/CastsTest.php b/tests/Unit/Models/ShortURL/CastsTest.php index 42e9666..b0b2e71 100644 --- a/tests/Unit/Models/ShortURL/CastsTest.php +++ b/tests/Unit/Models/ShortURL/CastsTest.php @@ -7,10 +7,11 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; use Carbon\Carbon; +use PHPUnit\Framework\Attributes\Test; final class CastsTest extends TestCase { - /** @test */ + #[Test] public function carbon_date_objects_are_returned(): void { $shortUrl = ShortURL::factory() @@ -29,7 +30,7 @@ public function carbon_date_objects_are_returned(): void $this->assertInstanceOf(Carbon::class, $shortUrl->updated_at); } - /** @test */ + #[Test] public function forward_query_params_is_casted_correctly(): void { $shortUrl = ShortURL::factory()->create(['forward_query_params' => 1]); diff --git a/tests/Unit/Models/ShortURL/ShortURLFactoryTest.php b/tests/Unit/Models/ShortURL/ShortURLFactoryTest.php index 9ec906d..d2b9f69 100644 --- a/tests/Unit/Models/ShortURL/ShortURLFactoryTest.php +++ b/tests/Unit/Models/ShortURL/ShortURLFactoryTest.php @@ -5,9 +5,9 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; -class ShortURLFactoryTest extends TestCase +final class ShortURLFactoryTest extends TestCase { - public function test_that_the_short_url_model_factory_works_fine() + public function test_that_the_short_url_model_factory_works_fine(): void { $shortURL = ShortURL::factory()->create(); diff --git a/tests/Unit/Models/ShortURL/ShortURLTest.php b/tests/Unit/Models/ShortURL/ShortURLTest.php index 8be9406..d4e4f6c 100644 --- a/tests/Unit/Models/ShortURL/ShortURLTest.php +++ b/tests/Unit/Models/ShortURL/ShortURLTest.php @@ -6,10 +6,11 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; +use PHPUnit\Framework\Attributes\Test; final class ShortURLTest extends TestCase { - /** @test */ + #[Test] public function connection_can_be_overridden(): void { config(['short-url.connection' => 'custom']); @@ -20,7 +21,7 @@ public function connection_can_be_overridden(): void ); } - /** @test */ + #[Test] public function default_connection_is_used_if_the_override_is_not_set(): void { $this->assertNull((new ShortURL())->getConnectionName()); diff --git a/tests/Unit/Models/ShortURL/TrackingEnabledTest.php b/tests/Unit/Models/ShortURL/TrackingEnabledTest.php index 09ac8a8..efa82d4 100644 --- a/tests/Unit/Models/ShortURL/TrackingEnabledTest.php +++ b/tests/Unit/Models/ShortURL/TrackingEnabledTest.php @@ -4,11 +4,12 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; +use PHPUnit\Framework\Attributes\Test; -class TrackingEnabledTest extends TestCase +final class TrackingEnabledTest extends TestCase { - /** @test */ - public function true_is_returned_if_tracking_is_enabled_for_the_short_url() + #[Test] + public function true_is_returned_if_tracking_is_enabled_for_the_short_url(): void { $shortURL = ShortURL::create([ 'destination_url' => 'https://google.com', @@ -22,8 +23,8 @@ public function true_is_returned_if_tracking_is_enabled_for_the_short_url() $this->assertTrue($shortURL->trackingEnabled()); } - /** @test */ - public function false_is_returned_if_tracking_is_disabled_for_the_short_url() + #[Test] + public function false_is_returned_if_tracking_is_disabled_for_the_short_url(): void { $shortURL = ShortURL::create([ 'destination_url' => 'https://google.com', diff --git a/tests/Unit/Models/ShortURL/TrackingFieldsTest.php b/tests/Unit/Models/ShortURL/TrackingFieldsTest.php index 3a4e0e7..cbb553e 100644 --- a/tests/Unit/Models/ShortURL/TrackingFieldsTest.php +++ b/tests/Unit/Models/ShortURL/TrackingFieldsTest.php @@ -4,11 +4,12 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; +use PHPUnit\Framework\Attributes\Test; -class TrackingFieldsTest extends TestCase +final class TrackingFieldsTest extends TestCase { - /** @test */ - public function array_is_returned_with_tracked_fields() + #[Test] + public function array_is_returned_with_tracked_fields(): void { $shortURL = ShortURL::create([ 'destination_url' => 'https://google.com', @@ -35,8 +36,8 @@ public function array_is_returned_with_tracked_fields() ], $shortURL->trackingFields()); } - /** @test */ - public function empty_array_is_returned_if_no_fields_are_set_to_be_tracked() + #[Test] + public function empty_array_is_returned_if_no_fields_are_set_to_be_tracked(): void { $shortURL = ShortURL::create([ 'destination_url' => 'https://google.com', diff --git a/tests/Unit/Models/ShortURLVisit/CastsTest.php b/tests/Unit/Models/ShortURLVisit/CastsTest.php index f1b11ad..6342bf3 100644 --- a/tests/Unit/Models/ShortURLVisit/CastsTest.php +++ b/tests/Unit/Models/ShortURLVisit/CastsTest.php @@ -8,10 +8,11 @@ use AshAllenDesign\ShortURL\Models\ShortURLVisit; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; use Carbon\Carbon; +use PHPUnit\Framework\Attributes\Test; final class CastsTest extends TestCase { - /** @test */ + #[Test] public function carbon_date_objects_are_returned(): void { $shortUrlVisit = ShortURLVisit::factory() diff --git a/tests/Unit/Models/ShortURLVisit/ShortURLTest.php b/tests/Unit/Models/ShortURLVisit/ShortURLTest.php index ee3b614..3c43f17 100644 --- a/tests/Unit/Models/ShortURLVisit/ShortURLTest.php +++ b/tests/Unit/Models/ShortURLVisit/ShortURLTest.php @@ -5,10 +5,11 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Models\ShortURLVisit; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; +use PHPUnit\Framework\Attributes\Test; -class ShortURLTest extends TestCase +final class ShortURLTest extends TestCase { - /** @test */ + #[Test] public function short_url_can_be_fetched_from_visit(): void { $shortURL = ShortURL::create([ diff --git a/tests/Unit/Models/ShortURLVisit/ShortURLVisitFactoryTest.php b/tests/Unit/Models/ShortURLVisit/ShortURLVisitFactoryTest.php index 01b06e5..753ce7c 100644 --- a/tests/Unit/Models/ShortURLVisit/ShortURLVisitFactoryTest.php +++ b/tests/Unit/Models/ShortURLVisit/ShortURLVisitFactoryTest.php @@ -5,10 +5,11 @@ use AshAllenDesign\ShortURL\Models\ShortURL; use AshAllenDesign\ShortURL\Models\ShortURLVisit; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; +use PHPUnit\Framework\Attributes\Test; -class ShortURLVisitFactoryTest extends TestCase +final class ShortURLVisitFactoryTest extends TestCase { - /** @test */ + #[Test] public function test_that_short_url_visit_model_factory_works_fine(): void { $shortURL = ShortURL::factory()->create(); diff --git a/tests/Unit/Models/ShortURLVisit/ShortURLVisitTest.php b/tests/Unit/Models/ShortURLVisit/ShortURLVisitTest.php index d05cf01..2107689 100644 --- a/tests/Unit/Models/ShortURLVisit/ShortURLVisitTest.php +++ b/tests/Unit/Models/ShortURLVisit/ShortURLVisitTest.php @@ -6,10 +6,11 @@ use AshAllenDesign\ShortURL\Models\ShortURLVisit; use AshAllenDesign\ShortURL\Tests\Unit\TestCase; +use PHPUnit\Framework\Attributes\Test; final class ShortURLVisitTest extends TestCase { - /** @test */ + #[Test] public function connection_can_be_overridden(): void { config(['short-url.connection' => 'custom']); @@ -20,7 +21,7 @@ public function connection_can_be_overridden(): void ); } - /** @test */ + #[Test] public function default_connection_is_used_if_the_override_is_not_set(): void { $this->assertNull((new ShortURLVisit())->getConnectionName());