-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathNetteApplicationModule.php
More file actions
88 lines (71 loc) · 2.24 KB
/
NetteApplicationModule.php
File metadata and controls
88 lines (71 loc) · 2.24 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php declare(strict_types = 1);
namespace Contributte\Codeception\Module;
use Codeception\Lib\Framework;
use Codeception\TestInterface;
use Contributte\Codeception\Connector\NetteConnector;
use Nette\DI\Container;
use Nette\Http\IRequest;
use Nette\Http\IResponse;
/**
* @property NetteConnector $client
*/
class NetteApplicationModule extends Framework
{
/** @var array<string, mixed> */
protected array $config = [
'followRedirects' => true,
];
private ?string $path = null;
/**
* @param array{path?: string} $settings
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
*/
public function _beforeSuite(mixed $settings = []): void
{
assert(isset($settings['path']));
$this->path = $settings['path'];
}
public function _before(TestInterface $test): void
{
$this->client = new NetteConnector();
$this->client->setContainerAccessor(
function (): Container {
/** @var NetteDIModule $diModule */
$diModule = $this->getModule(NetteDIModule::class);
return $diModule->getContainer();
}
);
$this->client->followRedirects((bool) $this->config['followRedirects']);
parent::_before($test);
}
public function _after(TestInterface $test): void
{
parent::_after($test);
$_SESSION = [];
$_GET = [];
$_POST = [];
$_FILES = [];
$_COOKIE = [];
}
public function followRedirects(bool $followRedirects): void
{
$this->client->followRedirects($followRedirects);
}
public function seeRedirectTo(string $url): void
{
if ($this->client->isFollowingRedirects()) {
$this->fail('Method seeRedirectTo only works when followRedirects option is disabled');
}
/** @var NetteDIModule $diModule */
$diModule = $this->getModule(NetteDIModule::class);
$request = $diModule->grabService(IRequest::class);
$response = $diModule->grabService(IResponse::class);
if ($response->getHeader('Location') !== $request->getUrl()->getHostUrl() . $url && $response->getHeader('Location') !== $url) {
$this->fail('Couldn\'t confirm redirect target to be "' . $url . '", Location header contains "' . $response->getHeader('Location') . '".');
}
}
public function debugContent(): void
{
$this->debugSection('Content', $this->client->getInternalResponse()->getContent());
}
}