-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFeatureContext.php
53 lines (44 loc) · 1.57 KB
/
FeatureContext.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
namespace Acpr\Behat\Psr\FeatureContexts;
use Acpr\Behat\Psr\Context\Psr11MinkAwareContext;
use Acpr\Behat\Psr\Context\RuntimeMinkContext;
use Behat\MinkExtension\Context\MinkContext;
use Laminas\Diactoros\Response;
use Mezzio\Application;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
class FeatureContext extends MinkContext implements Psr11MinkAwareContext
{
// this trait implements the methods required by the Psr11MinkAwareContext interface, you don't
// have to use it in your contexts, but you do have to do what it does.
use RuntimeMinkContext;
private ?ContainerInterface $container = null;
public function setContainer(ContainerInterface $container): void
{
$this->container = $container;
}
/**
* @When I go to the injected url
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function iGoToTheInjectedUrl(): void
{
// add a new route to the system under test by accessing the container and
// acting on the application directly.
/** @var Application $app */
$app = $this->container?->get(Application::class);
$app->get('/injection',
function (): ResponseInterface {
$response = new Response();
$response->getBody()->write('Injected!');
return $response;
}
);
$this->visit('/injection');
}
}