Skip to content

Commit

Permalink
Working
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephSilber committed Mar 14, 2024
1 parent e932256 commit e05734b
Show file tree
Hide file tree
Showing 40 changed files with 1,025 additions and 1,551 deletions.
48 changes: 3 additions & 45 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,53 +18,11 @@ jobs:
strategy:
fail-fast: false
matrix:
laravel: [11.*]
php: [8.3]
laravel: [10.*, 11.*]
php: [8.1, 8.2, 8.3]
exclude:

- laravel: 11.*
php: 7.2
- laravel: 11.*
php: 7.3
- laravel: 11.*
php: 8.0
- laravel: 11.*
php: 8.1

- laravel: 10.*
php: 7.2
- laravel: 10.*
php: 7.3
- laravel: 10.*
php: 8.0

- laravel: 9.*
php: 7.2
- laravel: 9.*
php: 7.3
- laravel: 9.*
php: 8.3

- laravel: 8.*
php: 7.2
- laravel: 8.*
php: 8.2
- laravel: 8.*
php: 8.3

- laravel: 7.*
php: 8.1
- laravel: 7.*
php: 8.2
- laravel: 7.*
php: 8.3

- laravel: 6.*
php: 8.1
- laravel: 6.*
php: 8.2
- laravel: 6.*
php: 8.3

name: Laravel ${{ matrix.laravel }}, PHP ${{ matrix.php }}

Expand All @@ -80,7 +38,7 @@ jobs:

- name: Install dependencies
run: |
composer require "illuminate/auth:${{ matrix.laravel }}" "illuminate/cache:${{ matrix.laravel }}" "illuminate/container:${{ matrix.laravel }}" "illuminate/contracts:${{ matrix.laravel }}" "illuminate/database:${{ matrix.laravel }}" "illuminate/console:${{ matrix.laravel }}" "illuminate/events:${{ matrix.laravel }}" --no-interaction --no-update
composer require --dev "illuminate/auth:${{ matrix.laravel }}" "illuminate/cache:${{ matrix.laravel }}" "illuminate/container:${{ matrix.laravel }}" "illuminate/contracts:${{ matrix.laravel }}" "illuminate/database:${{ matrix.laravel }}" "illuminate/console:${{ matrix.laravel }}" "illuminate/events:${{ matrix.laravel }}" --no-interaction --no-update
composer update --prefer-stable --prefer-dist --no-interaction --no-suggest
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions .phpunit.cache/test-results

Large diffs are not rendered by default.

50 changes: 32 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,47 @@
},
"autoload-dev": {
"psr-4": {
"Silber\\Bouncer\\Tests\\": "tests/"
},
"files": [
"tests/helpers.php"
]
"Silber\\Bouncer\\Tests\\": "tests/",
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
}
},
"require": {
"php": "^7.2|^8.0",
"illuminate/auth": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/cache": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/container": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/contracts": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/database": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"larapack/dd": "^1.1"
"php": "^8.1|^8.2|^8.3",
"illuminate/auth": "^10.0|^11.0",
"illuminate/cache": "^10.0|^11.0",
"illuminate/container": "^10.0|^11.0",
"illuminate/contracts": "^10.0|^11.0",
"illuminate/database": "^10.0|^11.0"
},
"require-dev": {
"illuminate/console": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/events": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"mockery/mockery": "^1.3.3",
"phpunit/phpunit": "^8.0|^9.0"
"illuminate/console": "^10.0|^11.0",
"illuminate/events": "^10.0|^11.0",
"phpunit/phpunit": "^9.0|^10.0|^11.0",
"orchestra/testbench": "^8.0|^9.0"
},
"suggest": {
"illuminate/console": "Allows running the bouncer:clean artisan command",
"illuminate/events": "Required for multi-tenancy support"
},
"scripts": {
"test": "phpunit"
"test": "phpunit",
"post-autoload-dump": [
"@clear",
"@prepare"
],
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"serve": [
"Composer\\Config::disableProcessTimeout",
"@build",
"@php vendor/bin/testbench serve"
],
"lint": [
"@php vendor/bin/phpstan analyse"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand All @@ -64,4 +78,4 @@
}
}
}
}
}
4 changes: 2 additions & 2 deletions migrations/create_bouncer_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateBouncerTables extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -90,4 +90,4 @@ public function down()
Schema::drop(Models::table('roles'));
Schema::drop(Models::table('abilities'));
}
}
};
24 changes: 9 additions & 15 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<php>
<env name="DB_CONNECTION" value="testing"/>
</php>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
81 changes: 33 additions & 48 deletions tests/AbilitiesForModelsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

namespace Silber\Bouncer\Tests;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\DataProvider;

use Silber\Bouncer\Database\Ability;
use Illuminate\Database\Eloquent\Model;
use Workbench\App\Models\User;
use Workbench\App\Models\Account;

class AbilitiesForModelsTest extends BaseTestCase
{
use Concerns\TestsClipboards;

/**
* @test
* @dataProvider bouncerProvider
*/
function model_blanket_ability($provider)
#[Test]
#[DataProvider('bouncerProvider')]
public function model_blanket_ability($provider)
{
list($bouncer, $user1, $user2) = $provider(2);
[$bouncer, $user1, $user2] = $provider(2);

$bouncer->allow($user1)->to('edit', User::class);

Expand All @@ -36,13 +39,11 @@ function model_blanket_ability($provider)
$this->assertTrue($bouncer->cannot('edit', $user2));
}

/**
* @test
* @dataProvider bouncerProvider
*/
function individual_model_ability($provider)
#[Test]
#[DataProvider('bouncerProvider')]
public function individual_model_ability($provider)
{
list($bouncer, $user1, $user2) = $provider(2);
[$bouncer, $user1, $user2] = $provider(2);

$bouncer->allow($user1)->to('edit', $user2);

Expand All @@ -67,13 +68,11 @@ function individual_model_ability($provider)
$this->assertTrue($bouncer->cannot('edit', $user2));
}

/**
* @test
* @dataProvider bouncerProvider
*/
function blanket_ability_and_individual_model_ability_are_kept_separate($provider)
#[Test]
#[DataProvider('bouncerProvider')]
public function blanket_ability_and_individual_model_ability_are_kept_separate($provider)
{
list($bouncer, $user1, $user2) = $provider(2);
[$bouncer, $user1, $user2] = $provider(2);

$bouncer->allow($user1)->to('edit', User::class);
$bouncer->allow($user1)->to('edit', $user2);
Expand All @@ -87,23 +86,19 @@ function blanket_ability_and_individual_model_ability_are_kept_separate($provide
$this->assertTrue($bouncer->can('edit', $user2));
}

/**
* @test
* @dataProvider bouncerProvider
*/
function allowing_on_non_existent_model_throws($provider)
#[Test]
#[DataProvider('bouncerProvider')]
public function allowing_on_non_existent_model_throws($provider)
{
$this->expectException('InvalidArgumentException');

list($bouncer, $user) = $provider();
[$bouncer, $user] = $provider();

$bouncer->allow($user)->to('delete', new User);
}

/**
* @test
*/
function can_create_an_ability_for_a_model()
#[Test]
public function can_create_an_ability_for_a_model()
{
$ability = Ability::createForModel(Account::class, 'delete');

Expand All @@ -112,10 +107,8 @@ function can_create_an_ability_for_a_model()
$this->assertNull($ability->entity_id);
}

/**
* @test
*/
function can_create_an_ability_for_a_model_plus_extra_attributes()
#[Test]
public function can_create_an_ability_for_a_model_plus_extra_attributes()
{
$ability = Ability::createForModel(Account::class, [
'name' => 'delete',
Expand All @@ -128,10 +121,8 @@ function can_create_an_ability_for_a_model_plus_extra_attributes()
$this->assertNull($ability->entity_id);
}

/**
* @test
*/
function can_create_an_ability_for_a_model_instance()
#[Test]
public function can_create_an_ability_for_a_model_instance()
{
$user = User::create();

Expand All @@ -142,10 +133,8 @@ function can_create_an_ability_for_a_model_instance()
$this->assertEquals('delete', $ability->name);
}

/**
* @test
*/
function can_create_an_ability_for_a_model_instance_plus_extra_attributes()
#[Test]
public function can_create_an_ability_for_a_model_instance_plus_extra_attributes()
{
$user = User::create();

Expand All @@ -160,10 +149,8 @@ function can_create_an_ability_for_a_model_instance_plus_extra_attributes()
$this->assertEquals('delete', $ability->name);
}

/**
* @test
*/
function can_create_an_ability_for_all_models()
#[Test]
public function can_create_an_ability_for_all_models()
{
$ability = Ability::createForModel('*', 'delete');

Expand All @@ -172,10 +159,8 @@ function can_create_an_ability_for_all_models()
$this->assertNull($ability->entity_id);
}

/**
* @test
*/
function can_create_an_ability_for_all_models_plus_extra_attributes()
#[Test]
public function can_create_an_ability_for_all_models_plus_extra_attributes()
{
$ability = Ability::createForModel('*', [
'name' => 'delete',
Expand Down
23 changes: 11 additions & 12 deletions tests/AbilityConstraintsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@

namespace Silber\Bouncer\Tests;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\DataProvider;

use Silber\Bouncer\Database\Ability;
use Silber\Bouncer\Constraints\Group;
use Silber\Bouncer\Constraints\Constraint;
use Workbench\App\Models\User;
use Workbench\App\Models\Account;

class AbilityConstraintsTest extends BaseTestCase
{
/**
* @test
*/
function can_get_empty_constraints()
#[Test]
public function can_get_empty_constraints()
{
$group = Ability::createForModel(Account::class, '*')->getConstraints();

$this->assertInstanceOf(Group::class, $group);
}

/**
* @test
*/
function can_check_if_has_constraints()
#[Test]
public function can_check_if_has_constraints()
{
$empty = Ability::makeForModel(Account::class, '*');

Expand All @@ -33,10 +34,8 @@ function can_check_if_has_constraints()
$this->assertTrue($full->hasConstraints());
}

/**
* @test
*/
function can_set_and_get_constraints()
#[Test]
public function can_set_and_get_constraints()
{
$ability = Ability::makeForModel(Account::class, '*')->setConstraints(
new Group([
Expand Down
Loading

0 comments on commit e05734b

Please sign in to comment.