Beispiel #1
0
 /**
  * Using a writer with a blocking filter
  */
 public function testNoPassFilters()
 {
     $config = array('mute' => false, 'url' => 'php://memory', 'filters' => array(array('DiscoBouncer' => array())));
     $logEvent = LogEvent::create(ILogger::LEVEL_ERROR, 'Shut up', array(), 'PHPUnit');
     $writer = new Stream($config);
     $writer->log($logEvent);
     $stream = $writer->getStream();
     fseek($stream, 0);
     $this->assertEmpty(stream_get_contents($stream));
 }
Beispiel #2
0
 /**
  * php://memory doesn't support locking, but as flock() is a PHP core method
  * I don't really have to unit test it. I pretty much stole a demo wrapper from the PHP documentation
  * and made lie that it supports locking...
  */
 public function testLogWithLock()
 {
     require_once __DIR__ . '/../StreamWrapper/VariableStream.php';
     stream_wrapper_register("globalz", "Zalora\\Punyan\\StreamWrapper\\VariableStream");
     $config = array('lock' => true, 'mute' => false, 'url' => 'globalz://foobar', 'filters' => array());
     $logEvent = LogEvent::create(ILogger::LEVEL_ERROR, 'Hello Streams', array(), 'PHPUnit');
     $formatter = new Bunyan();
     $writer = new Stream($config);
     $writer->log($logEvent);
     $stream = $writer->getStream();
     fseek($stream, 0);
     $this->assertSame($formatter->format($logEvent), stream_get_contents($stream));
 }
Beispiel #3
0
 /**
  * Run the process method and watch it do nothing
  */
 public function testProcess()
 {
     $configWithoutProcessor = array('url' => 'php://memory', 'filters' => array());
     $configWithProcessor = array('url' => 'php://memory', 'filters' => array(), 'processors' => array(array('NoOp' => array())));
     $logEvent = LogEvent::create(ILogger::LEVEL_INFO, 'Hello PHPUnit', array('time' => time()), 'PHPUnit');
     $writerWithoutProcessor = new Stream($configWithoutProcessor);
     $writerWithProcessor = new Stream($configWithProcessor);
     $writerWithoutProcessor->log($logEvent);
     $writerWithProcessor->log($logEvent);
     $output = array();
     $output[] = stream_get_contents($writerWithoutProcessor->getStream(), -1, 0);
     $output[] = stream_get_contents($writerWithProcessor->getStream(), -1, 0);
     // Prove that NoOp doesn't do shit
     $this->assertEquals($output[0], $output[1]);
 }
Beispiel #4
0
 /**
  * The processor should filter out all variables, because they were added to the original $_SERVER array
  */
 public function testProcessWithFakeVariables()
 {
     $config = array('url' => 'php://memory', 'filters' => array(), 'processors' => array(array('Web' => array())));
     /*
      * As there are not many web related variables in $_SERVER when running on CLI, we fake them...
      */
     $server['REQUEST_URI'] = '/test.php';
     $server['REQUEST_METHOD'] = 'HUSTLE';
     $server['SERVER_NAME'] = gethostname();
     $server['HTTP_REFERER'] = 'https://duckduckgo.com/?q=zalora+singapore';
     $_SERVER = array_merge($_SERVER, $server);
     $logEvent = LogEvent::create(ILogger::LEVEL_INFO, 'Hello PHPUnit', array('time' => time()), 'PHPUnit');
     $writer = new Stream($config);
     $writer->log($logEvent);
     $output = stream_get_contents($writer->getStream(), -1, 0);
     $this->assertJson($output);
     $outArr = json_decode($output, true);
     $this->assertArrayNotHasKey(IProcessor::PROCESSOR_DATA_KEY, $outArr);
 }