Skip to content

Commit

Permalink
Add github actions
Browse files Browse the repository at this point in the history
Signed-off-by: Iman Ghafoori <imanghafoori1@gmail.com>
  • Loading branch information
imanghafoori1 committed Dec 13, 2023
1 parent c8d59d4 commit 79d9866
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 114 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Expand Up @@ -12,3 +12,4 @@
/.scrutinizer.yml export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.github export-ignore
36 changes: 36 additions & 0 deletions .github/workflows/imports.yml
@@ -0,0 +1,36 @@
name: Check Imports

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Check Imports
run: ./vendor/bin/check_imports
71 changes: 71 additions & 0 deletions .github/workflows/tests.yml
@@ -0,0 +1,71 @@
name: tests

# Controls when the workflow will run
on:
push:
branches: [master]
pull_request:
branches: [master]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
test:
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3]
laravel: [^6.0, ^7.0, ^8.0, ^9.0, ^10.0]
exclude:
- php: 7.2
laravel: ^8.0
- php: 7.2
laravel: ^9.0
- php: 7.2
laravel: ^10.0
- php: 7.3
laravel: ^9.0
- php: 7.3
laravel: ^10.0
- php: 7.4
laravel: ^9.0
- php: 7.4
laravel: ^10.0
- php: 8.0
laravel: ^10.0
- php: 8.1
laravel: ^6.0
- php: 8.1
laravel: ^7.0
- php: 8.2
laravel: ^7.0
- php: 8.2
laravel: ^6.0
- php: 8.3
laravel: ^7.0
- php: 8.3
laravel: ^6.0

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

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, exif, iconv, tokenizer
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework=${{ matrix.laravel }}" --no-update
composer update --prefer-dist --no-interaction --no-progress
- name: Execute tests
run: ./vendor/bin/phpunit
3 changes: 1 addition & 2 deletions .styleci.yml
@@ -1,2 +1 @@
php:
preset: laravel
preset: laravel
11 changes: 6 additions & 5 deletions README.md
Expand Up @@ -9,7 +9,8 @@
<a href="https://scrutinizer-ci.com/g/imanghafoori1/laravel-heyman"><img src="https://img.shields.io/scrutinizer/g/imanghafoori1/laravel-heyman.svg?style=round-square" alt="Quality Score"></img></a>
[![code coverage](https://codecov.io/gh/imanghafoori1/laravel-heyman/branch/master/graph/badge.svg)](https://codecov.io/gh/imanghafoori1/laravel-heyman)
[![Maintainability](https://api.codeclimate.com/v1/badges/9d6be7b057103cb14410/maintainability)](https://codeclimate.com/github/imanghafoori1/laravel-heyman/maintainability)
[![Build Status](https://travis-ci.org/imanghafoori1/laravel-heyman.svg?branch=master)](https://travis-ci.org/imanghafoori1/laravel-heyman)
[![Imports](https://github.com/imanghafoori1/laravel-heyman/actions/workflows/imports.yml/badge.svg?branch=master)](https://github.com/imanghafoori1/laravel-heyman/actions/workflows/imports.yml)
[![Test](https://github.com/imanghafoori1/laravel-heyman/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/imanghafoori1/laravel-heyman/actions/workflows/tests.yml)
[![StyleCI](https://github.styleci.io/repos/139709518/shield?branch=master)](https://github.styleci.io/repos/139709518)
[![Latest Stable Version](https://poser.pugx.org/imanghafoori/laravel-heyman/v/stable)](https://packagist.org/packages/imanghafoori/laravel-heyman)
[![Daily Downloads](https://poser.pugx.org/imanghafoori/laravel-heyman/d/daily)](https://packagist.org/packages/imanghafoori/laravel-heyman)
Expand All @@ -24,9 +25,9 @@

#### Built with :heart: for every smart laravel developer

Very well tested, optimized and production ready!
Very well-tested, optimized, and production-ready!

In fact, We have tackled a lot of `complexity` behind the scenes, to provide you with a lot of `simplicity`.
We have tackled a lot of `complexity` behind the scenes, to provide you with a lot of `simplicity`.

- Integrated with laravel-debugbar package out of the box: <a href="https://github.com/barryvdh/laravel-debugbar">laravel debugbar</a>

Expand Down Expand Up @@ -148,7 +149,7 @@ You are telling the framework what to do in certain situations rather than getti
> — Alec Sharp `

3- This approach is paticularly useful when you for example write a package which needs ACL but you want to allow your package users to override and apply they own ACL (or validation) rules into your package routes...
3- This approach is particularly useful when you for example write a package which needs ACL but you want to allow your package users to override and apply they own ACL (or validation) rules into your package routes...

And that becomes possible when you use laravel-HeyMan for ACL. The users can easily cancel out the default rules and re-write their favorite acl or validation stuff in a regular ServiceProviders.

Expand Down Expand Up @@ -355,7 +356,7 @@ HeyMan::whenYouHitRouteName('welcome.name')

#### 5- Check points:

You can also declare some check points some where, within your application code:
You can also declare some check points somewhere, within your application code:

```php

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -15,11 +15,10 @@
"laravel/framework":"~5.1|6.*|7.*|8.*|9.*|10.*"
},
"require-dev": {
"orchestra/testbench": "~3.0|~4.0|~5.0|~6.0|~7.0",
"orchestra/testbench": ">=3.0",
"barryvdh/laravel-debugbar": "^2.3|3.*|4.*",
"imanghafoori/laravel-makesure": "^1.0",
"imanghafoori/php-imports-analyzer": "^1.0.2",
"orchestra/database": "@dev",
"mockery/mockery": "^1.0"
},
"autoload": {
Expand All @@ -43,7 +42,8 @@
"imanghafoori/laravel-terminator": "Gives you opportunity to refactor your controllers."
},
"scripts": {
"test": "./vendor/bin/phpunit"
"test": "./vendor/bin/phpunit",
"imports": "./vendor/bin/check_imports"
},
"extra": {
"laravel": {
Expand Down
48 changes: 16 additions & 32 deletions phpunit.xml.dist
@@ -1,39 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>

<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
</php>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<filter>

<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>



</filter>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
</php>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
4 changes: 3 additions & 1 deletion tests/EventsAuthorizationTest.php
Expand Up @@ -3,6 +3,7 @@
namespace Imanghafoori\HeyManTests;

use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Route;
use Imanghafoori\HeyMan\Facades\HeyMan;
use Imanghafoori\HeyMan\Plugins\WatchingStrategies\Events\EventSituationProvider;
Expand Down Expand Up @@ -118,7 +119,8 @@ public function testCheckPoints()

public function test_checkPoint()
{
$this->expectsEvents('heyman_checkpoint_wow');
Event::fake();
HeyMan::checkPoint('wow');
Event::assertDispatched('heyman_checkpoint_wow');
}
}
27 changes: 14 additions & 13 deletions tests/IgnoreTest.php
Expand Up @@ -5,13 +5,14 @@
use Illuminate\Support\Facades\Route;
use Imanghafoori\HeyMan\Facades\HeyMan;
use Imanghafoori\HeyMan\StartGuarding;
use Imanghafoori\HeyManTests\Stubs\HomeController;
use Imanghafoori\MakeSure\Facades\MakeSure;

class IgnoreTest extends TestCase
{
public function testUrlIsAuthorized()
{
Route::get('/welcome', 'HomeController@index');
Route::get('/welcome', HomeController::class.'@index');

HeyMan::whenYouVisitUrl('/welco*')->always()->weDenyAccess();
HeyMan::whenYouVisitUrl('welcome1')->thisValueShouldAllow(true)->otherwise()->weDenyAccess();
Expand All @@ -24,7 +25,7 @@ public function testUrlIsAuthorized()

public function testUrlIsAuthorized657()
{
Route::get('/welcome', 'HomeController@index');
Route::get('/welcome', HomeController::class.'@index');

HeyMan::whenYouVisitUrl(['welcome_', 'welcome'])->always()->weDenyAccess();
HeyMan::whenYouVisitUrl('welcome1')->thisValueShouldAllow(true)->otherwise()->weDenyAccess();
Expand All @@ -37,7 +38,7 @@ public function testUrlIsAuthorized657()

public function testUrlIsAuthorized563()
{
Route::get('/welcome', 'HomeController@index');
Route::get('/welcome', HomeController::class.'@index');

HeyMan::whenYouVisitUrl('welcome_', 'welcome')->always()->weDenyAccess();
HeyMan::whenYouVisitUrl('welcome1')->thisValueShouldAllow(true)->otherwise()->weDenyAccess();
Expand All @@ -50,7 +51,7 @@ public function testUrlIsAuthorized563()

public function testUrlIsAuthorized566()
{
Route::get('/welcome', 'HomeController@index');
Route::get('/welcome', HomeController::class.'@index');

HeyMan::whenYouVisitUrl('welcome_', 'welcome')->thisValueShouldAllow(true)->otherwise()->weDenyAccess();
HeyMan::whenYouVisitUrl('welcome1')->thisValueShouldAllow(true)->otherwise()->weDenyAccess();
Expand All @@ -63,7 +64,7 @@ public function testUrlIsAuthorized566()

public function testRouteNameIsAuthorized1()
{
Route::get('/welcome', 'HomeController@index')->name('welcome.name');
Route::get('/welcome', HomeController::class.'@index')->name('welcome.name');

HeyMan::whenYouHitRouteName('welcome.name')->always()->weDenyAccess();

Expand All @@ -75,7 +76,7 @@ public function testRouteNameIsAuthorized1()

public function testRouteNameIsMatchWithPattern()
{
Route::get('/welcome', 'HomeController@index')->name('welcome.name');
Route::get('/welcome', HomeController::class.'@index')->name('welcome.name');

HeyMan::whenYouHitRouteName('welcome.*')->always()->weDenyAccess();

Expand All @@ -87,9 +88,9 @@ public function testRouteNameIsMatchWithPattern()

public function testControllerActionIsAuthorized()
{
Route::get('/welcome', 'HomeController@index');
Route::get('/welcome', HomeController::class.'@index');

HeyMan::whenYouCallAction('\HomeController@index')->always()->weDenyAccess();
HeyMan::whenYouCallAction(HomeController::class.'@index')->always()->weDenyAccess();

HeyMan::turnOff()->routeChecks();
app(StartGuarding::class)->start();
Expand All @@ -99,9 +100,9 @@ public function testControllerActionIsAuthorized()

public function testControllerActionIsAuthorized878()
{
Route::get('/welcome', 'HomeController@index');
Route::get('/welcome', HomeController::class.'@index');

HeyMan::whenYouCallAction('\HomeController@index')->always()->weDenyAccess();
HeyMan::whenYouCallAction(HomeController::class.'@index')->always()->weDenyAccess();

HeyMan::turnOff()->routeChecks();
app(StartGuarding::class)->start();
Expand Down Expand Up @@ -184,7 +185,7 @@ public function test_check_would_be_turned_On_again()

public function test_it_ignores_validation()
{
Route::get('/welcome', 'HomeController@index')->name('welcome.name');
Route::get('/welcome', HomeController::class.'@index')->name('welcome.name');

HeyMan::whenYouVisitUrl('welcome')->yourRequestShouldBeValid(['name' => 'required']);

Expand All @@ -196,7 +197,7 @@ public function test_it_ignores_validation()

public function test_it_ignores_validation2()
{
Route::get('/welcome', 'HomeController@index')->name('welcome.name');
Route::get('/welcome', HomeController::class.'@index')->name('welcome.name');

HeyMan::whenYouVisitUrl('welcome')
->yourRequestShouldBeValid(['name' => 'required'])
Expand All @@ -211,7 +212,7 @@ public function test_it_ignores_validation2()

public function test_it_ignores_validation3()
{
Route::get('/welcome', 'HomeController@index')->name('welcome.name');
Route::get('/welcome', HomeController::class.'@index')->name('welcome.name');

HeyMan::whenYouVisitUrl('welcome')->yourRequestShouldBeValid(['name' => 'required']);

Expand Down

0 comments on commit 79d9866

Please sign in to comment.