Пример #1
0
 /**
  * @test
  */
 public function logObserver()
 {
     $observer = new LogObserver(FileLog::init(self::LOG_PATH));
     $provider = new NullProvider();
     $provider->attach($observer);
     $provider->getPosts();
     $file = file(self::LOG_PATH);
     $this->assertEquals(count($file), count($provider->exceptions));
 }
Пример #2
0
 /**
  * @test
  */
 public function addLog()
 {
     $date = new \DateTime();
     $logger = FileLog::init(self::LOG_PATH);
     $logger->add(FileLog::ERROR, 'Something is broken #1.', $date);
     $logger->add(FileLog::WARNING, 'Something is broken #2.', $date);
     $logger->add(FileLog::INFO, 'Something is broken #3.', $date);
     $messages = [sprintf("[error] %s | Something is broken #1.\n", $date->format(FileLog::$format)), sprintf("[warning] %s | Something is broken #2.\n", $date->format(FileLog::$format)), sprintf("[info] %s | Something is broken #3.\n", $date->format(FileLog::$format))];
     $file = file(self::LOG_PATH);
     $this->assertEquals($file[0], $messages[0]);
     $this->assertEquals($file[1], $messages[1]);
     $this->assertEquals($file[2], $messages[2]);
 }
Пример #3
0
use DataAggregator\Log\FileLog;
use DataAggregator\Observer\ReportObserver;
use DataAggregator\Observer\StoreObserver;
use DataAggregator\Observer\LogObserver;
$connection = new AMQPConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
$channel->queue_declare('task_aggregator3', false, true, false, false);
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
$callback = function ($msg) {
    $pathToReportFile = __DIR__ . '/report/' . $msg->body . '.txt';
    $pathToLogFile = __DIR__ . '/log/logs.txt';
    $token = 'CAACEdEose0cBAFZC99yIEZA6oJyz0QGgu95JYZAqcmVIl8warmNCBsfqwOTw60LaPJNHlhDzOR4jd4dUtvZA8YrXXTpvkYVjQU3xzenQZC5zOX9YtMB2nbJtup43o7RQD2CZB6XMO2IIPAI3lYmAGBBPMLM1W8sQNsOqpOnsXsvL0hBRDVNBCVZAwnA2qnx6a4YKqjVo5YCKAeRqq21vb6W';
    $config = ['facebook' => ['facebook_id' => $msg->body, 'access_token' => $token]];
    $dbConfig = ['db' => 'fake_db', 'host' => 'localhost', 'user' => 'fake_user', 'password' => 'fake_password'];
    /** @var LogInterface $logger */
    $logger = FileLog::init($pathToLogFile);
    $observers = [new StoreObserver(new MySqlStore($dbConfig), $logger), new ReportObserver(new TextReport($pathToReportFile), $logger), new LogObserver($logger)];
    $provider = Provider::factory('facebook', $config, $observers);
    $provider->getPosts();
    echo " [x] Received ", $msg->body, " contact.\n";
    echo " [x] Done", "\n";
    $logger->add(LogInterface::INFO, sprintf("Feeds for contact %s have been parsed properly.", $msg->body));
    $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
};
$channel->basic_qos(null, 1, null);
$channel->basic_consume('task_aggregator3', '', false, false, false, false, $callback);
while (count($channel->callbacks)) {
    $channel->wait();
}
$channel->close();
$connection->close();