Code Monkey home page Code Monkey logo

behat-psr7extension's Introduction

PSR-7 Behat Driver

This is a proof of concept to show that Behat can drive a PSR-7 application without going via a webserver

It's currently built by combining:

  • The existing Mink Browserkit driver, that can test a Symfony app
  • The existing Symfony to PSR-7 bridge, to translate requests and resources back and forth

... and integrating into a behat extension

Usage

Install via composer and configure your behat.yml, specifying the php file that will bootstrap the app (see below):

extensions:
  Cjm\Behat\Psr7Extension:
    app: %paths.base%/path/to/file.php

You can then also modify your MinkExtension configuration to use the PSR-7 driver, e.g.:

extensions:
Behat\MinkExtension:
  base_url:  'http://localhost'
  sessions:
    default:
      psr7: ~

Because there is no current standard interface for PSR-7-handling apps, you will need to select one of the following supported approaches.

Zend Expressive applications

Your configuration file will need to return your application file, bootstrapped. For example:

$container = require __DIR__ . '/../config/container.php';
return $container->get('Zend\Expressive\Application');

Slim applications

Your configuration file will need to return your application file, bootstrapped. For example:

<?php

$app = new \Slim\App;
// .. any necessary bootstrapping
return $app;

All other PSR-7 applications

As long as you can write a function that takes a request and returns a response, you should be able to test your app. Your configuration file will need to return return a callable with the right signature. For example:

<?php

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

// bootstrap your application
$app = new My\App();

return function (RequestInterface $request) use ($app) : ResponseInterface
{
    // exercise your application however you normally would
    return $app->handle($request);
};

behat-psr7extension's People

Contributors

asgrim avatar brunty avatar ciaranmcnulty avatar stof avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.