test(arch): update Pest architecture test suite for the new client architecture
This commit is contained in:
parent
d2ff816b0c
commit
8ff36e5207
3 changed files with 173 additions and 35 deletions
|
|
@ -2,14 +2,23 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Uwil\ArcadiaApiPhpClient\Exception\ArcadiaGenesisApiException;
|
||||
use Uwil\ArcadiaApiPhpClient\Lib\ApiCaller;
|
||||
use Uwil\ArcadiaApiPhpClient\Auth\ApiMandatoryHeadersMiddleware;
|
||||
use Uwil\ArcadiaApiPhpClient\Auth\ClientIdentifier;
|
||||
use Uwil\ArcadiaApiPhpClient\Auth\ClientSecret;
|
||||
use Uwil\ArcadiaApiPhpClient\Auth\Nonce;
|
||||
use Uwil\ArcadiaApiPhpClient\Error\AbstractApiError;
|
||||
use Uwil\ArcadiaApiPhpClient\Error\ApiError;
|
||||
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto;
|
||||
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\Inco\PortionType;
|
||||
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\IncoCompo\AbstractIncoCompoPartDto;
|
||||
use Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\IncoCompo\IncoCompoPartDto;
|
||||
use Uwil\ArcadiaApiPhpClient\Mapper\Mapper;
|
||||
use Uwil\ArcadiaApiPhpClient\Repository\AbstractGenesisRepository;
|
||||
use Uwil\ArcadiaApiPhpClient\Lib\ApiSorter\EmployeeSortColumn;
|
||||
use Uwil\ArcadiaApiPhpClient\Lib\ApiSorter\IncoSortColumn;
|
||||
use Uwil\ArcadiaApiPhpClient\Lib\ApiSorter\SortColumn;
|
||||
use Uwil\ArcadiaApiPhpClient\Lib\LibMiddleware;
|
||||
use Uwil\ArcadiaApiPhpClient\Lib\ValueObjectId;
|
||||
use Uwil\ArcadiaApiPhpClient\Logger\ApiLoggerMiddleware;
|
||||
use Uwil\ArcadiaApiPhpClient\Repository\AbstractApiRepository;
|
||||
use Uwil\ArcadiaApiPhpClient\Repository\Repository;
|
||||
|
||||
$libraryNamespace = 'Uwil\ArcadiaApiPhpClient';
|
||||
|
|
@ -19,7 +28,7 @@ describe('coding standards', function () use ($libraryNamespace): void {
|
|||
arch()->preset()->security();
|
||||
|
||||
test('no shell execution functions are used')
|
||||
->expect(['exec', 'shell_exec', 'system', 'passthru', 'proc_open'])
|
||||
->expect(['exec', 'shell_exec', 'system', 'passthru', 'proc_open', 'popen', 'pcntl_exec'])
|
||||
->not->toBeUsed();
|
||||
|
||||
test('no eval usage')
|
||||
|
|
@ -27,7 +36,7 @@ describe('coding standards', function () use ($libraryNamespace): void {
|
|||
->not->toBeUsed();
|
||||
|
||||
test('no dangerous file functions')
|
||||
->expect(['file_get_contents', 'file_put_contents', 'fopen'])
|
||||
->expect(['file_put_contents'])
|
||||
->not->toBeUsed();
|
||||
|
||||
test('no globals are used')
|
||||
|
|
@ -43,12 +52,11 @@ describe('coding standards', function () use ($libraryNamespace): void {
|
|||
->not->toBeUsed();
|
||||
|
||||
test('no sleep function are used')
|
||||
->expect(['sleep', 'usleep'])
|
||||
->not->toBeUsed()
|
||||
->ignoring(ApiCaller::class);
|
||||
->expect(['sleep', 'usleep', 'time_nanosleep', 'time_sleep_until'])
|
||||
->not->toBeUsed();
|
||||
|
||||
test('no debug globals are used')
|
||||
->expect(['var_dump', 'die', 'print_r'])
|
||||
->expect(['var_dump', 'die', 'print_r', 'dd', 'dump'])
|
||||
->not->toBeUsed();
|
||||
|
||||
arch('all source files use strict types')
|
||||
|
|
@ -57,55 +65,191 @@ describe('coding standards', function () use ($libraryNamespace): void {
|
|||
});
|
||||
|
||||
describe('naming conventions', function () use ($libraryNamespace): void {
|
||||
arch('mappers have Mapper suffix')
|
||||
->expect("{$libraryNamespace}\Mapper")
|
||||
->toHaveSuffix('Mapper');
|
||||
arch('hydrators have Hydrator suffix')
|
||||
->expect("{$libraryNamespace}\Hydrator")
|
||||
->toHaveSuffix('Hydrator');
|
||||
|
||||
arch('repositories have Repository suffix')
|
||||
->expect("{$libraryNamespace}\Repository")
|
||||
->toHaveSuffix('Repository')
|
||||
->ignoring([AbstractGenesisRepository::class]);
|
||||
->toHaveSuffix('Repository');
|
||||
|
||||
arch('services have Service suffix')
|
||||
->expect("{$libraryNamespace}\Service")
|
||||
->toHaveSuffix('Service');
|
||||
|
||||
arch('errors have Error suffix')
|
||||
->expect("{$libraryNamespace}\Error")
|
||||
->toHaveSuffix('Error');
|
||||
|
||||
arch('factories have Factory suffix')
|
||||
->expect("{$libraryNamespace}\Factory")
|
||||
->toHaveSuffix('Factory');
|
||||
|
||||
arch('middlewares have Middleware suffix')
|
||||
->expect([
|
||||
ApiMandatoryHeadersMiddleware::class,
|
||||
ApiLoggerMiddleware::class,
|
||||
])
|
||||
->toHaveSuffix('Middleware');
|
||||
});
|
||||
|
||||
describe('inheritance contracts', function () use ($libraryNamespace): void {
|
||||
arch('ApiDtos implements Dto')
|
||||
arch('ApiDtos implement Dto')
|
||||
->expect("{$libraryNamespace}\Lib\ApiDto\Dto")
|
||||
->toImplement(Dto::class);
|
||||
->toImplement(Dto::class)
|
||||
->ignoring([
|
||||
Dto::class,
|
||||
AbstractIncoCompoPartDto::class,
|
||||
IncoCompoPartDto::class,
|
||||
]);
|
||||
|
||||
arch('Exceptions implements ArcadiaGenesisApiException')
|
||||
->expect("{$libraryNamespace}\Exception")
|
||||
->toImplement(ArcadiaGenesisApiException::class);
|
||||
arch('Errors implement ApiError')
|
||||
->expect("{$libraryNamespace}\Error")
|
||||
->toImplement(ApiError::class)
|
||||
->ignoring([ApiError::class]);
|
||||
|
||||
arch('Mappers implements Mapper')
|
||||
->expect("{$libraryNamespace}\Mapper")
|
||||
->toImplement(Mapper::class);
|
||||
arch('Concrete errors extend AbstractApiError')
|
||||
->expect("{$libraryNamespace}\Error")
|
||||
->classes()
|
||||
->toExtend(AbstractApiError::class)
|
||||
->ignoring([AbstractApiError::class]);
|
||||
|
||||
arch('Repositories implements Repository')
|
||||
arch('Repositories implement Repository')
|
||||
->expect("{$libraryNamespace}\Repository")
|
||||
->toImplement(Repository::class)
|
||||
->ignoring([AbstractGenesisRepository::class]);
|
||||
->ignoring([Repository::class]);
|
||||
|
||||
arch('Concrete repositories extend AbstractApiRepository')
|
||||
->expect("{$libraryNamespace}\Repository")
|
||||
->classes()
|
||||
->toExtend(AbstractApiRepository::class)
|
||||
->ignoring([AbstractApiRepository::class]);
|
||||
|
||||
arch('Middlewares implement LibMiddleware')
|
||||
->expect([
|
||||
ApiMandatoryHeadersMiddleware::class,
|
||||
ApiLoggerMiddleware::class,
|
||||
])
|
||||
->toImplement(LibMiddleware::class);
|
||||
|
||||
arch('Sort columns implement SortColumn')
|
||||
->expect([
|
||||
EmployeeSortColumn::class,
|
||||
IncoSortColumn::class,
|
||||
])
|
||||
->toImplement(SortColumn::class);
|
||||
|
||||
arch('Value objects implement ValueObjectId')
|
||||
->expect("{$libraryNamespace}\Lib\ApiValueObject")
|
||||
->toImplement(ValueObjectId::class);
|
||||
});
|
||||
|
||||
describe('api lib elements', function () use ($libraryNamespace): void {
|
||||
arch('Api Dto are immutable')
|
||||
describe('class modifiers and immutability', function () use ($libraryNamespace): void {
|
||||
arch('Api DTOs are final and readonly')
|
||||
->expect("{$libraryNamespace}\Lib\ApiDto\Dto")
|
||||
->classes()
|
||||
->toBeReadonly()
|
||||
->toBeFinal()
|
||||
->ignoring([
|
||||
Dto::class,
|
||||
AbstractIncoCompoPartDto::class,
|
||||
IncoCompoPartDto::class,
|
||||
PortionType::class,
|
||||
]);
|
||||
|
||||
arch('Value objects are immutable')
|
||||
arch('Value objects are final and readonly')
|
||||
->expect("{$libraryNamespace}\Lib\ApiValueObject")
|
||||
->classes()
|
||||
->toBeReadonly()
|
||||
->toBeFinal();
|
||||
|
||||
arch('Auth value objects are final and readonly')
|
||||
->expect([
|
||||
ClientIdentifier::class,
|
||||
ClientSecret::class,
|
||||
Nonce::class,
|
||||
])
|
||||
->classes()
|
||||
->toBeReadonly()
|
||||
->toBeFinal();
|
||||
|
||||
arch('Concrete errors are final and readonly')
|
||||
->expect("{$libraryNamespace}\Error")
|
||||
->classes()
|
||||
->toBeReadonly()
|
||||
->toBeFinal()
|
||||
->ignoring([
|
||||
ApiError::class,
|
||||
AbstractApiError::class,
|
||||
]);
|
||||
|
||||
arch('Hydrators are final')
|
||||
->expect("{$libraryNamespace}\Hydrator")
|
||||
->classes()
|
||||
->toBeFinal();
|
||||
|
||||
arch('Factories are final')
|
||||
->expect("{$libraryNamespace}\Factory")
|
||||
->classes()
|
||||
->toBeFinal();
|
||||
|
||||
arch('Concrete services are final')
|
||||
->expect("{$libraryNamespace}\Service")
|
||||
->classes()
|
||||
->toBeFinal();
|
||||
|
||||
arch('Concrete repositories are final')
|
||||
->expect("{$libraryNamespace}\Repository")
|
||||
->classes()
|
||||
->toBeFinal()
|
||||
->ignoring([AbstractApiRepository::class]);
|
||||
|
||||
arch('Middlewares are final')
|
||||
->expect([
|
||||
ApiMandatoryHeadersMiddleware::class,
|
||||
ApiLoggerMiddleware::class,
|
||||
])
|
||||
->classes()
|
||||
->toBeFinal();
|
||||
});
|
||||
|
||||
describe('layer isolation', function () use ($libraryNamespace): void {
|
||||
arch('DTOs do not depend on Repositories, Services, or Hydrators')
|
||||
->expect("{$libraryNamespace}\Lib\ApiDto")
|
||||
->not->toUse([
|
||||
"{$libraryNamespace}\Repository",
|
||||
"{$libraryNamespace}\Service",
|
||||
"{$libraryNamespace}\Hydrator",
|
||||
]);
|
||||
|
||||
arch('Value objects do not depend on Repositories, Services, Hydrators, or DTOs')
|
||||
->expect("{$libraryNamespace}\Lib\ApiValueObject")
|
||||
->not->toUse([
|
||||
"{$libraryNamespace}\Repository",
|
||||
"{$libraryNamespace}\Service",
|
||||
"{$libraryNamespace}\Hydrator",
|
||||
"{$libraryNamespace}\Lib\ApiDto",
|
||||
]);
|
||||
|
||||
arch('Errors do not depend on Repositories, Services, Hydrators, or DTOs')
|
||||
->expect("{$libraryNamespace}\Error")
|
||||
->not->toUse([
|
||||
"{$libraryNamespace}\Repository",
|
||||
"{$libraryNamespace}\Service",
|
||||
"{$libraryNamespace}\Hydrator",
|
||||
"{$libraryNamespace}\Lib\ApiDto",
|
||||
]);
|
||||
|
||||
arch('Repositories do not depend on Services')
|
||||
->expect("{$libraryNamespace}\Repository")
|
||||
->not->toUse([
|
||||
"{$libraryNamespace}\Service",
|
||||
]);
|
||||
|
||||
arch('Hydrators do not depend on Repositories or Services')
|
||||
->expect("{$libraryNamespace}\Hydrator")
|
||||
->not->toUse([
|
||||
"{$libraryNamespace}\Repository",
|
||||
"{$libraryNamespace}\Service",
|
||||
]);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,17 +6,11 @@ namespace Tests;
|
|||
|
||||
use PHPUnit\Framework\TestCase as PhpUnitTestCase;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Uwil\ArcadiaApiPhpClient\Lib\ApiCaller;
|
||||
use Uwil\ArcadiaApiPhpClient\Lib\ApiConfig;
|
||||
use Uwil\ArcadiaApiPhpClient\Lib\Psr7\RequestFactory;
|
||||
|
||||
class TestCase extends PhpUnitTestCase
|
||||
abstract class TestCase extends PhpUnitTestCase
|
||||
{
|
||||
protected ClientInterface $client;
|
||||
|
||||
protected RequestFactory $requestFactory;
|
||||
|
||||
protected ApiConfig $apiConfig;
|
||||
|
||||
protected ApiCaller $apiCaller;
|
||||
}
|
||||
|
|
|
|||
0
tests/Unit/.gitkeep
Normal file
0
tests/Unit/.gitkeep
Normal file
Loading…
Add table
Reference in a new issue