Building ServerRequest class which implement PSR-7 ServerRequestInterface from global PHP variables.
Require PHP 8.1 or newest.
additional links: PSR-7, PSR-17
composer kaspi/psr7-wizard// Example build ServerRequest class with package kaspi/http-message
$httpFactory = new \Kaspi\HttpMessage\HttpFactory();
$wizard = new \Kaspi\Psr7Wizard\ServerRequestWizard(
serverRequestFactory: $httpFactory,
streamFactory: $httpFactory,
uploadedFileFactory: $httpFactory,
uriFactory: $httpFactory,
);
/** @var \Psr\Http\Message\ServerRequestInterface $serverRequest */
$serverRequest = $wizard->fromGlobals();
// ✋🏻 Or create by params 👇🏻
$serverEnv = [
'REMOTE_ADDR' => '127.0.0.1',
'REMOTE_PORT' => '35096',
'SERVER_SOFTWARE' => 'PHP 8.2.14 Development Server',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'SERVER_NAME' => '127.0.0.1',
'SERVER_PORT' => '8080',
'REQUEST_URI' => '/',
'REQUEST_METHOD' => 'POST',
'SCRIPT_NAME' => '/index.php',
'CONTENT_LENGTH' => '53',
'HTTP_CONTENT_LENGTH' => '53'
];
$queryStringParams = [
'search' => 'php%',
];
$cookie = [
'save' => 'no'
];
$uploadedFiles = [
$httpFactory->createUploadedFile('/tmp/file1');
];
$parsedBody = [
'form' => [
'name' => 'Joe',
'contact' => '+555-36-89'
],
];
$body = 'form%5Bname%5D=Joe&form%5Bcontact%5D=%2B555-36-89';
$wizard->fromParams(
serverParams: $serverEnv,
queryParams: $queryStringParams,
cookieParams: $cookie,
files: $uploadedFiles,
parsedBody: $parsedBody,
body: $body
);- Local development (without Docker)
- With Docker images (WSL, Linux)
Required PHP 8.1 or higher, php Composer 2.x
Run test without code coverage
composer testRunning tests with checking code coverage by tests with a report in html format
./vendor/bin/phpunitRequires installed PCOV driver
⛑ the results will be in the folder .coverage-html
For static analysis we use the package Phan.
Running without PHP extension PHP AST
./vendor/bin/phan --allow-polyfill-parserTo bring the code to standards, we use php-cs-fixer which is declared in composer's dev dependencies.
composer fixerYou can specify the image with the PHP version in the .env file in the PHP_IMAGE key.
By default, the container is built with the php:8.1-cli-alpine image.
Build docker container
docker-compose buildInstall php composer dependencies:
docker-compose run --rm php composer installRun tests with a code coverage report and a report in html format
docker-compose run --rm php vendor/bin/phpunit⛑ the results will be in the folder .coverage-html
Phan (static analyzer for PHP)
docker-compose run --rm php vendor/bin/phanYou can work in a shell into a docker container:
docker-compose run --rm php shCheck and correct code style:
make fixRun the static code analyzer:
make statRun tests:
make testRun all stages of checks:
make allRun test for all support php version:
make test-supports-php