Skip to content

Commit 9ef7f68

Browse files
committed
Merge pull request #28 from Busuu/master
Add cookies feature to WebTestClient
2 parents 308fd6d + 9008c24 commit 9ef7f68

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/There4/Slim/Test/WebTestClient.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class WebTestClient
1515
/** @var \Slim\Http\Response */
1616
public $response;
1717

18+
private $cookies = array();
19+
1820
public function __construct(Slim\Slim $slim)
1921
{
2022
$this->app = $slim;
@@ -92,10 +94,22 @@ private function request($method, $path, $data = array(), $optionalHeaders = arr
9294
$this->request = $this->app->request();
9395
$this->response = $this->app->response();
9496

97+
//apply cookies (if present)
98+
if ($this->cookies) {
99+
foreach ($this->cookies as $name => $value) {
100+
$this->request->cookies->set($name, $value);
101+
}
102+
}
103+
95104
// Execute our app
96105
$this->app->run();
97106

98107
// Return the application output. Also available in `response->body()`
99108
return ob_get_clean();
100109
}
110+
111+
public function setCookie($name, $value)
112+
{
113+
$this->cookies[$name] = $value;
114+
}
101115
}

0 commit comments

Comments
 (0)