Beispiel #1
0
 public function testDecoratorDestruct()
 {
     new LogDecorator(new Component(), $this->monolog);
     $this->assertTrue($this->handler->hasDebugRecords());
     $this->assertFalse($this->handler->hasInfoRecords());
     $this->assertCount(2, $this->handler->getRecords());
 }
Beispiel #2
0
 public function testProcessNoData()
 {
     $logHandler = new \Monolog\Handler\TestHandler();
     $logger = new \Monolog\Logger('test', [$logHandler]);
     Logger::setLogger($logger);
     $parser = new Json(Parser::create($logger));
     $parser->process([], 'empty');
     self::assertTrue($logHandler->hasDebug("No data returned in 'empty'"));
 }
Beispiel #3
0
 public function testProcessorRecords()
 {
     $Handler = new \Monolog\Handler\TestHandler();
     $config = array('rules' => array('*' => array('error' => array('handler' => array('error-handler'), 'processor' => array('uid')))), 'handler' => array('error-handler' => $Handler), 'processor' => array('uid' => array('type' => 'Monolog\\Processor\\UidProcessor', 'args' => array())));
     Monoconf::config($config);
     $Logger = Monoconf::getLogger('MyApp\\Other\\Class');
     $Logger->error('foo');
     $this->assertTrue($Handler->hasErrorRecords('foo'));
     $records = $Handler->getRecords();
     $this->assertTrue(isset($records[0]['extra']['uid']));
 }
 public function testOverringDefaultFunctionalityWithEvents()
 {
     $log = new Logger('emails');
     // should only have a database handler.
     $this->assertEquals(count($log->getHandlers()), 1);
     $this->assertEquals(count(Log::getHandlers()), 2);
     // this should still have the same stream handler from last test.
     $handler = new \Monolog\Handler\TestHandler(Logger::CRITICAL, false);
     $listener = Events::addListener('on_logger_create', function ($event) use($handler) {
         $logger = $event->getLogger();
         $formatter = new \Monolog\Formatter\LineFormatter();
         $handler->setFormatter($formatter);
         $logger->pushHandler($handler);
         return $logger;
     });
     $log2 = new Logger('transactions');
     $log3 = new Logger('testing');
     $this->assertEquals(count($log2->getHandlers()), 2);
     $this->assertEquals(count($log3->getHandlers()), 2);
     $log2->info('This is a test.');
     $log2->debug('This is a test.');
     $log3->debug('This is a test.');
     $log3->critical("oh boy this is big.");
     $log3->alert("Everything is broken.");
     $log3->emergency("Get out of bed.");
     $db = Database::get();
     $r = $db->GetAll('select * from Logs');
     $this->assertEquals(count($r), 3);
     // only the non-critical, non-alert, non-emergency items.
     $this->assertEquals(count($handler->getRecords()), 3);
     $records = $handler->getRecords();
     $this->assertEquals($records[0]['level'], Logger::CRITICAL);
     $this->assertEquals($records[1]['level'], Logger::ALERT);
     $this->assertEquals($records[2]['level'], Logger::EMERGENCY);
     $this->assertEquals($records[2]['message'], 'Get out of bed.');
     $listeners = Events::getListeners('on_logger_create');
     Events::removeListener('on_logger_create', $listeners[0]);
     // AND we pop the stream handler from the previous test
     Log::popHandler();
 }
 public function testNestedArrays()
 {
     $logHandler = new \Monolog\Handler\TestHandler();
     $parser = Parser::create(new \Monolog\Logger('test', [$logHandler]));
     $parser->getAnalyzer()->setNestedArrayAsJson(true);
     $data = [[1, 2, 3, [7, 8]], [4, 5, 6]];
     $parser->process($data);
     self::assertEquals(true, $logHandler->hasWarning("Unsupported array nesting in 'root'! Converting to JSON string."), "Warning should have been logged");
     self::assertEquals(file_get_contents($this->getDataDir() . 'NestedArraysJson.csv'), file_get_contents($parser->getCsvFiles()['root']));
 }
Beispiel #6
0
 /**
  * Cannot use dataProvider because that gets set up before all tests
  * and the delay causes issues
  */
 public function testCurlBackoff()
 {
     // mapped curl error
     $retries = 3;
     $handler = new \Monolog\Handler\TestHandler();
     $logger = new \Monolog\Logger("test", [$handler]);
     Logger::setLogger($logger);
     $client = RestClient::create([], ['maxRetries' => $retries, 'curl' => ['codes' => [6]]]);
     try {
         $client->download(new RestRequest('http://keboolakeboolakeboola.com'));
         $this->fail("Request shoul fail");
     } catch (\Exception $e) {
         $this->assertCount($retries, $handler->getRecords());
         foreach ($handler->getRecords() as $record) {
             $this->assertEquals(100, $record['level']);
             $this->assertRegExp('/retrying/ui', $record['message']);
             $this->assertRegExp('/curl error 6\\:/ui', $record['context']['message']);
         }
         $this->assertRegExp('/curl error 6\\:/ui', $e->getMessage());
         $this->assertTrue($e instanceof \Keboola\Juicer\Exception\UserException);
     }
     // non-mapped curl error
     $retries = 3;
     $handler = new \Monolog\Handler\TestHandler();
     $logger = new \Monolog\Logger("test", [$handler]);
     Logger::setLogger($logger);
     $client = RestClient::create([], ['maxRetries' => $retries, 'curl' => ['codes' => [77]]]);
     try {
         $client->download(new RestRequest('http://keboolakeboolakeboola.com'));
         $this->fail("Request shoul fail");
     } catch (\Exception $e) {
         $this->assertCount(0, $handler->getRecords());
         $this->assertRegExp('/curl error 6\\:/ui', $e->getMessage());
         $this->assertTrue($e instanceof \Keboola\Juicer\Exception\UserException);
     }
 }