Consider the following class:
<?php
namespace EveOnline\Logging;
use Log;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
class EveLogHandler {
public function requestLog($response, $fileName) {
$streamHandler = new StreamHandler(storage_path($fileName), Logger::INFO);
$logInstance = Log::getMonolog();
$logInstance->setHandlers(array($streamHandler));
$logInstance->addInfo('Fetched', [$response->getStatusCode(), $response->getBody()->getContents()]);
$response->getBody()->rewind();
}
public function messageLog($message, $fileName) {
$streamHandler = new StreamHandler(storage_path($fileName), Logger::INFO);
$logInstance = Log::getMonolog();
$logInstance->setHandlers(array($streamHandler));
$logInstance->addInfo('Message', [$message]);
}
}
Now this is used in my library I am building to log out guzzle responses and up until now I have been mocking out this class with its methods.
Two things:
How do you test it? Like how would I test this class? How do I verify that a file was written to or do I?
Second part and most important storage_path is a laravel global function. This library is separate of laravel. But is intended to be used with laravel. So how do I get around this function ??
Aucun commentaire:
Enregistrer un commentaire