diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 296a458..b21e686 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - php: [7.3, 7.4, 8.0] + php: [8.2, 8.3] steps: - name: Checkout @@ -35,7 +35,7 @@ jobs: run: yarn build - name: Run PHP tests - run: vendor/bin/phpunit + run: vendor/bin/pest - name: Rust JS tests run: yarn test diff --git a/composer.json b/composer.json index d697110..acb2af0 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "require-dev": { "orchestra/testbench": "^8.0", "phpunit/phpunit": "^10.0", - "roave/security-advisories": "dev-master" + "pestphp/pest": "^2.31", + "roave/security-advisories": "dev-latest" }, "minimum-stability": "dev", "prefer-stable": true, @@ -45,5 +46,10 @@ "Deadbolt": "TPG\\Deadbolt\\Facades\\Deadbolt" } } + }, + "config": { + "allow-plugins": { + "pestphp/pest-plugin": true + } } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..e1fb237 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,27 @@ + + + + + ./tests + + + + + ./src + + + + + + + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 448ee2a..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,23 +0,0 @@ - - - - - tests/ - - - - - - - - - - - - - - - src/ - - - diff --git a/src/Contracts/UserCollectionInterface.php b/src/Contracts/UserCollectionInterface.php index f2f63c1..13864be 100644 --- a/src/Contracts/UserCollectionInterface.php +++ b/src/Contracts/UserCollectionInterface.php @@ -54,24 +54,19 @@ public function save(): UserCollectionInterface; * * @param array $permissions */ - public function allHave(...$permissions): bool; + public function have(...$permissions): bool; /** * Check if all the users have at least one of the specified permissions. * * @param array $permissions */ - public function anyHave(...$permissions): bool; - - /** - * Check if all the users have the specified permissions. - */ - public function has(string $permission): bool; + public function any(...$permissions): bool; /** * Check if all the users have none of the specified permissions. * * @param array $permissions */ - public function noneHave(...$permissions): bool; + public function dontHave(...$permissions): bool; } diff --git a/src/UserCollection.php b/src/UserCollection.php index 09dd43d..8eaea91 100644 --- a/src/UserCollection.php +++ b/src/UserCollection.php @@ -105,7 +105,7 @@ protected function callOnEachUser(string $name, mixed $arguments = null): UserCo * * @param array $permissions */ - public function allHave(...$permissions): bool + public function have(...$permissions): bool { foreach ($this->users as $user) { if (! $user->hasAll($permissions)) { @@ -121,7 +121,7 @@ public function allHave(...$permissions): bool * * @param array $permissions */ - public function anyHave(...$permissions): bool + public function any(...$permissions): bool { foreach ($this->users as $user) { if ($user->hasAll($permissions)) { @@ -132,18 +132,13 @@ public function anyHave(...$permissions): bool return false; } - public function has(string $permission): bool - { - return $this->anyHave($permission); - } - /** * Check if none of the users have the specified permissions. * * @param ...$permissions * @return bool */ - public function noneHave(...$permissions): bool + public function dontHave(...$permissions): bool { foreach ($this->users as $user) { if ($user->hasAny($permissions)) { diff --git a/tests/PermissionTest.php b/tests/PermissionTest.php index 91e42bd..0c2172d 100644 --- a/tests/PermissionTest.php +++ b/tests/PermissionTest.php @@ -183,10 +183,9 @@ public function it_can_assign_permissioins_to_multiple_users(): void self::assertTrue(Deadbolt::user($users[0])->has('articles.create')); self::assertTrue(Deadbolt::user($users[1])->has('articles.create')); - self::assertTrue(Deadbolt::users($users)->has('articles.create')); - self::assertTrue(Deadbolt::users($users)->allHave('articles.create')); - self::assertFalse(Deadbolt::users($users)->allHave('articles.edit')); - self::assertTrue(Deadbolt::users($users)->anyHave('articles.create')); + self::assertTrue(Deadbolt::users($users)->have('articles.create')); + self::assertFalse(Deadbolt::users($users)->have('articles.edit')); + self::assertTrue(Deadbolt::users($users)->any('articles.create')); } /** diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..ef59c36 --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,16 @@ +in('*'); diff --git a/tests/RelationshipTest.php b/tests/RelationshipTest.php index d48a95a..9447fc2 100644 --- a/tests/RelationshipTest.php +++ b/tests/RelationshipTest.php @@ -48,7 +48,7 @@ public function it_can_test_related_roles(): void $user->load('roles'); - $this->assertTrue(Deadbolt::users($user->roles)->anyHave('articles.edit')); - $this->assertFalse(Deadbolt::users($user->roles)->allHave('articles.delete')); + $this->assertTrue(Deadbolt::users($user->roles)->any('articles.edit')); + $this->assertFalse(Deadbolt::users($user->roles)->have('articles.delete')); } }