Skip to content

Commit 4e5d931

Browse files
committed
Update to Nette 3.0
1 parent 42fddff commit 4e5d931

File tree

5 files changed

+62
-62
lines changed

5 files changed

+62
-62
lines changed

composer.json

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,20 @@
1212
}
1313
],
1414
"require": {
15-
"php": "^5.5.0|^7.0.0",
15+
"php": "^7.1.0",
1616
"codeception/codeception": "^2.2.0",
17-
"nette/bootstrap": "^2.3.0",
18-
"nette/di": "^2.3.0",
19-
"nette/http": "^2.3.0"
17+
"nette/application": "^3.0.0@alpha",
18+
"nette/bootstrap": "^3.0.0@alpha",
19+
"nette/component-model": "^3.0.0@alpha",
20+
"nette/di": "^3.0.0@alpha",
21+
"nette/http": "^3.0.0@alpha",
22+
"nette/neon": "^3.0.0@alpha",
23+
"nette/php-generator": "^3.0.0@alpha",
24+
"nette/utils": "^3.0.0@alpha"
2025
},
2126
"require-dev": {
22-
"enumag/application": "^0.3.16",
23-
"latte/latte": "^2.3.0",
24-
"tracy/tracy": "^2.3.0"
27+
"latte/latte": "^3.0.0@alpha",
28+
"tracy/tracy": "^2.4.0"
2529
},
2630
"autoload": {
2731
"psr-4": {
@@ -32,5 +36,10 @@
3236
"psr-4": {
3337
"Tests\\Integration\\": "tests/integration/src"
3438
}
39+
},
40+
"extra": {
41+
"branch-alias": {
42+
"dev-master": "1.0-dev"
43+
}
3544
}
3645
}

src/Http/Request.php

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Nette\Http\IRequest;
1414
use Nette\Http\Request as HttpRequest;
1515
use Nette\Http\RequestFactory;
16+
use Nette\Http\UrlScript;
1617

1718
/**
1819
* HttpRequest class for tests.
@@ -40,88 +41,84 @@ public function __construct(RequestFactory $factory)
4041
public function reset()
4142
{
4243
$this->request = $this->factory->createHttpRequest();
43-
$url = $this->request->getUrl();
44-
if (!$url->getPort()) {
45-
$url->setPort(80); // Fix canonicalization in Nette 2.2.
46-
}
4744
}
4845

49-
public function getCookie($key, $default = null)
46+
public function getCookie(string $key)
5047
{
51-
return $this->request->getCookie($key, $default);
48+
return $this->request->getCookie($key);
5249
}
5350

54-
public function getCookies()
51+
public function getCookies(): array
5552
{
5653
return $this->request->getCookies();
5754
}
5855

59-
public function getFile($key)
56+
public function getFile(string $key)
6057
{
61-
return call_user_func_array([$this->request, 'getFile'], func_get_args());
58+
return $this->request->getFile($key);
6259
}
6360

64-
public function getFiles()
61+
public function getFiles(): array
6562
{
6663
return $this->request->getFiles();
6764
}
6865

69-
public function getHeader($header, $default = null)
66+
public function getHeader(string $header): ?string
7067
{
71-
return $this->request->getHeader($header, $default);
68+
return $this->request->getHeader($header);
7269
}
7370

74-
public function getHeaders()
71+
public function getHeaders(): array
7572
{
7673
return $this->request->getHeaders();
7774
}
7875

79-
public function getMethod()
76+
public function getMethod(): string
8077
{
8178
return $this->request->getMethod();
8279
}
8380

84-
public function getPost($key = null, $default = null)
81+
public function getPost(string $key = null)
8582
{
86-
return call_user_func_array([$this->request, 'getPost'], func_get_args());
83+
return $this->request->getPost(...func_get_args());
8784
}
8885

89-
public function getQuery($key = null, $default = null)
86+
public function getQuery(string $key = null)
9087
{
91-
return call_user_func_array([$this->request, 'getQuery'], func_get_args());
88+
return $this->request->getQuery(...func_get_args());
9289
}
9390

94-
public function getRawBody()
91+
public function getRawBody(): string
9592
{
9693
return $this->request->getRawBody();
9794
}
9895

99-
public function getRemoteAddress()
96+
public function getRemoteAddress(): ?string
10097
{
10198
return $this->request->getRemoteAddress();
10299
}
103100

104-
public function getRemoteHost()
101+
public function getRemoteHost(): ?string
105102
{
106103
return $this->request->getRemoteHost();
107104
}
108105

109-
public function getUrl()
106+
public function getUrl(): UrlScript
110107
{
111108
return $this->request->getUrl();
112109
}
113110

114-
public function isAjax()
111+
public function isAjax(): bool
115112
{
116113
return $this->request->isAjax();
117114
}
118115

119-
public function isMethod($method)
116+
public function isMethod(string $method): bool
120117
{
121118
return $this->request->isMethod($method);
122119
}
123120

124-
public function isSecured()
121+
public function isSecured(): bool
125122
{
126123
return $this->request->isSecured();
127124
}

src/Http/Response.php

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
namespace Arachne\Codeception\Http;
1212

13+
use Nette\Http\Helpers;
1314
use Nette\Http\IResponse;
1415
use Nette\Http\Response as HttpResponse;
15-
use Nette\Object;
1616
use Nette\Utils\DateTime;
1717

1818
/**
1919
* HttpResponse class for tests.
2020
*
2121
* @author Jáchym Toušek <enumag@gmail.com>
2222
*/
23-
class Response extends Object implements IResponse
23+
class Response implements IResponse
2424
{
2525
/**
2626
* @var int
@@ -39,11 +39,11 @@ public function reset()
3939
}
4040

4141
/**
42-
* @param int
42+
* @param int $code
4343
*
44-
* @return self
44+
* @return static
4545
*/
46-
public function setCode($code)
46+
public function setCode(int $code)
4747
{
4848
$this->code = $code;
4949

@@ -53,7 +53,7 @@ public function setCode($code)
5353
/**
5454
* @return int
5555
*/
56-
public function getCode()
56+
public function getCode(): int
5757
{
5858
return $this->code;
5959
}
@@ -62,9 +62,9 @@ public function getCode()
6262
* @param string $name
6363
* @param string $value
6464
*
65-
* @return self
65+
* @return static
6666
*/
67-
public function setHeader($name, $value)
67+
public function setHeader(string $name, string $value)
6868
{
6969
$this->headers[$name] = $value;
7070

@@ -75,9 +75,9 @@ public function setHeader($name, $value)
7575
* @param string $name
7676
* @param string $value
7777
*
78-
* @return self
78+
* @return static
7979
*/
80-
public function addHeader($name, $value)
80+
public function addHeader(string $name, string $value)
8181
{
8282
$this->headers[$name] = $value;
8383

@@ -88,9 +88,9 @@ public function addHeader($name, $value)
8888
* @param string $type
8989
* @param string $charset
9090
*
91-
* @return self
91+
* @return static
9292
*/
93-
public function setContentType($type, $charset = null)
93+
public function setContentType(string $type, string $charset = null)
9494
{
9595
$this->setHeader('Content-Type', $type.($charset ? '; charset='.$charset : ''));
9696

@@ -101,7 +101,7 @@ public function setContentType($type, $charset = null)
101101
* @param string $url
102102
* @param int $code
103103
*/
104-
public function redirect($url, $code = self::S302_FOUND)
104+
public function redirect(string $url, int $code = self::S302_FOUND): void
105105
{
106106
$this->setCode($code);
107107
$this->setHeader('Location', $url);
@@ -110,7 +110,7 @@ public function redirect($url, $code = self::S302_FOUND)
110110
/**
111111
* @param string|int|DateTime $time
112112
*
113-
* @return self
113+
* @return static
114114
*/
115115
public function setExpiration($time)
116116
{
@@ -123,34 +123,33 @@ public function setExpiration($time)
123123

124124
$time = DateTime::from($time);
125125
$this->setHeader('Cache-Control', 'max-age='.($time->format('U') - time()));
126-
$this->setHeader('Expires', HttpResponse::date($time));
126+
$this->setHeader('Expires', Helpers::formatDate($time));
127127

128128
return $this;
129129
}
130130

131131
/**
132132
* @return bool
133133
*/
134-
public function isSent()
134+
public function isSent(): bool
135135
{
136136
return false;
137137
}
138138

139139
/**
140140
* @param string $name
141-
* @param mixed $default
142141
*
143142
* @return mixed
144143
*/
145-
public function getHeader($name, $default = null)
144+
public function getHeader(string $name): ?string
146145
{
147-
return isset($this->headers[$name]) ? $this->headers[$name] : $default;
146+
return $this->headers[$name] ?? null;
148147
}
149148

150149
/**
151150
* @return array
152151
*/
153-
public function getHeaders()
152+
public function getHeaders(): array
154153
{
155154
return $this->headers;
156155
}
@@ -166,7 +165,7 @@ public function getHeaders()
166165
*
167166
* @return self
168167
*/
169-
public function setCookie($name, $value, $time, $path = null, $domain = null, $secure = null, $httpOnly = null)
168+
public function setCookie(string $name, string $value, $time, string $path = null, string $domain = null, bool $secure = null, bool $httpOnly = null, string $sameSite = null)
170169
{
171170
return $this;
172171
}
@@ -177,11 +176,7 @@ public function setCookie($name, $value, $time, $path = null, $domain = null, $s
177176
* @param string $domain
178177
* @param bool $secure
179178
*/
180-
public function deleteCookie($name, $path = null, $domain = null, $secure = null)
181-
{
182-
}
183-
184-
public function removeDuplicateCookies()
179+
public function deleteCookie(string $name, string $path = null, string $domain = null, bool $secure = null): void
185180
{
186181
}
187182
}

tests/integration/config/config.neon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ extensions:
33
nette.application: Nette\Bridges\ApplicationDI\ApplicationExtension(%debugMode%, [], %tempDir%)
44
nette.http: Nette\Bridges\HttpDI\HttpExtension
55
nette.latte: Nette\Bridges\ApplicationDI\LatteExtension(%tempDir%, %debugMode%)
6-
enumag.application: Enumag\Application\DI\ApplicationExtension
76

87
services:
98
routerFactory: Tests\Integration\Fixtures\RouterFactory
109
router: @routerFactory::create()
1110

1211
nette.application:
13-
catchExceptions: null
12+
catchExceptions: true
1413
mapping:
1514
*: Tests\Integration\Fixtures\*Presenter

tests/integration/src/Fixtures/ArticlePresenter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ class ArticlePresenter extends Presenter
1111
{
1212
public function actionRedirect()
1313
{
14-
$this->redirect(301, 'page');
14+
$this->redirectPermanent('page');
1515
}
1616

17-
public function formatTemplateFiles()
17+
public function formatTemplateFiles(): array
1818
{
1919
$name = $this->getName();
2020
$presenter = substr($name, strrpos(':'.$name, ':'));

0 commit comments

Comments
 (0)