PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 1ms

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