Skip to content
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

chore: backend tests, PHPStan #31

Merged
merged 13 commits into from
Oct 31, 2023
12 changes: 12 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: FoF Ban IPs PHP

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
with:
enable_backend_testing: true
enable_phpstan: true

backend_directory: .
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Javascript
name: FoF Ban IPs JS

on: [workflow_dispatch, push, pull_request]

Expand All @@ -8,11 +8,12 @@ jobs:
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: false
enable_typescript: true

frontend_directory: ./js
backend_directory: .
js_package_manager: npm
main_git_branch: master

secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
vendor
composer.lock
js/dist
tests/.phpunit.result.cache
35 changes: 34 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,43 @@
"flarum/flags",
"flarum/tags",
"flarum/approval"
]
]
},
"flagrow": {
"discuss": "https://discuss.flarum.org/d/20949"
},
"flarum-cli": {
"modules": {
"backendTesting": true,
"githubActions": true
}
}
},
"autoload-dev": {
"psr-4": {
"FoF\\BanIPs\\Tests\\": "tests/"
}
},
"scripts": {
"test": [
"@test:unit",
"@test:integration"
],
"test:unit": "phpunit -c tests/phpunit.unit.xml",
"test:integration": "phpunit -c tests/phpunit.integration.xml",
"test:setup": "@php tests/integration/setup.php",
"analyse:phpstan": "phpstan analyse",
"clear-cache:phpstan": "phpstan clear-result-cache"
},
"scripts-descriptions": {
"test": "Runs all tests.",
"test:unit": "Runs all unit tests.",
"test:integration": "Runs all integration tests.",
"test:setup": "Sets up a database for use with integration tests. Execute this only once.",
"analyse:phpstan": "Run static analysis"
},
"require-dev": {
"flarum/testing": "^1.0.0",
"flarum/phpstan": "*"
}
}
7 changes: 3 additions & 4 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Flarum\Api\Controller;
use Flarum\Api\Serializer;
use Flarum\Api\Serializer\AbstractSerializer;
use Flarum\Database\AbstractModel;
use Flarum\Extend;
use Flarum\Post\Post;
use Flarum\User\User;
Expand Down Expand Up @@ -61,8 +60,8 @@
->modelPolicy(User::class, Access\UserPolicy::class),

(new Extend\ApiSerializer(Serializer\PostSerializer::class))
->attributes(function (AbstractSerializer $serializer, AbstractModel $post, array $attributes): array {
$attributes['canBanIP'] = $serializer->getActor()->can('banIP', $post);
->attributes(function (AbstractSerializer $serializer, Post $post, array $attributes): array {
$attributes['canBanIP'] = $serializer->getActor()->can('banIP', $post->user);

return $attributes;
})
Expand Down Expand Up @@ -95,7 +94,7 @@
(new Extend\ApiController(Controller\ListPostsController::class))
->addInclude(['banned_ip', 'banned_ip.user']),

(new Extend\ApiController(Controller\ShowPostsController::class))
(new Extend\ApiController(Controller\ShowPostController::class))
->addInclude(['banned_ip', 'banned_ip.user']),

(new Extend\ApiController(Controller\CreatePostController::class))
Expand Down
Loading
Loading