Skip to content

Commit 618457e

Browse files
committed
Fix PHPUnit getMock warnings in 3.next.
1 parent 138f50f commit 618457e

File tree

12 files changed

+71
-61
lines changed

12 files changed

+71
-61
lines changed

tests/TestCase/Console/ShellTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,10 +1145,16 @@ public function testRunCommandInvokeTask()
11451145
{
11461146
$parser = new ConsoleOptionParser('knife');
11471147
$parser->addSubcommand('slice');
1148-
$io = $this->getMock('Cake\Console\ConsoleIo');
1148+
$io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
11491149

1150-
$shell = $this->getMock('Cake\Console\Shell', ['hasTask', 'getOptionParser'], [$io]);
1151-
$task = $this->getMock('Cake\Console\Shell', ['main', '_welcome'], [$io]);
1150+
$shell = $this->getMockBuilder('Cake\Console\Shell')
1151+
->setMethods(['hasTask', 'getOptionParser'])
1152+
->setConstructorArgs([$io])
1153+
->getMock();
1154+
$task = $this->getMockBuilder('Cake\Console\Shell')
1155+
->setMethods(['main', '_welcome'])
1156+
->setConstructorArgs([$io])
1157+
->getMock();
11521158

11531159
$shell->expects($this->once())
11541160
->method('getOptionParser')

tests/TestCase/Controller/Component/AuthComponentTest.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,10 @@ public function testIdentify()
165165
*/
166166
public function testIdentifyArrayAccess()
167167
{
168-
$AuthLoginFormAuthenticate = $this->getMock(
169-
'Cake\Controller\Component\Auth\FormAuthenticate',
170-
['authenticate'],
171-
[],
172-
'',
173-
false
174-
);
168+
$AuthLoginFormAuthenticate = $this->getMockBuilder('Cake\Controller\Component\Auth\FormAuthenticate')
169+
->setMethods(['authenticate'])
170+
->disableOriginalConstructor()
171+
->getMock();
175172
$this->Auth->authenticate = [
176173
'AuthLoginForm' => [
177174
'userModel' => 'AuthUsers'
@@ -315,13 +312,10 @@ public function testIsAuthorizedDelegation()
315312
*/
316313
public function testIsAuthorizedWithArrayObject()
317314
{
318-
$AuthMockOneAuthorize = $this->getMock(
319-
'Cake\Controller\Component\BaseAuthorize',
320-
['authorize'],
321-
[],
322-
'',
323-
false
324-
);
315+
$AuthMockOneAuthorize = $this->getMockBuilder('Cake\Controller\Component\BaseAuthorize')
316+
->setMethods(['authorize'])
317+
->disableOriginalConstructor()
318+
->getMock();
325319

326320
$this->Auth->setAuthorizeObject(0, $AuthMockOneAuthorize);
327321
$request = $this->Auth->request;

tests/TestCase/Database/Schema/MysqlSchemaTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,9 @@ public function testCreateSql()
990990
public function testCreateSqlJson()
991991
{
992992
$driver = $this->_getMockedDriver();
993-
$connection = $this->getMock('Cake\Database\Connection', [], [], '', false);
993+
$connection = $this->getMockBuilder('Cake\Database\Connection')
994+
->disableOriginalConstructor()
995+
->getMock();
994996
$connection->expects($this->any())
995997
->method('driver')
996998
->will($this->returnValue($driver));

tests/TestCase/Database/Type/JsonTypeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function setUp()
3333
{
3434
parent::setUp();
3535
$this->type = Type::build('json');
36-
$this->driver = $this->getMock('Cake\Database\Driver');
36+
$this->driver = $this->getMockBuilder('Cake\Database\Driver')->getMock();
3737
}
3838

3939
/**

tests/TestCase/Error/Middleware/ErrorHandlerMiddlewareTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ public function testRendererFactory()
7777
$factory = function ($exception) {
7878
$this->assertInstanceOf('LogicException', $exception);
7979
$cakeResponse = new CakeResponse;
80-
$mock = $this->getMock('StdClass', ['render']);
80+
$mock = $this->getMockBuilder('StdClass')
81+
->setMethods(['render'])
82+
->getMock();
8183
$mock->expects($this->once())
8284
->method('render')
8385
->will($this->returnValue($cakeResponse));
@@ -124,7 +126,9 @@ public function testHandleExceptionRenderingFails()
124126
$response = new Response();
125127

126128
$factory = function ($exception) {
127-
$mock = $this->getMock('StdClass', ['render']);
129+
$mock = $this->getMockBuilder('StdClass')
130+
->setMethods(['render'])
131+
->getMock();
128132
$mock->expects($this->once())
129133
->method('render')
130134
->will($this->throwException(new LogicException('Rendering failed')));

tests/TestCase/Http/ActionDispatcherTest.php

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function setUp()
4949
*/
5050
public function testConstructorArgs()
5151
{
52-
$factory = $this->getMock('Cake\Http\ControllerFactory');
53-
$events = $this->getMock('Cake\Event\EventManager');
52+
$factory = $this->getMockBuilder('Cake\Http\ControllerFactory')->getMock();
53+
$events = $this->getMockBuilder('Cake\Event\EventManager')->getMock();
5454
$dispatcher = new ActionDispatcher($factory, $events);
5555

5656
$this->assertAttributeSame($events, '_eventManager', $dispatcher);
@@ -69,10 +69,9 @@ public function testAddFilter()
6969
$this->assertCount(1, $events->listeners('Dispatcher.beforeDispatch'));
7070
$this->assertCount(1, $events->listeners('Dispatcher.afterDispatch'));
7171

72-
$filter = $this->getMock(
73-
'Cake\Routing\DispatcherFilter',
74-
['beforeDispatch', 'afterDispatch']
75-
);
72+
$filter = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
73+
->setMethods(['beforeDispatch', 'afterDispatch'])
74+
->getMock();
7675
$this->dispatcher->addFilter($filter);
7776

7877
$this->assertCount(2, $this->dispatcher->getFilters());
@@ -89,10 +88,9 @@ public function testBeforeDispatchEventAbort()
8988
{
9089
$response = new Response();
9190
$dispatcher = new ActionDispatcher();
92-
$filter = $this->getMock(
93-
'Cake\Routing\DispatcherFilter',
94-
['beforeDispatch', 'afterDispatch']
95-
);
91+
$filter = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
92+
->setMethods(['beforeDispatch', 'afterDispatch'])
93+
->getMock();
9694
$filter->expects($this->once())
9795
->method('beforeDispatch')
9896
->will($this->returnValue($response));
@@ -111,10 +109,9 @@ public function testBeforeDispatchEventAbort()
111109
*/
112110
public function testDispatchAfterDispatchEventModifyResponse()
113111
{
114-
$filter = $this->getMock(
115-
'Cake\Routing\DispatcherFilter',
116-
['beforeDispatch', 'afterDispatch']
117-
);
112+
$filter = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
113+
->setMethods(['beforeDispatch', 'afterDispatch'])
114+
->getMock();
118115
$filter->expects($this->once())
119116
->method('afterDispatch')
120117
->will($this->returnCallback(function ($event) {
@@ -145,10 +142,9 @@ public function testDispatchAfterDispatchEventModifyResponse()
145142
*/
146143
public function testDispatchActionReturnResponseNoAfterDispatch()
147144
{
148-
$filter = $this->getMock(
149-
'Cake\Routing\DispatcherFilter',
150-
['beforeDispatch', 'afterDispatch']
151-
);
145+
$filter = $this->getMockBuilder('Cake\Routing\DispatcherFilter')
146+
->setMethods(['beforeDispatch', 'afterDispatch'])
147+
->getMock();
152148
$filter->expects($this->never())
153149
->method('afterDispatch');
154150

@@ -271,7 +267,7 @@ public function testMissingController()
271267
'action' => 'home',
272268
]
273269
]);
274-
$response = $this->getMock('Cake\Network\Response');
270+
$response = $this->getMockBuilder('Cake\Network\Response')->getMock();
275271
$this->dispatcher->dispatch($request, $response);
276272
}
277273

@@ -291,7 +287,7 @@ public function testMissingControllerInterface()
291287
'action' => 'index',
292288
]
293289
]);
294-
$response = $this->getMock('Cake\Network\Response');
290+
$response = $this->getMockBuilder('Cake\Network\Response')->getMock();
295291
$this->dispatcher->dispatch($request, $response);
296292
}
297293

@@ -311,7 +307,7 @@ public function testMissingControllerAbstract()
311307
'action' => 'index',
312308
]
313309
]);
314-
$response = $this->getMock('Cake\Network\Response');
310+
$response = $this->getMockBuilder('Cake\Network\Response')->getMock();
315311
$this->dispatcher->dispatch($request, $response);
316312
}
317313

@@ -336,7 +332,7 @@ public function testMissingControllerLowercase()
336332
'pass' => ['home'],
337333
]
338334
]);
339-
$response = $this->getMock('Cake\Network\Response');
335+
$response = $this->getMockBuilder('Cake\Network\Response')->getMock();
340336
$this->dispatcher->dispatch($request, $response);
341337
}
342338

tests/TestCase/Http/ControllerFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function setUp()
3535
parent::setUp();
3636
Configure::write('App.namespace', 'TestApp');
3737
$this->factory = new ControllerFactory();
38-
$this->response = $this->getMock('Cake\Network\Response');
38+
$this->response = $this->getMockBuilder('Cake\Network\Response')->getMock();
3939
}
4040

4141
/**

tests/TestCase/Http/ResponseTransformerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ public function testToPsrBodyCallable()
198198
*/
199199
public function testToPsrBodyFileResponse()
200200
{
201-
$cake = $this->getMock('Cake\Network\Response', ['_clearBuffer']);
201+
$cake = $this->getMockBuilder('Cake\Network\Response')
202+
->setMethods(['_clearBuffer'])
203+
->getMock();
202204
$cake->file(__FILE__, ['name' => 'some-file.php', 'download' => true]);
203205

204206
$result = ResponseTransformer::toPsr($cake);
@@ -225,7 +227,9 @@ public function testToPsrBodyFileResponse()
225227
public function testToPsrBodyFileResponseFileRange()
226228
{
227229
$_SERVER['HTTP_RANGE'] = 'bytes=10-20';
228-
$cake = $this->getMock('Cake\Network\Response', ['_clearBuffer']);
230+
$cake = $this->getMockBuilder('Cake\Network\Response')
231+
->setMethods(['_clearBuffer'])
232+
->getMock();
229233
$path = TEST_APP . 'webroot/css/cake.generic.css';
230234
$cake->file($path, ['name' => 'test-asset.css', 'download' => true]);
231235

tests/TestCase/Http/RunnerTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public function setUp()
5555
public function testRunSingle()
5656
{
5757
$this->stack->push($this->ok);
58-
$req = $this->getMock('Psr\Http\Message\ServerRequestInterface');
59-
$res = $this->getMock('Psr\Http\Message\ResponseInterface');
58+
$req = $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->getMock();
59+
$res = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->getMock();
6060

6161
$runner = new Runner();
6262
$result = $runner->run($this->stack, $req, $res);
@@ -71,14 +71,14 @@ public function testRunSingle()
7171
public function testRunResponseReplace()
7272
{
7373
$one = function ($req, $res, $next) {
74-
$res = $this->getMock('Psr\Http\Message\ResponseInterface');
74+
$res = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->getMock();
7575
return $next($req, $res);
7676
};
7777
$this->stack->push($one);
7878
$runner = new Runner();
7979

80-
$req = $this->getMock('Psr\Http\Message\ServerRequestInterface');
81-
$res = $this->getMock('Psr\Http\Message\ResponseInterface');
80+
$req = $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->getMock();
81+
$res = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->getMock();
8282
$result = $runner->run($this->stack, $req, $res);
8383

8484
$this->assertNotSame($res, $result, 'Response was not replaced');
@@ -108,8 +108,8 @@ public function testRunSequencing()
108108
$this->stack->push($one)->push($two)->push($three);
109109
$runner = new Runner();
110110

111-
$req = $this->getMock('Psr\Http\Message\ServerRequestInterface');
112-
$res = $this->getMock('Psr\Http\Message\ResponseInterface');
111+
$req = $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->getMock();
112+
$res = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->getMock();
113113
$result = $runner->run($this->stack, $req, $res);
114114

115115
$this->assertSame($res, $result, 'Response is not correct');
@@ -127,8 +127,8 @@ public function testRunSequencing()
127127
public function testRunExceptionInMiddleware()
128128
{
129129
$this->stack->push($this->ok)->push($this->fail);
130-
$req = $this->getMock('Psr\Http\Message\ServerRequestInterface');
131-
$res = $this->getMock('Psr\Http\Message\ResponseInterface');
130+
$req = $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->getMock();
131+
$res = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->getMock();
132132

133133
$runner = new Runner();
134134
$runner->run($this->stack, $req, $res);
@@ -142,8 +142,8 @@ public function testRunExceptionInMiddleware()
142142
public function testRunNextNotCalled()
143143
{
144144
$this->stack->push($this->noNext);
145-
$req = $this->getMock('Psr\Http\Message\ServerRequestInterface');
146-
$res = $this->getMock('Psr\Http\Message\ResponseInterface');
145+
$req = $this->getMockBuilder('Psr\Http\Message\ServerRequestInterface')->getMock();
146+
$res = $this->getMockBuilder('Psr\Http\Message\ResponseInterface')->getMock();
147147

148148
$runner = new Runner();
149149
$result = $runner->run($this->stack, $req, $res);

tests/TestCase/Http/ServerTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public function tearDown()
5757
*/
5858
public function testAppGetSet()
5959
{
60-
$app = $this->getMock('Cake\Http\BaseApplication', [], [$this->config]);
60+
$app = $this->getMockBuilder('Cake\Http\BaseApplication')
61+
->setConstructorArgs([$this->config])
62+
->getMock();
6163
$server = new Server($app);
6264
$this->assertSame($app, $server->getApp($app));
6365
}
@@ -160,7 +162,7 @@ public function testEmit()
160162
->withHeader('X-First', 'first')
161163
->withHeader('X-Second', 'second');
162164

163-
$emitter = $this->getMock('Zend\Diactoros\Response\EmitterInterface');
165+
$emitter = $this->getMockBuilder('Zend\Diactoros\Response\EmitterInterface')->getMock();
164166
$emitter->expects($this->once())
165167
->method('emit')
166168
->with($final);

0 commit comments

Comments
 (0)