PHPackages                             wubbleyou/laravel-access-control-checker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. wubbleyou/laravel-access-control-checker

ActiveLibrary[Testing &amp; Quality](/categories/testing)

wubbleyou/laravel-access-control-checker
========================================

Automatic test generation for validating route middleware and policy boundaries

v0.0.2(2y ago)07MITPHP

Since Apr 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Wubbleyou/laravel-access-control-checker)[ Packagist](https://packagist.org/packages/wubbleyou/laravel-access-control-checker)[ RSS](/packages/wubbleyou-laravel-access-control-checker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Wubbleyou Boundaries
====================

[](#wubbleyou-boundaries)

Boundaries is a DX tool used to generate unit tests to automatically test your routes against developer-determined rules.

Two rules are provided with out of the box with Boundaries, a `MiddlewareRule` and a `PolicyRule`

Installation
------------

[](#installation)

Install the package normally via Composer

```
composer require wubbleyou/boundaries

```

Usage
-----

[](#usage)

To get started you'll need to run the following command to generate the base test file:

```
php/sail artisan wubbleyou:generate-test

```

Configuration
-------------

[](#configuration)

Now you've got your test generated and saved in `tests\Feature\Boundaries\BoundaryTest.php` you might notice a trait has been placed in `app\Traits\BoundaryRouteTrait.php` which contains 2 methods, please read the additional information at the bottom to understand why you need to supply these.

### getWhitelist()

[](#getwhitelist)

The `getWhitelist()` method allows you to return an array of all the routes you want to be ignored by Wubbleyou\\Boundaries.

```
return [
    'login',
    'register',
    'homepage',
    'about',
];

```

### getRoutes()

[](#getroutes)

The `getRoutes()` method allows you to return an array to specify the exact assertions that should be ran on each route, here's an example:

```
$admin = User::factory()->create(['is_admin', true]);
$userOne = User::factory()->create();
$userTwo = User::factory()->create();

return [
    'users.change-password' => [
        new MiddlewareRule(['web', 'auth', 'incorrect']),
        new PolicyRule('get', 403, $userOne, ['user' => $userTwo]),
    ]
];

```

#### MiddlewareRule

[](#middlewarerule)

The middleware rule tests your route against a certain set of middleware, if it doesn't match all of these middleware the test will fail.

MiddlewareRule also has an optional second parameter for `$strict` (default: `false`). If strict is enabled the supplied array of expected middleware must match exactly to the middleware present on the route. If strict is not enabled the middleware present on the route must contain all the expected middleware but can also contain other middleware we're not testing for.

```
new MiddlewareRule(['web', 'auth'], true),

```

#### PolicyRule

[](#policyrule)

The policy rule performs a test against a specific route to test the HTTP status code. You supply it with:

- The request type (get/post/etc)
- The expected HTTP status code response (200, 404, 403, etc)
- A user to test the route as (this can be set to NULL to test unauthenticated) (default: null)
- Parameters the route expects (optional) (default: \[\])

And it will test that route and return an error if the response code doesn't match the one you've supplied.

#### Custom BoundaryRules

[](#custom-boundaryrules)

You can also generate custom BoundaryRules using the following command:

```
php/sail artisan wubbleyou:generate-rule RuleName

```

An example BoundaryRule would look like:

```
