Skip to content

Commit 80f5209

Browse files
committed
Move request and response into members
1 parent d160bed commit 80f5209

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

tests/TestCase/Controller/Component/ApiPaginationComponentTest.php

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class ApiPaginationComponentTest extends TestCase
2323
*/
2424
public function setUp()
2525
{
26+
$this->request = new Request('/articles');
27+
$this->response = $this->getMock('Cake\Network\Response');
2628
$this->Articles = TableRegistry::get('BryanCrowe/ApiPagination.Articles', ['table' => 'bryancrowe_articles']);
2729
parent::setUp();
2830
}
@@ -39,9 +41,7 @@ public function tearDown()
3941

4042
public function testNonApiPaginatedRequest()
4143
{
42-
$request = new Request('/articles');
43-
$response = $this->getMock('Cake\Network\Response');
44-
$controller = new ArticlesController($request, $response);
44+
$controller = new ArticlesController($this->request, $this->response);
4545
$apiPaginationComponent = new ApiPaginationComponent($controller->components());
4646
$event = new Event('Controller.beforeRender', $controller);
4747

@@ -50,10 +50,8 @@ public function testNonApiPaginatedRequest()
5050

5151
public function testDefaultPaginationSettings()
5252
{
53-
$request = new Request('/articles');
54-
$request->env('HTTP_ACCEPT', 'application/json');
55-
$response = $this->getMock('Cake\Network\Response');
56-
$controller = new ArticlesController($request, $response);
53+
$this->request->env('HTTP_ACCEPT', 'application/json');
54+
$controller = new ArticlesController($this->request, $this->response);
5755
$controller->set('data', $controller->paginate($this->Articles));
5856
$apiPaginationComponent = new ApiPaginationComponent($controller->components());
5957
$event = new Event('Controller.beforeRender', $controller);
@@ -81,10 +79,8 @@ public function testDefaultPaginationSettings()
8179

8280
public function testVisibilitySettings()
8381
{
84-
$request = new Request('/articles');
85-
$request->env('HTTP_ACCEPT', 'application/json');
86-
$response = $this->getMock('Cake\Network\Response');
87-
$controller = new ArticlesController($request, $response);
82+
$this->request->env('HTTP_ACCEPT', 'application/json');
83+
$controller = new ArticlesController($this->request, $this->response);
8884
$controller->set('data', $controller->paginate($this->Articles));
8985
$apiPaginationComponent = new ApiPaginationComponent($controller->components(), [
9086
'visible' => [
@@ -114,10 +110,8 @@ public function testVisibilitySettings()
114110

115111
public function testAliasSettings()
116112
{
117-
$request = new Request('/articles');
118-
$request->env('HTTP_ACCEPT', 'application/json');
119-
$response = $this->getMock('Cake\Network\Response');
120-
$controller = new ArticlesController($request, $response);
113+
$this->request->env('HTTP_ACCEPT', 'application/json');
114+
$controller = new ArticlesController($this->request, $this->response);
121115
$controller->set('data', $controller->paginate($this->Articles));
122116
$apiPaginationComponent = new ApiPaginationComponent($controller->components(), [
123117
'aliases' => [
@@ -151,10 +145,8 @@ public function testAliasSettings()
151145

152146
public function testKeySetting()
153147
{
154-
$request = new Request('/articles');
155-
$request->env('HTTP_ACCEPT', 'application/json');
156-
$response = $this->getMock('Cake\Network\Response');
157-
$controller = new ArticlesController($request, $response);
148+
$this->request->env('HTTP_ACCEPT', 'application/json');
149+
$controller = new ArticlesController($this->request, $this->response);
158150
$controller->set('data', $controller->paginate($this->Articles));
159151
$apiPaginationComponent = new ApiPaginationComponent($controller->components(), [
160152
'key' => 'paging'
@@ -186,8 +178,7 @@ public function testAllSettings()
186178
{
187179
$request = new Request('/articles');
188180
$request->env('HTTP_ACCEPT', 'application/json');
189-
$response = $this->getMock('Cake\Network\Response');
190-
$controller = new ArticlesController($request, $response);
181+
$controller = new ArticlesController($request, $this->response);
191182
$controller->set('data', $controller->paginate($this->Articles));
192183
$apiPaginationComponent = new ApiPaginationComponent($controller->components(), [
193184
'key' => 'fun',

0 commit comments

Comments
 (0)