2017 © Pedro Peláez
 

library slim-requester

This package contains a tool that allows you to perform requests to your Slim application by bypassing the WEB server.

image

dbeurive/slim-requester

This package contains a tool that allows you to perform requests to your Slim application by bypassing the WEB server.

  • Friday, January 13, 2017
  • by dbeurive
  • Repository
  • 1 Watchers
  • 0 Stars
  • 9 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Introduction

This package contains a "requester" the Slim framework., (*1)

The requester allows you to perform requests over your Slim application without the need for a WEB server. This is particularly useful when you want to automate unit tests. Indeed, while you are unit-testing your application's logic, you don't want to test the WEB server's configuration., (*2)

Please note that this package is a work in progress, since new features will be added., (*3)

License

This code is published under the following license:, (*4)

Creative Commons Attribution 4.0 International Public License, (*5)

See the file LICENSE.TXT, (*6)

Installation

From the command line:, (*7)

composer require dbeurive/slim-requester

Or, from within the file composer.json:, (*8)

"require": {
    "dbeurive/slim-requester": "*"
}

Synopsis

Create a the Slim application:, (*9)

use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use dbeurive\Slim\Requester;

// Create your Slim application

$configuration = array(/* your configuration */);
$application = new \Slim\App($configuration);

$application->get('/get/{name}', function (Request $request, Response $response) {
    $name = $request->getAttribute('name');
    $response->getBody()->write("Hello, $name");
    return $response;
});

$application->post('/post', function (Request $request, Response $response) {
    $data = $request->getParsedBody();
    $firstName = filter_var($data['firstname'], FILTER_SANITIZE_STRING);
    $lastName  = filter_var($data['lastname'], FILTER_SANITIZE_STRING);
    $response->getBody()->write("Hello, $firstName $lastName");
    return $response;
});

// Create the requester

$requester = new Requester($application);

// And then you can perform requests:

$text = $requester->get('/get/toto');
$parameters = ['firstname' => 'Mickey', 'lastname' => 'Mouse'];
$text = $requester->post('/post', $parameters);
$response = $requester->getResponse();

API

\dbeurive\Slim\Requester::__construct(App $inApplication)
\dbeurive\Slim\Requester::get($inRequestUri, $inQueryString='')
\dbeurive\Slim\Requester::post($inRequestUri, $inPostParameters=[])
\dbeurive\Slim\Requester::jsonRpc($inRequestUri, $inParameters=[])
\dbeurive\Slim\Requester::setServerCgiEnvironmentVariables(array $inServerCgiEnvironmentVariables, $inMerge=false)
\dbeurive\Slim\Requester::setHttpHeaders(array $inHttpHeaders, $inMerge=false)
\dbeurive\Slim\Requester::getResponse()
\dbeurive\Slim\Requester::getRequest()

Please see the file Requester.php for a detailed description of the API., (*10)

Examples

Please see the unit tests for examples., (*11)

The file below creates the application:, (*12)

  • index.php: this file is the application's entry point.

The three files below implement unit tests:, (*13)

The Versions

13/01 2017

dev-master

9999999-dev

This package contains a tool that allows you to perform requests to your Slim application by bypassing the WEB server.

  Sources   Download

Creative Commons Attribution 4.0 International Public License

The Requires

 

The Development Requires

13/01 2017

1.0.2

1.0.2.0

This package contains a tool that allows you to perform requests to your Slim application by bypassing the WEB server.

  Sources   Download

Creative Commons Attribution 4.0 International Public License

The Requires

 

The Development Requires

13/01 2017

1.0.1

1.0.1.0

This package contains a tool that allows you to perform requests to your Slim application by bypassing the WEB server.

  Sources   Download

Creative Commons Attribution 4.0 International Public License

The Requires

 

The Development Requires

10/01 2017

1.0.0

1.0.0.0

This package contains a tool that allows you to perform requests to your Slim application by bypassing the WEB server.

  Sources   Download

Creative Commons Attribution 4.0 International Public License

The Requires

 

The Development Requires