Skip to content
Merged
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
22 changes: 17 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Tests

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

jobs:
PHPStan:
Expand Down Expand Up @@ -39,7 +43,7 @@ jobs:
- name: PHPStan tests
run: vendor/bin/phpstan analyze -l 8 -a vendor/yiisoft/yii2/Yii.php --no-progress src

PHPUnit:
Infection:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
Expand All @@ -56,7 +60,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: mbstring, intl, mysql
coverage: none
coverage: "pcov"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update: true
Expand All @@ -80,5 +84,13 @@ jobs:
if: matrix.php == '7.4'
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader

- name: PHPUnit tests
run: vendor/bin/phpunit --verbose
- name: Run PHPUnit
if: matrix.php == '8.0'
run: vendor/bin/phpunit

- name: Run Infection with PHPUnit
if: matrix.php == '7.4'
run: |
mkdir -p build/logs
vendor/bin/phpunit --coverage-xml=build/logs/coverage-xml --log-junit=build/logs/junit.xml
vendor/bin/infection --threads=2 --coverage=build/logs --show-mutations --no-progress
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@ There are some rules:
- each repository knows how to handle one single storage unit and not more,
- components operate on repositories, not on identifiers.

TODOs:
- [ ] Infection

When API is ready, I'll start preparing the client.
2 changes: 1 addition & 1 deletion infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"mutators": {
"@default": true
},
"minMsi": 95,
"minMsi": 100,
"minCoveredMsi": 100
}
File renamed without changes.
25 changes: 23 additions & 2 deletions src/Services/Category/CategoryArchiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Podium\Api\Services\Category;

use InvalidArgumentException;
use Podium\Api\Components\PodiumResponse;
use Podium\Api\Events\ArchiveEvent;
use Podium\Api\Interfaces\ArchiverInterface;
Expand Down Expand Up @@ -38,7 +39,17 @@ private function beforeArchive(): bool
*/
public function archive(RepositoryInterface $category): PodiumResponse
{
if (!$category instanceof CategoryRepositoryInterface || !$this->beforeArchive()) {
if (!$category instanceof CategoryRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'Category must be instance of Podium\Api\Interfaces\CategoryRepositoryInterface!'
),
]
);
}

if (!$this->beforeArchive()) {
return PodiumResponse::error();
}

Expand Down Expand Up @@ -94,7 +105,17 @@ private function beforeRevive(): bool
*/
public function revive(RepositoryInterface $category): PodiumResponse
{
if (!$category instanceof CategoryRepositoryInterface || !$this->beforeRevive()) {
if (!$category instanceof CategoryRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'Category must be instance of Podium\Api\Interfaces\CategoryRepositoryInterface!'
),
]
);
}

if (!$this->beforeRevive()) {
return PodiumResponse::error();
}

Expand Down
13 changes: 12 additions & 1 deletion src/Services/Category/CategoryRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Podium\Api\Services\Category;

use InvalidArgumentException;
use Podium\Api\Components\PodiumResponse;
use Podium\Api\Events\RemoveEvent;
use Podium\Api\Interfaces\CategoryRepositoryInterface;
Expand Down Expand Up @@ -36,7 +37,17 @@ private function beforeRemove(): bool
*/
public function remove(RepositoryInterface $category): PodiumResponse
{
if (!$category instanceof CategoryRepositoryInterface || !$this->beforeRemove()) {
if (!$category instanceof CategoryRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'Category must be instance of Podium\Api\Interfaces\CategoryRepositoryInterface!'
),
]
);
}

if (!$this->beforeRemove()) {
return PodiumResponse::error();
}

Expand Down
39 changes: 33 additions & 6 deletions src/Services/Category/CategorySorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Podium\Api\Services\Category;

use InvalidArgumentException;
use Podium\Api\Components\PodiumResponse;
use Podium\Api\Events\SortEvent;
use Podium\Api\Interfaces\CategoryRepositoryInterface;
Expand Down Expand Up @@ -39,11 +40,27 @@ private function beforeReplace(): bool
*/
public function replace(RepositoryInterface $firstCategory, RepositoryInterface $secondCategory): PodiumResponse
{
if (
!$firstCategory instanceof CategoryRepositoryInterface
|| !$secondCategory instanceof CategoryRepositoryInterface
|| !$this->beforeReplace()
) {
if (!$firstCategory instanceof CategoryRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'First category must be instance of Podium\Api\Interfaces\CategoryRepositoryInterface!'
),
]
);
}

if (!$secondCategory instanceof CategoryRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'Second category must be instance of Podium\Api\Interfaces\CategoryRepositoryInterface!'
),
]
);
}

if (!$this->beforeReplace()) {
return PodiumResponse::error();
}

Expand Down Expand Up @@ -98,7 +115,17 @@ private function beforeSort(): bool
*/
public function sort(RepositoryInterface $category): PodiumResponse
{
if (!$category instanceof CategoryRepositoryInterface || !$this->beforeSort()) {
if (!$category instanceof CategoryRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'Category must be instance of Podium\Api\Interfaces\CategoryRepositoryInterface!'
),
]
);
}

if (!$this->beforeSort()) {
return PodiumResponse::error();
}

Expand Down
25 changes: 23 additions & 2 deletions src/Services/Forum/ForumArchiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Podium\Api\Services\Forum;

use InvalidArgumentException;
use Podium\Api\Components\PodiumResponse;
use Podium\Api\Events\ArchiveEvent;
use Podium\Api\Interfaces\ArchiverInterface;
Expand Down Expand Up @@ -38,7 +39,17 @@ private function beforeArchive(): bool
*/
public function archive(RepositoryInterface $forum): PodiumResponse
{
if (!$forum instanceof ForumRepositoryInterface || !$this->beforeArchive()) {
if (!$forum instanceof ForumRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'Forum must be instance of Podium\Api\Interfaces\ForumRepositoryInterface!'
),
]
);
}

if (!$this->beforeArchive()) {
return PodiumResponse::error();
}

Expand Down Expand Up @@ -94,7 +105,17 @@ private function beforeRevive(): bool
*/
public function revive(RepositoryInterface $forum): PodiumResponse
{
if (!$forum instanceof ForumRepositoryInterface || !$this->beforeRevive()) {
if (!$forum instanceof ForumRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'Forum must be instance of Podium\Api\Interfaces\ForumRepositoryInterface!'
),
]
);
}

if (!$this->beforeRevive()) {
return PodiumResponse::error();
}

Expand Down
39 changes: 33 additions & 6 deletions src/Services/Forum/ForumBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Podium\Api\Services\Forum;

use InvalidArgumentException;
use Podium\Api\Components\PodiumResponse;
use Podium\Api\Events\BuildEvent;
use Podium\Api\Interfaces\CategorisedBuilderInterface;
Expand Down Expand Up @@ -44,11 +45,27 @@ public function create(
RepositoryInterface $category,
array $data = []
): PodiumResponse {
if (
!$forum instanceof ForumRepositoryInterface
|| !$category instanceof CategoryRepositoryInterface
|| !$this->beforeCreate()
) {
if (!$forum instanceof ForumRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'Forum must be instance of Podium\Api\Interfaces\ForumRepositoryInterface!'
),
]
);
}

if (!$category instanceof CategoryRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'Category must be instance of Podium\Api\Interfaces\CategoryRepositoryInterface!'
),
]
);
}

if (!$this->beforeCreate()) {
return PodiumResponse::error();
}

Expand Down Expand Up @@ -100,7 +117,17 @@ private function beforeEdit(): bool
*/
public function edit(RepositoryInterface $forum, array $data = []): PodiumResponse
{
if (!$forum instanceof ForumRepositoryInterface || !$this->beforeEdit()) {
if (!$forum instanceof ForumRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'Forum must be instance of Podium\Api\Interfaces\ForumRepositoryInterface!'
),
]
);
}

if (!$this->beforeEdit()) {
return PodiumResponse::error();
}

Expand Down
27 changes: 22 additions & 5 deletions src/Services/Forum/ForumMover.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Podium\Api\Services\Forum;

use InvalidArgumentException;
use Podium\Api\Components\PodiumResponse;
use Podium\Api\Events\MoveEvent;
use Podium\Api\Interfaces\CategoryRepositoryInterface;
Expand Down Expand Up @@ -37,11 +38,27 @@ private function beforeMove(): bool
*/
public function move(RepositoryInterface $forum, RepositoryInterface $category): PodiumResponse
{
if (
!$forum instanceof ForumRepositoryInterface
|| !$category instanceof CategoryRepositoryInterface
|| !$this->beforeMove()
) {
if (!$forum instanceof ForumRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'Forum must be instance of Podium\Api\Interfaces\ForumRepositoryInterface!'
),
]
);
}

if (!$category instanceof CategoryRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'Category must be instance of Podium\Api\Interfaces\CategoryRepositoryInterface!'
),
]
);
}

if (!$this->beforeMove()) {
return PodiumResponse::error();
}

Expand Down
13 changes: 12 additions & 1 deletion src/Services/Forum/ForumRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Podium\Api\Services\Forum;

use InvalidArgumentException;
use Podium\Api\Components\PodiumResponse;
use Podium\Api\Events\RemoveEvent;
use Podium\Api\Interfaces\ForumRepositoryInterface;
Expand Down Expand Up @@ -36,7 +37,17 @@ private function beforeRemove(): bool
*/
public function remove(RepositoryInterface $forum): PodiumResponse
{
if (!$forum instanceof ForumRepositoryInterface || !$this->beforeRemove()) {
if (!$forum instanceof ForumRepositoryInterface) {
return PodiumResponse::error(
[
'exception' => new InvalidArgumentException(
'Forum must be instance of Podium\Api\Interfaces\ForumRepositoryInterface!'
),
]
);
}

if (!$this->beforeRemove()) {
return PodiumResponse::error();
}

Expand Down
Loading