Skip to content

Instantly share code, notes, and snippets.

@beez
Created April 7, 2015 09:49
Show Gist options
  • Save beez/6f9ee89538d1a6be6dfb to your computer and use it in GitHub Desktop.
Save beez/6f9ee89538d1a6be6dfb to your computer and use it in GitHub Desktop.
App::uses('ChannelsController', 'Epg.Controller');
class ChannelsControllerTest extends ControllerTestCase {
public function setUp() {
parent::setUp();
$this->Controller = $this->generate('Epg.Channels', ['components' => ['Auth' => ['_apiLoginRequest']]]);
$httpSocketResponseBody = new HttpSocketResponse();
$httpSocketResponseBody->code = 200;
$httpSocketResponseBody->body = '{"UserLogin": "UserOne"}';
$this->Controller->Auth
->expects($this->any())
->method('_apiLoginRequest')
->will($this->returnValue($httpSocketResponseBody));
}
}
public function testViewChannel() {
var_dump($this->Controller->Auth->_apiLoginRequest()); // Uses the mock and dumps "['body' => '{"UserLogin": "UserOne"}']"
$result = $this->testAction('/channels/view/2.json', ['method' => 'GET']); // Doesn't uses the mock and therefore gets an error from the auth component
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment