Navigation Menu

Skip to content

Commit

Permalink
Fix tests that relied on protected methods.
Browse files Browse the repository at this point in the history
Don't use mocks when we can use the real deal.
  • Loading branch information
markstory committed Sep 8, 2016
1 parent 169ee49 commit e9f7c41
Showing 1 changed file with 9 additions and 32 deletions.
Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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);
}
Expand All @@ -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');

Expand All @@ -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');
Expand Down

0 comments on commit e9f7c41

Please sign in to comment.