Skip to content

Commit 97dc9b4

Browse files
KacerCZf3l1x
authored andcommitted
Support for Nette 3.0
* updated dependencies * updated implementations of HTTP request and response classes * ignore some errors reported by PHPStan
1 parent 0671e71 commit 97dc9b4

File tree

4 files changed

+41
-90
lines changed

4 files changed

+41
-90
lines changed

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
],
2121
"require": {
2222
"php": ">= 7.1",
23-
"codeception/codeception": "^2.5.1|^3.0.2",
24-
"nette/di": "~2.4.14",
25-
"nette/bootstrap": "~2.4.6",
26-
"nette/http": "~2.4.10",
27-
"nette/utils": "~2.5.3"
23+
"codeception/codeception": "^2.5.1 || ^3.0.2",
24+
"nette/di": "^3.0",
25+
"nette/bootstrap": "^3.0",
26+
"nette/http": "^3.0.3",
27+
"nette/utils": "^3.0"
2828
},
2929
"require-dev": {
3030
"ninjify/qa": "^0.8.0",
31-
"nette/application": "~2.4.12",
32-
"nette/caching": "~2.5.8",
31+
"nette/application": "^3.0",
32+
"nette/caching": "~2.5.8 || ^3.0",
3333
"latte/latte": "~2.5.1",
3434
"tracy/tracy": "~2.6.1"
3535
},
@@ -65,7 +65,7 @@
6565
],
6666
"phpstan-install": [
6767
"mkdir -p temp/phpstan",
68-
"composer require -d temp/phpstan nette/utils:~2.5.3",
68+
"composer require -d temp/phpstan nette/utils:^3.0",
6969
"composer require -d temp/phpstan phpstan/phpstan:^0.10",
7070
"composer require -d temp/phpstan phpstan/phpstan-deprecation-rules:^0.10",
7171
"composer require -d temp/phpstan phpstan/phpstan-nette:^0.10",

phpstan.neon

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ parameters:
1515
- %rootDir%/../../../tests/_*
1616

1717
ignoreErrors:
18-
- '#^Only booleans are allowed in a negated boolean, int\|Nette\\Utils\\DateTime\|string given.#'
18+
- '#^Only booleans are allowed in a negated boolean, string\|null given.#'
1919

2020
# Should not happen
2121
- '#^Method Contributte\\Codeception\\Module\\NetteDIModule::getContainer\(\) should return Nette\\DI\\Container but returns Nette\\DI\\Container\|null#'
2222
- '#^Method Contributte\\Codeception\\Http\\Request::getFile\(\) should return Nette\\Http\\FileUpload\|null but returns array\|Nette\\Http\\FileUpload\|null.#'
2323
- '#^Cannot call method getName\(\) on PHPStan\\Reflection\\ClassReflection\|null.#'
24+
- '#Parameter \#1 \$path of static method Nette\\Utils\\FileSystem::delete\(\) expects string, string\|false given\.#'
25+
- '#Call to an undefined method Nette\\DI\\Definitions\\Definition::setFactory\(\)\.#'
26+
- '#Call to protected method setType\(\) of class Nette\\DI\\Definitions\\Definition\.#'
2427

2528
# Complicated to test dev-required phpstan with separatly installed version
2629
- '#^Call to an undefined method PHPStan\\#'
2730

2831
# Symfony 4.3 deprecation message
2932
- '#^Class Contributte\\Codeception\\Connector\\NetteConnector extends deprecated class Symfony\\Component\\BrowserKit\\Client\.#'
30-
33+
-

src/Http/Request.php

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,13 @@ public function __construct(RequestFactory $factory)
2727

2828
public function reset(): void
2929
{
30-
$this->request = $this->factory->createHttpRequest();
30+
$this->request = $this->factory->fromGlobals();
3131
}
3232

3333
/**
34-
* @param string $key
35-
* @param mixed $default
3634
* @return mixed
37-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
3835
*/
39-
public function getCookie($key, $default = null)
36+
public function getCookie(string $key)
4037
{
4138
return $this->request->getCookie($key);
4239
}
@@ -49,11 +46,7 @@ public function getCookies(): array
4946
return $this->request->getCookies();
5047
}
5148

52-
/**
53-
* @param string $key
54-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
55-
*/
56-
public function getFile($key): ?FileUpload
49+
public function getFile(string $key): ?FileUpload
5750
{
5851
return $this->request->getFile($key);
5952
}
@@ -66,14 +59,9 @@ public function getFiles(): array
6659
return $this->request->getFiles();
6760
}
6861

69-
/**
70-
* @param string $header
71-
* @param string|null $default
72-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
73-
*/
74-
public function getHeader($header, $default = null): ?string
62+
public function getHeader(string $header): ?string
7563
{
76-
return $this->request->getHeader($header, $default);
64+
return $this->request->getHeader($header);
7765
}
7866

7967
/**
@@ -90,32 +78,26 @@ public function getMethod(): string
9078
}
9179

9280
/**
93-
* @param string|null $key
94-
* @param mixed $default
9581
* @return mixed
96-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
9782
*/
98-
public function getPost($key = null, $default = null)
83+
public function getPost(?string $key = null)
9984
{
10085
if (func_num_args() === 0) {
10186
return $this->request->getPost();
10287
} else {
103-
return $this->request->getPost($key, $default);
88+
return $this->request->getPost($key);
10489
}
10590
}
10691

10792
/**
108-
* @param string|null $key
109-
* @param mixed $default
11093
* @return mixed
111-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
11294
*/
113-
public function getQuery($key = null, $default = null)
95+
public function getQuery(?string $key = null)
11496
{
11597
if (func_num_args() === 0) {
11698
return $this->request->getQuery();
11799
} else {
118-
return $this->request->getQuery($key, $default);
100+
return $this->request->getQuery($key);
119101
}
120102
}
121103

@@ -144,11 +126,7 @@ public function isAjax(): bool
144126
return $this->request->isAjax();
145127
}
146128

147-
/**
148-
* @param string $method
149-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
150-
*/
151-
public function isMethod($method): bool
129+
public function isMethod(string $method): bool
152130
{
153131
return $this->request->isMethod($method);
154132
}

src/Http/Response.php

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Contributte\Codeception\Http;
44

5+
use DateTimeInterface;
56
use Nette\Http\Helpers;
67
use Nette\Http\IResponse;
78
use Nette\Utils\DateTime;
@@ -30,63 +31,51 @@ public function getCode(): int
3031
}
3132

3233
/**
33-
* @param int $code
34-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
34+
* @return static
3535
*/
36-
public function setCode($code): self
36+
public function setCode(int $code, ?string $reason = null)
3737
{
3838
$this->code = $code;
3939
return $this;
4040
}
4141

4242
/**
43-
* @param string $name
44-
* @param string $value
45-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
43+
* @return static
4644
*/
47-
public function setHeader($name, $value): self
45+
public function setHeader(string $name, string $value)
4846
{
4947
$this->headers[$name] = $value;
5048
return $this;
5149
}
5250

5351
/**
54-
* @param string $name
55-
* @param string $value
56-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
52+
* @return static
5753
*/
58-
public function addHeader($name, $value): self
54+
public function addHeader(string $name, string $value)
5955
{
6056
$this->headers[$name] = $value;
6157
return $this;
6258
}
6359

6460
/**
65-
* @param string $type
66-
* @param string|null $charset
67-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
61+
* @return static
6862
*/
69-
public function setContentType($type, $charset = null): self
63+
public function setContentType(string $type, ?string $charset = null)
7064
{
7165
$this->setHeader('Content-Type', $type . ($charset !== null ? '; charset=' . $charset : ''));
7266
return $this;
7367
}
7468

75-
/**
76-
* @param string $url
77-
* @param int $code
78-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
79-
*/
80-
public function redirect($url, $code = self::S302_FOUND): void
69+
public function redirect(string $url, int $code = self::S302_FOUND): void
8170
{
8271
$this->setCode($code);
8372
$this->setHeader('Location', $url);
8473
}
8574

8675
/**
87-
* @param string|int|DateTime $time
76+
* @return static
8877
*/
89-
public function setExpiration($time): self
78+
public function setExpiration(?string $time)
9079
{
9180
if (!$time) {
9281
$this->setHeader('Cache-Control', 's-maxage=0, max-age=0, must-revalidate');
@@ -107,14 +96,9 @@ public function isSent(): bool
10796
return false;
10897
}
10998

110-
/**
111-
* @param string $name
112-
* @param string|null $default
113-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
114-
*/
115-
public function getHeader($name, $default = null): ?string
99+
public function getHeader(string $name): ?string
116100
{
117-
return $this->headers[$name] ?? $default;
101+
return $this->headers[$name] ?? null;
118102
}
119103

120104
/**
@@ -126,29 +110,15 @@ public function getHeaders(): array
126110
}
127111

128112
/**
129-
* @param string $name
130-
* @param string $value
131-
* @param string|int|DateTime $time
132-
* @param string|null $path
133-
* @param string|null $domain
134-
* @param bool|null $secure
135-
* @param bool|null $httpOnly
136-
* @param string|null $sameSite
137-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
113+
* @param string|int|DateTimeInterface $time
114+
* @return static
138115
*/
139-
public function setCookie($name, $value, $time, $path = null, $domain = null, $secure = null, $httpOnly = null, $sameSite = null): self
116+
public function setCookie(string $name, string $value, $time, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null, ?string $sameSite = null)
140117
{
141118
return $this;
142119
}
143120

144-
/**
145-
* @param string $name
146-
* @param string|null $path
147-
* @param string|null $domain
148-
* @param bool|null $secure
149-
* @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint
150-
*/
151-
public function deleteCookie($name, $path = null, $domain = null, $secure = null): void
121+
public function deleteCookie(string $name, ?string $path = null, ?string $domain = null, ?bool $secure = null): void
152122
{
153123
}
154124

0 commit comments

Comments
 (0)