Skip to content

add github actions integration #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DB_CONNECTION=mongodb
DB_HOST=localhost
DB_PORT=27017
DB_DATABASE=laravel_permission_mongodb_test
DB_USERNAME=db_user
DB_PASSWORD=db_password
DB_AUTHENTICATION_DATABASE=admin
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
services:
mongodb:
image: mongo:7.0
options: >-
--health-cmd "echo 'db.runCommand({ ping: 1 })' | mongosh --quiet"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 27017:27017

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: mongodb, mbstring
ini-values: |
memory_limit = 2G
coverage: xdebug
tools: composer

- name: debug
run: docker ps

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run PHPCS
run: composer check-style

- name: Run tests
run: composer test

- name: Run tests with coverage
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml --coverage-html=coverage-html

# - name: Upload coverage to GitHub Pages
# uses: peaceiris/actions-gh-pages@v3
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_dir: ./build/coverage/coverage-html
39 changes: 0 additions & 39 deletions .scrutinizer.yml

This file was deleted.

6 changes: 5 additions & 1 deletion src/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ public static function create(array $attributes = []): \Illuminate\Database\Eloq
{
$attributes['guard_name'] = $attributes['guard_name'] ?? (new Guard())->getDefaultName(static::class);
$helpers = new Helpers();
$role = static::query()
->where('name', $attributes['name'])
->where('guard_name', $attributes['guard_name'])
->first();

if (static::query()->where('name', $attributes['name'])->where('guard_name', $attributes['guard_name'])->first()) {
if ($role) {
$name = (string)$attributes['name'];
$guardName = (string)$attributes['guard_name'];
throw new RoleAlreadyExists($helpers->getRoleAlreadyExistsMessage($name, $guardName));
Expand Down
9 changes: 7 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@ protected function getEnvironmentSetUp($app)
{
$app['config']->set('database.default', 'mongodb');
$app['config']->set('database.connections.mongodb', [
'host' => 'localhost',
'host' => env('DB_HOST', 'localhost'),
'port' => '27017',
'driver' => 'mongodb',
'database' => 'laravel_permission_mongodb_test',
'database' => env('DB_DATABASE', 'laravel_permission_mongodb_test'),
'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),
'options' => [
'database' => env('DB_AUTHENTICATION_DATABASE', ''), // required with Mongo 3+
],
'prefix' => '',
]);

Expand Down
Loading