Skip to content

Commit

Permalink
PHPUnit -> Pest
Browse files Browse the repository at this point in the history
  • Loading branch information
warrickbayman committed Feb 28, 2024
1 parent 5e8b829 commit 012f715
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 48 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
php: [7.3, 7.4, 8.0]
php: [8.2, 8.3]

steps:
- name: Checkout
Expand All @@ -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
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -45,5 +46,10 @@
"Deadbolt": "TPG\\Deadbolt\\Facades\\Deadbolt"
}
}
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
27 changes: 27 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./src</directory>
</include>
</source>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="MAIL_DRIVER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="DB_CONNECTION" value="testing"/>
<server name="APP_KEY" value="base64:CTh/NL1V6ZtBL/trNlpV3toG1+1HRY1AqdvsuECL/aw="/>
</php>
</phpunit>
23 changes: 0 additions & 23 deletions phpunit.xml.dist

This file was deleted.

11 changes: 3 additions & 8 deletions src/Contracts/UserCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,19 @@ public function save(): UserCollectionInterface;
*
* @param array<string> $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<string> $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<string> $permissions
*/
public function noneHave(...$permissions): bool;
public function dontHave(...$permissions): bool;
}
11 changes: 3 additions & 8 deletions src/UserCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected function callOnEachUser(string $name, mixed $arguments = null): UserCo
*
* @param array<string> $permissions
*/
public function allHave(...$permissions): bool
public function have(...$permissions): bool
{
foreach ($this->users as $user) {
if (! $user->hasAll($permissions)) {
Expand All @@ -121,7 +121,7 @@ public function allHave(...$permissions): bool
*
* @param array<string> $permissions
*/
public function anyHave(...$permissions): bool
public function any(...$permissions): bool
{
foreach ($this->users as $user) {
if ($user->hasAll($permissions)) {
Expand All @@ -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)) {
Expand Down
7 changes: 3 additions & 4 deletions tests/PermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "uses()" function to bind a different classes or traits.
|
*/

use TPG\Deadbolt\Tests\Models\User;

uses(\TPG\Deadbolt\Tests\TestCase::class)->in('*');
4 changes: 2 additions & 2 deletions tests/RelationshipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

0 comments on commit 012f715

Please sign in to comment.