Closed gabbydgab closed 6 years ago
Was also looking for this feature
You can use this in the meantime: https://github.com/zendframework/zend-expressive/blob/master/test/IntegrationTest.php
Made one much simpler, this works like CURL but without the server having to run
<?php
namespace Test;
use PHPUnit\Framework\TestCase;
use Zend\Diactoros\ServerRequest;
use \Zend\Expressive\Application;
class MiddlewareTest extends \PHPUnit\Framework\TestCase
{
/**
* Initialize required configs and classes
*/
public function setUp()
{
$this->container = require 'config/container.php';
$this->app = $container->get(\Zend\Expressive\Application::class);
}
/**
* Test middleware from the top
*/
public function testRoutingWithMultipleMethodsSamePath()
{
$app = $this->app;
$request = new ServerRequest([], [], '/foo/bar', 'GET');
$result = $app->process($request, $app->getDefaultDelegate());
$this->assertEquals(
'{success: true}',
(string) $result->getBody()
);
}
}
Generally against this, as it is at the edge of e2e testing, but without the benefit of it, and with all its pitfalls. An http-client designed for tests would be better, and yes, it doesn't need to actually run the tests over TCP.
Wouldn't include in expressive, but would rather make it a separate PHPUnit utility/package designed for PSR-7/PSR-15
On 25 Apr 2017 2:03 a.m., "paulocastroo" notifications@github.com wrote:
Made one, its like curl BUT you don't have to run the server to test it
<?php
namespace Test;
use PHPUnit\Framework\TestCase; use Zend\Diactoros\ServerRequest; use \Zend\Expressive\Application;
class MiddlewareTest extends \PHPUnit\Framework\TestCase { /**
Initialize required configs and classes */ public function setUp() { $this->container = require 'config/container.php'; $this->app = $container->get(\Zend\Expressive\Application::class); }
/**
@see https://github.com/zendframework/zend-expressive/issues/40 */ public function testRoutingWithMultipleMethodsSamePath() { $app = $this->app;
$request = new ServerRequest([], [], '/bar/foo/url', 'GET'); $result = $app->process($request, $app->getDefaultDelegate());
$this->assertEquals( '{success: true}', (string) $result->getBody() ); } }
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/zendframework/zend-test/issues/34#issuecomment-296854409, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJakCF6UJY-ilDLJAJpeGSp846F8aEKks5rzThAgaJpZM4J0cXf .
I was actually looking to work on this myself. It's true that it's close to E2E testing, but I still see it's value. I would mock 3rd parties and potentially persistence layer if I see fit; and call it application test. It would be testing all middleware layers in my app - starting from creating a PSR-7 Request and calling the app with with it (similar to the above linked ZF3 WebApp test) and returning response to perform desired assertions on it.
Not sure if it's viable to try to create a general package for testing PSR-7 and 15 micro frameworks as they're using the same components, but in various ways.
Another thing, I would not include this here, as per description - Zend Test is for testing ZF MVC, not Expressive app. (I came across this as I was looking for it myself).
We will not be shoe-horning Expressive-compatible testing features into zend-test.
If somebody would like to make a general-purpose PHPUnit utility package for testing PSR-7/PSR-15 packages, we can direct folks to that, or potentially bring it under the zendframework organization, but this repository is definitely not the location for such features.
I'm learning to develop an app with TDD + Zend Expressive (inspired by TDD in Laravel). I would like to test features on my app while having a separated test for the implementation details, without using/refreshing a browser, with the following test:
Similar with Zend-MVC app, it should have the following testing capabilities:
dispatch($route, $method, $params)
Hoping to have this one. I would love to start this but needs guidance - don't know if it will be integrated as separate library due to expressive dependencies.
Thoughts?