PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/LogShutdownTest.php

https://github.com/pop/pop_log
PHP | 29 lines | 24 code | 2 blank | 3 comment | 0 complexity | ec4e2b6a6b8cc7b780b30bef5c9ae035 MD5 | raw file
  1. <?php
  2. require_once dirname(__FILE__).'/../../padrino/src/PadrinoTestCase.php';
  3. class LogShutdownTest extends PadrinoTestCase{
  4. public function testExceptionEvent(){
  5. $dir = dirname(__FILE__).'/_temp_';
  6. PurFile::delete($dir);
  7. ob_start();
  8. passthru('php '.dirname(__FILE__).'/LogShutdownTest/log.php 2>/dev/null');
  9. $stdout = ob_get_contents();
  10. ob_end_clean();
  11. // Check script execution
  12. $stdout = preg_replace('/\/.*?log\.php/','log.php',trim($stdout));
  13. // Note: xdebug add a stack strace, so only assert the first line
  14. preg_match('/.*/',$stdout,$matches);
  15. $this->assertSame('Fatal error: Maximum execution time of 1 second exceeded in log.php on line 23',$matches[0]);
  16. // Validate log content
  17. $expect = PurFile::read(dirname(__FILE__).'/LogShutdownTest/expect.log');
  18. $expect = preg_replace('/(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} GMT)/','{date}',$expect);
  19. $assert = PurFile::read($dir.'/error.log');
  20. $assert = preg_replace('/(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} GMT)/','{date}',$assert);
  21. $this->assertSame(
  22. $expect,
  23. $assert
  24. );
  25. PurFile::delete($dir);
  26. }
  27. }