So I am not sure what I am doing wrong but:
class Details {
public function details($href) {
$client = new Client();
$eveLog = new EveLogHandler();
$response = $client->request('GET', $href);
$eveLog->requestLog($response, 'eveonline_item_details.log');
if ($response->getStatusCode() === 200) {
return json_decode($response->getBody()->getContents());
}
return false;
}
}
I want to mock this: $eveLog->requestLog($response, 'eveonline_item_details.log');
So I wrote a test:
class DetailsTest extends \PHPUnit_Framework_TestCase {
public function getLogMock() {
return $this->getMockBuilder('EveOnline\Logging\EveLogHandler')
->setMethods(['requestLog'])
->getMock();
}
public function testDetailsDoesNotReturnFalse() {
$details = new EveOnline\Items\Details();
$logger = $this->getLogMock();
$logger->expects($this->exactly(1))
->method('requestLog')
->with('request', 'request.log');
$response = $details->details('http://example.com');
$this->assertNotFalse($response);
}
}
Accept it doesnt mock the method call, instead it freaks out with an error:
1) DetailsTest::testDetailsDoesNotReturnFalse
Error: Call to undefined function EveOnline\Logging\storage_path()
Now this method: storage_path
is a laravel method and since this library is out side of laravel, for development purposes, the method doesn't exist, hence me trying to mock the call to: $eveLog->requestLog($response, 'eveonline_item_details.log');
Two questions arise from this:
- First of all why doesn't my test pick up on the fact that I have mocked the method call?
- When it coms time to test this particular method how do you mock global functions? Laravel has a few of them and I'll need mock out the
storage_path
method.
Ideas?
Aucun commentaire:
Enregistrer un commentaire