Skip to content

Commit 3030e48

Browse files
authored
- Add tests roles and logs (#5)
* add blt * ignore .php-cs-fixer.cache * add roles * add activitylog * add activitylog * create Example behat test * add behat to makefile
1 parent e0f8971 commit 3030e48

23 files changed

+1565
-169
lines changed

.env.behat

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
APP_NAME=community-with-legends
2+
VITE_APP_NAME=community-with-legends
3+
APP_ENV=local
4+
APP_KEY=base64:sCsJw8z+d/4ymp0OvzSip2h4Vp2hZZhpV2uOxgTqP94=
5+
APP_DEBUG=true
6+
APP_URL=http://api.community-with-legends.mmr.localhost
7+
8+
APP_LOCALE=en
9+
APP_FALLBACK_LOCALE=en
10+
APP_FAKER_LOCALE=en_US
11+
12+
APP_MAINTENANCE_DRIVER=file
13+
APP_MAINTENANCE_STORE=database
14+
15+
BCRYPT_ROUNDS=12
16+
17+
LOG_CHANNEL=stack
18+
LOG_DEPRECATIONS_CHANNEL=null
19+
LOG_LEVEL=debug
20+
21+
DB_CONNECTION=pgsql
22+
DB_HOST=community-with-legends-db-dev
23+
DB_PORT=5432
24+
DB_DATABASE=community-with-legends
25+
DB_USERNAME=community-with-legends
26+
DB_PASSWORD=password
27+
DB_ROOT_PASSWORD=example
28+
29+
SESSION_DRIVER=redis
30+
SESSION_LIFETIME=120
31+
SESSION_ENCRYPT=false
32+
SESSION_PATH=/
33+
SESSION_DOMAIN=null
34+
35+
BROADCAST_CONNECTION=log
36+
FILESYSTEM_DISK=local
37+
QUEUE_CONNECTION=redis
38+
39+
CACHE_STORE=redis
40+
CACHE_PREFIX=
41+
42+
MEMCACHED_HOST=127.0.0.1
43+
44+
REDIS_CLIENT=phpredis
45+
REDIS_HOST=community-with-legends-redis-dev
46+
REDIS_PASSWORD=null
47+
REDIS_PORT=6379
48+
49+
MAIL_MAILER=smtp
50+
MAIL_HOST=mailpit
51+
MAIL_PORT=1025
52+
MAIL_USERNAME=null
53+
MAIL_PASSWORD=null
54+
MAIL_ENCRYPTION=null
55+
MAIL_FROM_ADDRESS="[email protected]"
56+
MAIL_FROM_NAME="${APP_NAME}"
57+
58+
AWS_ACCESS_KEY_ID=
59+
AWS_SECRET_ACCESS_KEY=
60+
AWS_DEFAULT_REGION=us-east-1
61+
AWS_BUCKET=
62+
AWS_USE_PATH_STYLE_ENDPOINT=false
63+
64+
# DOCKER
65+
DOCKER_APP_HOST_PORT=63861
66+
DOCKER_DATABASE_HOST_PORT=63863
67+
DOCKER_MAILPIT_DASHBOARD_HOST_PORT=63864
68+
DOCKER_REDIS_HOST_PORT=63862
69+
DOCKER_INSTALL_XDEBUG=true
70+
71+
DOCKER_HOST_USER_ID=1000

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ google-credentials.json
1919
.composer
2020
/public/build/
2121
supervisord.pid
22+
.php-cs-fixer.cache

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ shell-root:
4747

4848
test:
4949
@docker compose --file ${DOCKER_COMPOSE_FILE} exec --user "${CURRENT_USER_ID}:${CURRENT_USER_GROUP_ID}" ${DOCKER_COMPOSE_APP_CONTAINER} composer test
50+
@docker compose --file ${DOCKER_COMPOSE_FILE} exec --user "${CURRENT_USER_ID}:${CURRENT_USER_GROUP_ID}" ${DOCKER_COMPOSE_APP_CONTAINER} composer test-features
5051

5152
fix:
5253
@docker compose --file ${DOCKER_COMPOSE_FILE} exec --user "${CURRENT_USER_ID}:${CURRENT_USER_GROUP_ID}" ${DOCKER_COMPOSE_APP_CONTAINER} bash -c 'composer csf'

app/Enums/Role.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace CommunityWithLegends\Enums;
6+
7+
enum Role: string
8+
{
9+
case User = "user";
10+
case Administrator = "administrator";
11+
case Moderator = "moderator";
12+
13+
public static function casesToSelect(): array
14+
{
15+
$cases = collect(Role::cases());
16+
17+
return $cases->map(
18+
fn(Role $enum): array => [
19+
"label" => $enum->label(),
20+
"value" => $enum->value,
21+
],
22+
)->toArray();
23+
}
24+
25+
public function label(): string
26+
{
27+
return __($this->value);
28+
}
29+
30+
public function permissions(): array
31+
{
32+
return config("permission.permission_roles")[$this->value];
33+
}
34+
}

app/Models/User.php

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Foundation\Auth\User as Authenticatable;
1010
use Illuminate\Notifications\Notifiable;
1111
use Laravel\Sanctum\HasApiTokens;
12+
use Spatie\Permission\Traits\HasRoles;
1213

1314
/**
1415
* @property string $name
@@ -23,6 +24,7 @@ class User extends Authenticatable
2324
use HasApiTokens;
2425
use HasFactory;
2526
use Notifiable;
27+
use HasRoles;
2628

2729
protected $fillable = [
2830
"name",

composer.json

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
{
2-
"name": "blumilksoftware/community-with-legends",
2+
"name": "mmr/community-with-legends",
33
"type": "project",
44
"description": "community-with-legends project.",
55
"keywords": ["framework", "laravel"],
66
"license": "MIT",
7+
"repositories": [
8+
{
9+
"type": "vcs",
10+
"url": "https://github.com/MRR-Group/blt"
11+
}
12+
],
713
"require": {
814
"php": "^8.3.4",
915
"ext-pdo": "*",
1016
"guzzlehttp/guzzle": "^7.9.2",
11-
"inertiajs/inertia-laravel": "^1.3.1",
12-
"laravel/framework": "^11.34.2",
13-
"laravel/sanctum": "^4.0.5",
14-
"laravel/tinker": "^2.10.0"
17+
"laravel/framework": "^11.43.2",
18+
"laravel/sanctum": "^4.0.8",
19+
"laravel/tinker": "^2.10.1",
20+
"spatie/laravel-activitylog": "^4.10",
21+
"spatie/laravel-permission": "^6.15"
1522
},
1623
"require-dev": {
24+
"behat/behat": "^3.19",
25+
"blumilksoftware/blt": "^v0.1.1",
1726
"blumilksoftware/codestyle": "^v3.3.0",
1827
"fakerphp/faker": "^1.24.1",
1928
"mockery/mockery": "^1.6.12",
@@ -52,6 +61,7 @@
5261
"@putenv XDEBUG_MODE=off",
5362
"@php artisan test"
5463
],
64+
"test-features": "./vendor/bin/behat",
5565
"analyse": "./vendor/bin/phpstan analyse",
5666
"cs": "./vendor/bin/php-cs-fixer fix --dry-run --diff --config codestyle.php",
5767
"csf": "./vendor/bin/php-cs-fixer fix --diff --config codestyle.php"

0 commit comments

Comments
 (0)