hellonico / guzzle-cli-handler
Guzzle handler to imitate HTTP calls through CLI
0.1.0
2021-05-06 12:08 UTC
Requires
- ext-json: *
- guzzlehttp/guzzle: ^6.2 || ^7.2
- guzzlehttp/promises: ^1.3
- guzzlehttp/psr7: ^1.6
- psr/http-message: ^1.0
- symfony/http-foundation: ^5.2
- symfony/process: ^5.0
Requires (Dev)
- phpstan/phpstan: ^0.12.83
- phpunit/phpunit: ^8.5 || ^9.0
- symplify/easy-coding-standard: ^9.2
README
Guzzle handler to imitate HTTP calls through CLI.
Motivation
Execute requests without running a webserver.
Usage
use GuzzleHttp\Client; use GuzzleHttp\HandlerStack; use HelloNico\GuzzleCliHandler\CliHandler; // Document root $docRoot = '/var/www'; // File path // - If absolute, will directly use $filePath // - If relative, will be `$docRoot . DIRECTORY_SEPARATOR . $filePath` // - If URL requested ends with .php, will be overrided and set to `$docRoot . DIRECTORY_SEPARATOR . $urlPath` $filePath = 'index.php'; $cliHandler = new CliHandler( $docRoot, $filePath, function (array &$globals) { // you can mofify global variables here before execution $globals['_ENV'] = ['a' => 'Lorem', 'b' => 'ipsum']; } ); $client = new Client(['handler' => HandlerStack::create($cliHandler)]); $response = $client->get('http://localhost/install.php');
Installing
composer require hellonico/guzzle-cli-handler
Limitations
Due to PHP running in CLI, it's unfortunately not possible to get response headers and maintain sessions.
Developing
composer test
- run phpunitcomposer analyse
- run phpstancomposer lint
- run ecs (coding standards)