Skip to content

Commit

Permalink
chore: backend tests, PHPStan (#31)
Browse files Browse the repository at this point in the history
* wip: add tests for existing functionality

* add workflow

* Apply fixes from StyleCI

* any version of var-dumper

* temporarily check for a 401

* remove results.cache

* wip: fixup a few bits, add more tests

* Apply fixes from StyleCI

* tests passing locally

* Apply fixes from StyleCI

* chore: enable phpstan, apply fixes

* Apply fixes from StyleCI

* chore: npm audit fix

---------

Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
imorland and StyleCIBot authored Oct 31, 2023
1 parent a54b8ce commit 139db7e
Show file tree
Hide file tree
Showing 30 changed files with 1,551 additions and 410 deletions.
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

0 comments on commit 139db7e

Please sign in to comment.