1. Go to this page and download the library: Download wellrested/test library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wellrested / test example snippets
use Psr\Http\Server\RequestHandlerInterface;
use WellRESTed\Test\TestCases\RequestHandlerTestCase;
class MyHandlerTest extends RequestHandlerTestCase
{
public function setUp(): void
{
parent::setUp();
// Configure the default request.
$this->request = $this->request
->withAttribute('id', 12345);
}
protected function getHandler(): RequestHandlerInterface
{
// Return a configured instance of the handler under test.
return new MyHandler();
}
public function testReturns200()
{
// Call `dispatch` to send the request to the handler under test and return
// the response.
$response = $this->dispatch();
$this->assertEquals(200, $response->getStatusCode());
}
}
use Psr\Http\Server\RequestHandlerInterface;
use WellRESTed\Message\Response;
use WellRESTed\Test\TestCases\MiddlewareTestCase;
class MyMiddlewareTest extends MiddlewareTestCase
{
public function setUp(): void
{
parent::setUp();
// Configure the default request.
$this->request = $this->request
->withAttribute('id', 12345);
// Configure the upstream handler the middleware may call.
// Set the `response` member to the respone the handler should return.
$this->handler->response = new Response(200);
}
protected function getMiddleware(): MiddlewareInterface
{
// Return a configured instance of the middleware under test.
return new MyMiddleware();
}
public function testDelegatesToUpstreamHandler()
{
// Call `dispatch` to send the request to the middleware under test and
// return the response.
$response = $this->dispatch();
// You can make assertions on the `handler` member to check if the upstream
// handler was called.
// The `called` member will be true if the handler was called.
$this->assertTrue($this->handler->called);
// The `request` member will be set with the request passed to the handler.
$this->assertSame($this->request, $this->handler->request);
}
}
class MyLegacyMiddlewareTest extends LegacyMiddlewareTestCase
{
public function setUp(): void
{
parent::setUp();
// Configure the default request.
$this->request = $this->request
->withAttribute('id', 12345);
// Configure the `next` member.
$this->next->upstreamResponse = new Response(200);
}
protected function getMiddleware()
{
// Return the legacy middleware under test.
return new MyLegacyMiddleware();
}
public function testDelegatesToNext()
{
// Call `dispatch` to send the request to the middleware under test and
// return the response.
$response = $this->dispatch();
// You can make assertions on the `next` member.
// The `called` member will be true if `next` was called.
$this->assertTrue($this->next->called);
// The `request` member will be set with the request passed to `next`.
$this->assertSame($this->request, $this->next->request);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.