ciaranmcnulty / behat-psr7extension
0.1
2017-05-06 18:32 UTC
Requires
- php: ^7.0
- behat/mink-browserkit-driver: ^1.0
- behat/mink-extension: ^2.0
- psr/http-message: ^1.0
- symfony/http-foundation: ^3.0
- symfony/http-kernel: ^3.0
- symfony/psr-http-message-bridge: ^1.0
- zendframework/zend-diactoros: ^1.0
Requires (Dev)
- behat/behat: ^3.3
- phpunit/phpunit: ^6.1
- slim/slim: ^3.8
- zendframework/zend-expressive: ^2.0.3
- zendframework/zend-expressive-fastroute: ^2.0.0
- zendframework/zend-servicemanager: ^3.3.0
This package is auto-updated.
Last update: 2024-08-24 04:32:54 UTC
README
这是一个概念验证,展示了Behat可以在不经过web服务器的情况下驱动PSR-7应用程序
它目前是通过组合以下内容构建的
- 现有的Mink Browserkit驱动,可以测试Symfony应用程序
- 现有的从Symfony到PSR-7的桥梁,用于在请求和资源之间进行转换
...并将其集成到Behat扩展中
用法
通过composer安装,并配置您的behat.yml,指定将启动应用程序的PHP文件(见下文)
extensions: Cjm\Behat\Psr7Extension: app: %paths.base%/path/to/file.php
然后您还可以修改MinkExtension配置以使用PSR-7驱动程序,例如
extensions: Behat\MinkExtension: base_url: 'http://localhost' sessions: default: psr7: ~
由于目前没有用于处理PSR-7应用程序的当前标准接口,您需要选择以下支持方法之一。
Zend Expressive应用程序
您的配置文件需要返回启动后的应用程序文件。例如
$container = require __DIR__ . '/../config/container.php'; return $container->get('Zend\Expressive\Application');
Slim应用程序
您的配置文件需要返回启动后的应用程序文件。例如
<?php $app = new \Slim\App; // .. any necessary bootstrapping return $app;
所有其他PSR-7应用程序
只要您能编写一个函数,该函数接受一个请求并返回一个响应,您就应该能够测试您的应用程序。您的配置文件需要返回具有正确签名的可调用对象。例如
<?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); };