Skip to content
Permalink
Browse files

Fix tests that relied on protected methods.

Don't use mocks when we can use the real deal.
  • Loading branch information...
markstory committed Sep 8, 2016
1 parent 169ee49 commit e9f7c4127a71f335b0def5d3a304b06e0a183084
Showing with 9 additions and 32 deletions.
  1. +9 −32 tests/TestCase/Controller/Component/RequestHandlerComponentTest.php
@@ -478,9 +478,7 @@ public function testStartupCallback()
$event = new Event('Controller.beforeRender', $this->Controller);
$_SERVER['REQUEST_METHOD'] = 'PUT';
$_SERVER['CONTENT_TYPE'] = 'application/xml';
$this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
->setMethods(['_readInput'])
->getMock();
$this->Controller->request = new Request();
$this->RequestHandler->beforeRender($event);
$this->assertTrue(is_array($this->Controller->request->data));
$this->assertFalse(is_object($this->Controller->request->data));
@@ -497,9 +495,7 @@ public function testStartupCallbackCharset()
$event = new Event('Controller.startup', $this->Controller);
$_SERVER['REQUEST_METHOD'] = 'PUT';
$_SERVER['CONTENT_TYPE'] = 'application/xml; charset=UTF-8';
$this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
->setMethods(['_readInput'])
->getMock();
$this->Controller->request = new Request();
$this->RequestHandler->startup($event);
$this->assertTrue(is_array($this->Controller->request->data));
$this->assertFalse(is_object($this->Controller->request->data));
@@ -513,29 +509,19 @@ public function testStartupCallbackCharset()
*/
public function testStartupProcessData()
{
$this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
->setMethods(['_readInput'])
->getMock();
$this->Controller->request->expects($this->at(0))
->method('_readInput')
->will($this->returnValue(''));
$this->Controller->request->expects($this->at(1))
->method('_readInput')
->will($this->returnValue('"invalid"'));
$this->Controller->request->expects($this->at(2))
->method('_readInput')
->will($this->returnValue('{"valid":true}'));
$this->Controller->request = new Request();
$this->Controller->request->env('REQUEST_METHOD', 'POST');
$this->Controller->request->env('CONTENT_TYPE', 'application/json');
$event = new Event('Controller.startup', $this->Controller);
$this->RequestHandler->startup($event);
$this->assertEquals([], $this->Controller->request->data);
$this->Controller->request->setInput('"invalid"');
$this->RequestHandler->startup($event);
$this->assertEquals(['invalid'], $this->Controller->request->data);
$this->Controller->request->setInput('{"valid":true}');
$this->RequestHandler->startup($event);
$this->assertEquals(['valid' => true], $this->Controller->request->data);
}
@@ -548,13 +534,7 @@ public function testStartupProcessData()
*/
public function testStartupIgnoreFileAsXml()
{
$this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
->setMethods(['_readInput'])
->getMock();
$this->Controller->request->expects($this->any())
->method('_readInput')
->will($this->returnValue('/dev/random'));
$this->Controller->request = new Request(['input' => '/dev/random']);
$this->Controller->request->env('REQUEST_METHOD', 'POST');
$this->Controller->request->env('CONTENT_TYPE', 'application/xml');
@@ -572,12 +552,9 @@ public function testStartupIgnoreFileAsXml()
public function testStartupCustomTypeProcess()
{
$restore = error_reporting(E_ALL & ~E_USER_DEPRECATED);
$this->Controller->request = $this->getMockBuilder('Cake\Network\Request')
->setMethods(['_readInput'])
->getMock();
$this->Controller->request->expects($this->once())
->method('_readInput')
->will($this->returnValue('"A","csv","string"'));
$this->Controller->request = new Request([
'input' => '"A","csv","string"'
]);
$this->RequestHandler->addInputType('csv', ['str_getcsv']);
$this->Controller->request->env('REQUEST_METHOD', 'POST');
$this->Controller->request->env('CONTENT_TYPE', 'text/csv');

0 comments on commit e9f7c41

Please sign in to comment.
You can’t perform that action at this time.