diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a9b4452..bd6b127 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: - php: [8.1] + php: [8.2] stability: [prefer-lowest, prefer-stable] # Steps represent a sequence of tasks that will be executed as part of the job diff --git a/.gitignore b/.gitignore index 2963aa5..280cdca 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /.idea coverage.xml .phpunit.result.cache +.phpunit.cache composer.lock \ No newline at end of file diff --git a/README.md b/README.md index 57054f8..e94cffd 100644 --- a/README.md +++ b/README.md @@ -33,13 +33,14 @@ Invite Codes: 8.x | 6.x 9.x | 7.x 10.x | 8.x + 11.x | 9.x ## Installation You can pull in the package using [composer](https://getcomposer.org): ```bash -$ composer require "clarkeash/doorman=^8.0" +$ composer require "clarkeash/doorman=^9.0" ``` Next, migrate the database: diff --git a/composer.json b/composer.json index 41368c1..5a38236 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,8 @@ } ], "require": { - "php": "^8.1", - "laravel/framework": "^10.0", + "php": "^8.2", + "laravel/framework": "^11.0", "ramsey/uuid": "^4.0" }, "autoload": { @@ -24,8 +24,8 @@ } }, "require-dev": { - "orchestra/testbench": "^8.0", - "phpunit/phpunit": "^9.3", + "orchestra/testbench": "^9.0", + "phpunit/phpunit": "^11.0", "mockery/mockery": "^1.4" }, "extra": { diff --git a/phpunit.xml b/phpunit.xml index f372de0..74fc105 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,9 +1,6 @@ - - - - ./src - + + @@ -23,4 +20,9 @@ + + + ./src + + diff --git a/tests/Feature/CheckInvitesTest.php b/tests/Feature/CheckInvitesTest.php index 3fe3460..b24a8af 100644 --- a/tests/Feature/CheckInvitesTest.php +++ b/tests/Feature/CheckInvitesTest.php @@ -13,18 +13,12 @@ class CheckInvitesTest extends TestCase { use DatabaseMigrations; - /** - * @test - */ - public function check_if_code_is_invalid() + public function test_can_check_if_code_is_invalid() { Assert::assertFalse(Doorman::check('NOPE')); } - /** - * @test - */ - public function check_if_maximum_uses_has_been_reached() + public function text_can_check_if_maximum_uses_has_been_reached() { Invite::forceCreate([ 'code' => 'ABCDE', @@ -35,10 +29,7 @@ public function check_if_maximum_uses_has_been_reached() Assert::assertFalse(Doorman::check('ABCDE')); } - /** - * @test - */ - public function check_if_code_has_expired() + public function test_can_check_if_code_has_expired() { Invite::forceCreate([ 'code' => 'ABCDE', @@ -48,10 +39,7 @@ public function check_if_code_has_expired() Assert::assertFalse(Doorman::check('ABCDE')); } - /** - * @test - */ - public function check_if_trying_to_use_a_code_belonging_to_someone_else() + public function test_can_check_if_trying_to_use_a_code_belonging_to_someone_else() { Invite::forceCreate([ 'code' => 'ABCDE', @@ -61,10 +49,7 @@ public function check_if_trying_to_use_a_code_belonging_to_someone_else() Assert::assertFalse(Doorman::check('ABCDE')); } - /** - * @test - */ - public function check_a_code_for_a_specific_user() + public function test_can_check_a_code_for_a_specific_user() { Invite::forceCreate([ 'code' => 'ABCDE', @@ -74,10 +59,7 @@ public function check_a_code_for_a_specific_user() Assert::assertTrue(Doorman::check('ABCDE', 'me@ashleyclarke.me')); } - /** - * @test - */ - public function a_unrestricted_invite_can_be_redeemed_when_email_is_provided() + public function test_can_a_unrestricted_invite_can_be_redeemed_when_email_is_provided() { Invite::forceCreate([ 'code' => 'ABCDE', @@ -86,10 +68,7 @@ public function a_unrestricted_invite_can_be_redeemed_when_email_is_provided() Assert::assertTrue(Doorman::check('ABCDE', 'me@ashleyclarke.me')); } - /** - * @test - */ - public function it_can_have_unlimited_redemptions() + public function test_can_it_can_have_unlimited_redemptions() { Invite::forceCreate([ 'code' => 'ABCDE', @@ -101,10 +80,7 @@ public function it_can_have_unlimited_redemptions() } } - /** - * @test - */ - public function it_is_not_case_sensitive() + public function test_it_is_not_case_sensitive() { Invite::forceCreate([ 'code' => 'ABCDE', diff --git a/tests/Feature/CustomModelTest.php b/tests/Feature/CustomModelTest.php index 3939821..528560c 100644 --- a/tests/Feature/CustomModelTest.php +++ b/tests/Feature/CustomModelTest.php @@ -17,10 +17,7 @@ protected function getEnvironmentSetUp($app) $app['config']->set('doorman.invite_model', MyCustomModel::class); } - /** - * @test - */ - public function it_can_use_a_custom_model() + public function test_it_can_use_a_custom_model() { $invites = Doorman::generate()->make(); diff --git a/tests/Feature/CustomValidationRuleTest.php b/tests/Feature/CustomValidationRuleTest.php index b62222b..568b427 100644 --- a/tests/Feature/CustomValidationRuleTest.php +++ b/tests/Feature/CustomValidationRuleTest.php @@ -14,10 +14,7 @@ class CustomValidationRuleTest extends TestCase { use DatabaseMigrations; - /** - * @test - */ - public function basic_validation() + public function test_basic_validation() { Invite::forceCreate([ 'code' => 'ABCDE', @@ -37,10 +34,7 @@ public function basic_validation() Assert::assertTrue($validator->passes()); } - /** - * @test - */ - public function validates_email_address() + public function test_validates_email_address() { Invite::forceCreate([ 'code' => 'ABCDE', @@ -62,10 +56,7 @@ public function validates_email_address() Assert::assertTrue($validator->passes()); } - /** - * @test - */ - public function it_provides_an_error_message() + public function test_it_provides_an_error_message() { Invite::forceCreate([ 'code' => 'ABCDE', diff --git a/tests/Feature/Drivers/BasicDriverTest.php b/tests/Feature/Drivers/BasicDriverTest.php index bbbcdaa..26c3c23 100644 --- a/tests/Feature/Drivers/BasicDriverTest.php +++ b/tests/Feature/Drivers/BasicDriverTest.php @@ -13,35 +13,23 @@ class BasicDriverTest extends TestCase { use DatabaseMigrations; - /** - * @test - */ - public function it_is_a_driver() + public function test_it_is_a_driver() { Assert::assertInstanceOf(DriverInterface::class, new BasicDriver); } - /** - * @test - */ - public function it_is_the_correct_driver() + public function test_it_is_the_correct_driver() { Assert::assertInstanceOf(BasicDriver::class, app(DoormanManager::class)->driver('basic')); } - /** - * @test - */ - public function it_is_the_default_driver() + public function test_it_is_the_default_driver() { Assert::assertSame('basic', config('doorman.driver')); Assert::assertSame('basic', app(DoormanManager::class)->getDefaultDriver()); } - /** - * @test - */ - public function it_has_a_default_length() + public function test_it_has_a_default_length() { Assert::assertSame(5, config('doorman.basic.length')); @@ -50,10 +38,7 @@ public function it_has_a_default_length() Assert::assertSame(5, strlen($driver->code())); } - /** - * @test - */ - public function it_allows_the_length_to_be_overridden() + public function test_it_allows_the_length_to_be_overridden() { Assert::assertSame(5, config('doorman.basic.length')); diff --git a/tests/Feature/Drivers/UuidDriverTest.php b/tests/Feature/Drivers/UuidDriverTest.php index a679fea..0417b69 100644 --- a/tests/Feature/Drivers/UuidDriverTest.php +++ b/tests/Feature/Drivers/UuidDriverTest.php @@ -16,24 +16,17 @@ class UuidDriverTest extends TestCase { use DatabaseMigrations; - /** - * @test - */ - public function it_is_a_driver() + public function test_it_is_a_driver() { Assert::assertInstanceOf(DriverInterface::class, new UuidDriver); } - /** - * @test - */ - public function it_is_the_correct_driver() + public function test_it_is_the_correct_driver() { Assert::assertInstanceOf(UuidDriver::class, app(DoormanManager::class)->driver('uuid')); } - /** @test */ - public function it_can_generate_a_version_1_uuid() + public function test_it_can_generate_a_version_1_uuid() { $this->app['config']['doorman.uuid.version'] = 1; @@ -45,10 +38,7 @@ public function it_can_generate_a_version_1_uuid() Assert::assertSame(1, Uuid::fromString($code)->getVersion()); } - /** - * @test - */ - public function it_throws_exception_if_invalid_version_supplied() + public function test_it_throws_exception_if_invalid_version_supplied() { $this->expectException(InvalidArgumentException::class); @@ -59,10 +49,7 @@ public function it_throws_exception_if_invalid_version_supplied() $driver->code(); } - /** - * @test - */ - public function namespace_is_required_for_version_3() + public function test_namespace_is_required_for_version_3() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Namespace must be set for uuid version 3'); @@ -75,10 +62,7 @@ public function namespace_is_required_for_version_3() $driver->code(); } - /** - * @test - */ - public function name_is_required_for_version_3() + public function test_name_is_required_for_version_3() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Name must be set for uuid version 3'); @@ -91,9 +75,7 @@ public function name_is_required_for_version_3() $driver->code(); } - - /** @test */ - public function it_can_generate_a_version_3_uuid() + public function test_it_can_generate_a_version_3_uuid() { $this->app['config']['doorman.uuid.version'] = 3; $this->app['config']['doorman.uuid.namespace'] = Uuid::NAMESPACE_DNS; @@ -107,8 +89,7 @@ public function it_can_generate_a_version_3_uuid() Assert::assertSame(3, Uuid::fromString($code)->getVersion()); } - /** @test */ - public function it_can_generate_a_version_4_uuid() + public function test_it_can_generate_a_version_4_uuid() { $this->app['config']['doorman.uuid.version'] = 4; @@ -120,10 +101,7 @@ public function it_can_generate_a_version_4_uuid() Assert::assertSame(4, Uuid::fromString($code)->getVersion()); } - /** - * @test - */ - public function namespace_is_required_for_version_5() + public function test_namespace_is_required_for_version_5() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Namespace must be set for uuid version 5'); @@ -136,10 +114,7 @@ public function namespace_is_required_for_version_5() $driver->code(); } - /** - * @test - */ - public function name_is_required_for_version_5() + public function test_name_is_required_for_version_5() { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Name must be set for uuid version 5'); @@ -152,9 +127,7 @@ public function name_is_required_for_version_5() $driver->code(); } - - /** @test */ - public function it_can_generate_a_version_5_uuid() + public function test_it_can_generate_a_version_5_uuid() { $this->app['config']['doorman.uuid.version'] = 5; $this->app['config']['doorman.uuid.namespace'] = Uuid::NAMESPACE_DNS; diff --git a/tests/Feature/GenerateInvitesTest.php b/tests/Feature/GenerateInvitesTest.php index d8f79f2..51b2b8e 100644 --- a/tests/Feature/GenerateInvitesTest.php +++ b/tests/Feature/GenerateInvitesTest.php @@ -15,30 +15,21 @@ class GenerateInvitesTest extends TestCase { use DatabaseMigrations; - /** - * @test - */ - public function it_will_generate_one_invite_by_default() + public function test_it_will_generate_one_invite_by_default() { Doorman::generate()->make(); Assert::assertCount(1, Invite::all()); } - /** - * @test - */ - public function it_can_generate_multiple_invites() + public function test_it_can_generate_multiple_invites() { Doorman::generate()->times(5)->make(); Assert::assertCount(5, Invite::all()); } - /** - * @test - */ - public function it_has_one_use_by_default() + public function test_it_has_one_use_by_default() { Doorman::generate()->make(); @@ -47,10 +38,7 @@ public function it_has_one_use_by_default() Assert::assertEquals(1, $invite->max); } - /** - * @test - */ - public function it_can_have_multiple_uses() + public function test_it_can_have_multiple_uses() { Doorman::generate()->uses(10)->make(); @@ -59,10 +47,7 @@ public function it_can_have_multiple_uses() Assert::assertEquals(10, $invite->max); } - /** - * @test - */ - public function it_can_have_an_expiry_date() + public function test_it_can_have_an_expiry_date() { $date = Carbon::now('UTC')->endOfDay(); @@ -73,10 +58,7 @@ public function it_can_have_an_expiry_date() Assert::assertLessThan(1, $date->floatDiffInSeconds($invite->valid_until)); } - /** - * @test - */ - public function it_can_accept_immutable_date() + public function test_it_can_accept_immutable_date() { $date = CarbonImmutable::now('UTC')->endOfDay(); @@ -87,10 +69,7 @@ public function it_can_accept_immutable_date() Assert::assertLessThan(1, $date->floatDiffInSeconds($invite->valid_until)); } - /** - * @test - */ - public function it_can_accept_vanilla_date() + public function test_it_can_accept_vanilla_date() { $date = (new \DateTime)->setTime(23, 59, 59); @@ -101,10 +80,7 @@ public function it_can_accept_vanilla_date() Assert::assertLessThan(1, $date->diff($invite->valid_until)->format('%s')); } - /** - * @test - */ - public function it_can_accept_vanilla_immutable_date() + public function test_it_can_accept_vanilla_immutable_date() { $date = (new \DateTimeImmutable)->setTime(23, 59, 59); @@ -115,10 +91,7 @@ public function it_can_accept_vanilla_immutable_date() Assert::assertLessThan(1, $date->diff($invite->valid_until)->format('%s')); } - /** - * @test - */ - public function it_has_helper_to_set_number_of_days_in_future_to_expire() + public function test_it_has_helper_to_set_number_of_days_in_future_to_expire() { Doorman::generate()->expiresIn(7)->make(); @@ -129,10 +102,7 @@ public function it_has_helper_to_set_number_of_days_in_future_to_expire() Assert::assertLessThan(1, $date->floatDiffInSeconds($invite->valid_until)); } - /** - * @test - */ - public function it_can_be_valid_for_a_single_email() + public function test_it_can_be_valid_for_a_single_email() { Doorman::generate()->for('me@ashleyclarke.me')->make(); @@ -141,10 +111,7 @@ public function it_can_be_valid_for_a_single_email() Assert::assertEquals('me@ashleyclarke.me', $invite->for); } - /** - * @test - */ - public function only_one_invite_per_email_can_be_generated_1() + public function test_only_one_invite_per_email_can_be_generated_1() { $this->expectException(DuplicateException::class); @@ -152,20 +119,14 @@ public function only_one_invite_per_email_can_be_generated_1() Doorman::generate()->for('me@ashleyclarke.me')->make(); } - /** - * @test - */ - public function only_one_invite_per_email_can_be_generated_2() + public function test_only_one_invite_per_email_can_be_generated_2() { $this->expectException(DuplicateException::class); Doorman::generate()->for('me@ashleyclarke.me')->times(3)->make(); } - /** - * @test - */ - public function generated_codes_should_always_be_uppercase() + public function test_generated_codes_should_always_be_uppercase() { Doorman::generate()->make(); @@ -174,20 +135,14 @@ public function generated_codes_should_always_be_uppercase() Assert::assertEquals(strtoupper($invite->code), $invite->code); } - /** - * @test - */ - public function it_will_generate_an_invite_only_once() + public function test_it_will_generate_an_invite_only_once() { $invite = Doorman::generate()->once(); Assert::assertInstanceOf(Invite::class, $invite); } - /** - * @test - */ - public function it_will_generate_an_invite_with_unlimited_redemptions() + public function test_it_will_generate_an_invite_with_unlimited_redemptions() { $invite = Doorman::generate()->unlimited()->once(); diff --git a/tests/Feature/InviteHelperTest.php b/tests/Feature/InviteHelperTest.php index 963aa45..426a2ce 100644 --- a/tests/Feature/InviteHelperTest.php +++ b/tests/Feature/InviteHelperTest.php @@ -12,10 +12,7 @@ class InviteHelperTest extends TestCase { use DatabaseMigrations; - /** - * @test - */ - public function check_if_it_has_expired() + public function test_can_check_if_it_has_expired() { /** @var Invite $one */ $one = Invite::forceCreate([ @@ -41,10 +38,7 @@ public function check_if_it_has_expired() Assert::assertTrue($three->hasExpired()); } - /** - * @test - */ - public function check_if_it_is_full() + public function test_can_check_if_it_is_full() { /** @var Invite $one */ $one = Invite::forceCreate([ @@ -74,10 +68,7 @@ public function check_if_it_is_full() Assert::assertTrue($three->isFull()); } - /** - * @test - */ - public function check_if_it_is_restricted() + public function test_can_check_if_it_is_restricted() { /** @var Invite $one */ $one = Invite::forceCreate([ @@ -95,10 +86,7 @@ public function check_if_it_is_restricted() Assert::assertTrue($two->isRestricted()); } - /** - * @test - */ - public function check_if_it_is_restricted_for_a_particular_person() + public function test_can_check_if_it_is_restricted_for_a_particular_person() { /** @var Invite $one */ $one = Invite::forceCreate([ @@ -116,10 +104,7 @@ public function check_if_it_is_restricted_for_a_particular_person() Assert::assertTrue($two->isRestrictedFor('user@example.com')); } - /** - * @test - */ - public function check_if_it_is_useless() + public function test_can_check_if_it_is_useless() { /** @var Invite $one */ $one = Invite::forceCreate([ @@ -156,10 +141,7 @@ public function check_if_it_is_useless() Assert::assertTrue($four->isUseless()); } - /** - * @test - */ - public function expired_scope() + public function test_expired_scope() { Invite::forceCreate([ 'code' => 'ONE' @@ -178,10 +160,7 @@ public function expired_scope() Assert::assertEquals(1, Invite::expired()->count()); } - /** - * @test - */ - public function full_scope() + public function test_full_scope() { Invite::forceCreate([ 'code' => 'ONE', @@ -204,10 +183,7 @@ public function full_scope() Assert::assertEquals(1, Invite::full()->count()); } - /** - * @test - */ - public function useless_scope() + public function test_useless_scope() { Invite::forceCreate([ 'code' => 'ONE' diff --git a/tests/Feature/RedeemInvitesTest.php b/tests/Feature/RedeemInvitesTest.php index 4e667b5..838a257 100644 --- a/tests/Feature/RedeemInvitesTest.php +++ b/tests/Feature/RedeemInvitesTest.php @@ -17,10 +17,7 @@ class RedeemInvitesTest extends TestCase { use DatabaseMigrations; - /** - * @test - */ - public function it_squawks_if_code_is_invalid() + public function test_it_squawks_if_code_is_invalid() { $this->expectException(InvalidInviteCode::class); $this->expectExceptionMessage('The invite code NOPE is invalid.'); @@ -28,10 +25,7 @@ public function it_squawks_if_code_is_invalid() Doorman::redeem('NOPE'); } - /** - * @test - */ - public function it_increments_uses_if_valid_code() + public function test_it_increments_uses_if_valid_code() { Invite::forceCreate([ 'code' => 'ABCDE', @@ -47,10 +41,7 @@ public function it_increments_uses_if_valid_code() Assert::assertEquals(2, $invite->uses); } - /** - * @test - */ - public function it_squawks_if_maximum_uses_has_been_reached() + public function test_it_squawks_if_maximum_uses_has_been_reached() { $this->expectException(MaxUsesReached::class); $this->expectExceptionMessage('The invite code ABCDE has already been used the maximum number of times.'); @@ -64,10 +55,7 @@ public function it_squawks_if_maximum_uses_has_been_reached() Doorman::redeem('ABCDE'); } - /** - * @test - */ - public function it_squawks_if_code_has_expired() + public function test_it_squawks_if_code_has_expired() { $this->expectException(ExpiredInviteCode::class); $this->expectExceptionMessage('The invite code ABCDE has expired.'); @@ -80,10 +68,7 @@ public function it_squawks_if_code_has_expired() Doorman::redeem('ABCDE'); } - /** - * @test - */ - public function it_squawks_if_trying_to_use_a_code_belonging_to_someone_else() + public function test_it_squawks_if_trying_to_use_a_code_belonging_to_someone_else() { $this->expectException(NotYourInviteCode::class); $this->expectExceptionMessage('The invite code ABCDE belongs to another user.'); @@ -96,10 +81,7 @@ public function it_squawks_if_trying_to_use_a_code_belonging_to_someone_else() Doorman::redeem('ABCDE'); } - /** - * @test - */ - public function it_can_redeem_a_code_for_a_specific_user() + public function test_it_can_redeem_a_code_for_a_specific_user() { Invite::forceCreate([ 'code' => 'ABCDE', @@ -113,10 +95,7 @@ public function it_can_redeem_a_code_for_a_specific_user() Assert::assertEquals(1, $invite->uses); } - /** - * @test - */ - public function email_address_is_case_insensitive_1() + public function test_email_address_is_case_insensitive_1() { Invite::forceCreate([ 'code' => 'ABCDE', @@ -130,10 +109,7 @@ public function email_address_is_case_insensitive_1() Assert::assertEquals(1, $invite->uses); } - /** - * @test - */ - public function email_address_is_case_insensitive_2() + public function test_email_address_is_case_insensitive_2() { Invite::forceCreate([ 'code' => 'ABCDE', @@ -147,10 +123,7 @@ public function email_address_is_case_insensitive_2() Assert::assertEquals(1, $invite->uses); } - /** - * @test - */ - public function a_unrestricted_invite_can_be_redeemed_when_email_is_provided() + public function test_a_unrestricted_invite_can_be_redeemed_when_email_is_provided() { Invite::forceCreate([ 'code' => 'ABCDE', @@ -163,10 +136,7 @@ public function a_unrestricted_invite_can_be_redeemed_when_email_is_provided() Assert::assertEquals(1, $invite->uses); } - /** - * @test - */ - public function it_can_have_unlimited_redemptions() + public function test_it_can_have_unlimited_redemptions() { Invite::forceCreate([ 'code' => 'ABCDE', diff --git a/tests/Unit/CleanupCommandTest.php b/tests/Unit/CleanupCommandTest.php index e9f2213..a2def76 100644 --- a/tests/Unit/CleanupCommandTest.php +++ b/tests/Unit/CleanupCommandTest.php @@ -13,10 +13,7 @@ class CleanupCommandTest extends TestCase { use DatabaseMigrations; - /** - * @test - */ - public function it_deletes_wasted_invites() + public function test_it_deletes_wasted_invites() { Assert::assertCount(0, Invite::all()); @@ -39,7 +36,7 @@ public function it_deletes_wasted_invites() Assert::assertCount(1, Invite::all()); } - public function it_deletes_expired_invites() + public function test_it_deletes_expired_invites() { Assert::assertCount(0, Invite::all()); diff --git a/tests/Unit/DoormanTest.php b/tests/Unit/DoormanTest.php index 1acea7e..201def9 100644 --- a/tests/Unit/DoormanTest.php +++ b/tests/Unit/DoormanTest.php @@ -9,10 +9,7 @@ class DoormanTest extends TestCase { - /** - * @test - */ - public function it_provides_a_generator() + public function test_it_provides_a_generator() { $generator = Doorman::generate();