<commit_before><?php

// TODO: Document!
class Prack_Utils_LoggerTest extends PHPUnit_Framework_TestCase 
{
	/**
	 * It should know its level
	 * @author <NAME>
	 * @test
	 */
	public function It_should_know_its_level()
	{
		$logger = Prb_Logger::with( Prb_IO::withString() );
		$this->assertEquals( Prb_Logger::DEBUG, $logger->getLevel() );
		
		$this->assertTrue( $logger->logsDebug()   );
		$this->assertTrue( $logger->logsInfo()    );
		$this->assertTrue( $logger->logsWarn()    );
		$this->assertTrue( $logger->logsError()   );
		$this->assertTrue( $logger->logsFatal()   );
		$this->assertTrue( $logger->logsUnknown() );
		
		$logger->setLevel( Prb_Logger::INFO );
		$this->assertFalse( $logger->logsDebug()   );
		$this->assertTrue ( $logger->logsInfo()    );
		$this->assertTrue ( $logger->logsWarn()    );
		$this->assertTrue ( $logger->logsError()   );
		$this->assertTrue ( $logger->logsFatal()   );
		$this->assertTrue ( $logger->logsUnknown() );
		
		$logger->setLevel( Prb_Logger::WARN );
		$this->assertFalse( $logger->logsDebug()   );
		$this->assertFalse( $logger->logsInfo()    );
		$this->assertTrue ( $logger->logsWarn()    );
		$this->assertTrue ( $logger->logsError()   );
		$this->assertTrue ( $logger->logsFatal()   );
		$this->assertTrue ( $logger->logsUnknown() );
		
		$logger->setLevel( Prb_Logger::ERROR );
		$this->assertFalse( $logger->logsDebug()   );
		$this->assertFalse( $logger->logsInfo()    );
		$this->assertFalse( $logger->logsWarn()    );
		$this->assertTrue ( $logger->logsError()   );
		$this->assertTrue ( $logger->logsFatal()   );
		$this->assertTrue ( $logger->logsUnknown() );
		
		$logger->setLevel( Prb_Logger::FATAL );
		$this->assertFalse( $logger->logsDebug()   );
		$this->assertFalse( $logger->logsInfo()    );
		$this->assertFalse( $logger->logsWarn()    );
		$this->assertFalse( $logger->logsError()   );
		$this->assertTrue ( $logger->logsFatal()   );
		$this->assertTrue ( $logger->logsUnknown() );
		
		$logger->setLevel( Prb_Logger::UNKNOWN );
		$this->assertFalse( $logger->logsDebug()   );
		$this->assertFalse( $logger->logsInfo()    );
		$this->assertFalse( $logger->logsWarn()    );
		$this->assertFalse( $logger->logsError()   );
		$this->assertFalse( $logger->logsFatal()   );
		$this->assertTrue ( $logger->logsUnknown() );
	} // It should know its level
	
	/**
	 * It should log messages of appropriate severity
	 * @author <NAME>
	 * @test
	 */
	public function It_should_log_messages_of_appropriate_severity()
	{
		$io     = Prb_IO::withString();
		$logger = Prb_Logger::with( $io );
		
		$logger->warn( Prb::_String( 'error lol' ) );
		$io->rewind();
		$this->assertTrue( $io->read()->match( '/error lol/' ) );
	} // It should log messages of appropriate severity
	
	/**
	 * It should not log messages of inappropriate severity
	 * @author <NAME>
	 * @test
	 */
	public function It_should_not_log_messages_of_inappropriate_severity()
	{
		$io     = Prb_IO::withString();
		$logger = Prb_Logger::with( $io );
		$logger->setLevel( Prb_Logger::UNKNOWN + 1 );
		$error  = Prb::_String( 'error lol' );
		
		$logger->debug( $error );
		$io->rewind();
		$this->assertFalse( $io->read()->match( '/error lol/' ) );
		
		$logger->info( $error );
		$io->rewind();
		$this->assertFalse( $io->read()->match( '/error lol/' ) );
		
		$logger->warn( $error );
		$io->rewind();
		$this->assertFalse( $io->read()->match( '/error lol/' ) );
		
		$logger->error( $error );
		$io->rewind();
		$this->assertFalse( $io->read()->match( '/error lol/' ) );
		
		$logger->fatal( $error );
		$io->rewind();
		$this->assertFalse( $io->read()->match( '/error lol/' ) );
		
		$logger->unknown( $error );
		$io->rewind();
		$this->assertFalse( $io->read()->match( '/error lol/' ) );
	} // It should not log messages of inappropriate severity
	
	/**
	 * It should alias method add to log
	 * @author <NAME>
	 * @test
	 */
	public function It_should_alias_method_add_to_log()
	{
		$io     = Prb_IO::withString();
		$logger = Prb_Logger::with( $io );
		
		$logger->log( Prb_Logger::WARN, Prb::_String( 'error lol' ) );
		$io->rewind();
		
		$this->assertTrue( $io->read()->match( '/error lol/' ) );
	} // It should alias method add to log
	
	/**
	 * It should allow direct concatenation to the device
	 * @author <NAME>
	 * @test
	 */
	public function It_should_allow_direct_concatenation_to_the_device()
	{
		$io     = Prb_IO::withString();
		$logger = Prb_Logger::with( $io );
		
		$logger->concat( Prb::_String( 'error lol' ) );
		$io->rewind();
		
		$this->assertTrue( $io->read()->match( '/error lol/' ) );
	} // It should allow direct concatenation to the device
	
	/**
	 * It should allow direct setting of the default formatter's datetime format
	 * @author <NAME>
	 * @test
	 */
	public function It_should_allow_direct_setting_of_the_default_formatter_s_datetime_format()
	{
		$io     = Prb_IO::withString();
		$dtf    = Prb::_String( '%H' );
		$logger = Prb_Logger::with( $io );
		
		$logger->setDatetimeFormat( $dtf );
		$this->assertSame( $logger->getDatetimeFormat(), $dtf );
		
		$logger->info( Prb::_String( 'hello' ) );
		$io->rewind();
		$this->assertTrue( $io->read()->match( '/\[\d\d#\d{5}\].*hello/' ) );
	} // It should allow direct setting of the default formatter's datetime format
	
	/**
	 * It should allow setting of the formatter to use for logging
	 * @author <NAME>
	 * @test
	 */
	public function It_should_allow_setting_of_the_formatter_to_use_for_logging()
	{
		$mock_formatter = $this->getMock( 'Formatter', array( 'call' ) );
		$mock_formatter->expects( $this->once() )
		               ->method( 'call' )
		               ->will( $this->returnValue( Prb::_String() ) );
		
		$logger = Prb_Logger::with( Prb_IO::withString() );
		$logger->setFormatter( $mock_formatter );
		$logger->log( Prb_Logger::INFO, Prb::_String( 'hello world' ) );
		$this->assertSame( $mock_formatter, $logger->getFormatter() );
	} // It should allow setting of the formatter to use for logging
}<commit_msg>Prb_Logger: edge case in logger with pid less than 5 digits.<commit_after><?php

// TODO: Document!
class Prack_Utils_LoggerTest extends PHPUnit_Framework_TestCase 
{
	/**
	 * It should know its level
	 * @author <NAME>
	 * @test
	 */
	public function It_should_know_its_level()
	{
		$logger = Prb_Logger::with( Prb_IO::withString() );
		$this->assertEquals( Prb_Logger::DEBUG, $logger->getLevel() );
		
		$this->assertTrue( $logger->logsDebug()   );
		$this->assertTrue( $logger->logsInfo()    );
		$this->assertTrue( $logger->logsWarn()    );
		$this->assertTrue( $logger->logsError()   );
		$this->assertTrue( $logger->logsFatal()   );
		$this->assertTrue( $logger->logsUnknown() );
		
		$logger->setLevel( Prb_Logger::INFO );
		$this->assertFalse( $logger->logsDebug()   );
		$this->assertTrue ( $logger->logsInfo()    );
		$this->assertTrue ( $logger->logsWarn()    );
		$this->assertTrue ( $logger->logsError()   );
		$this->assertTrue ( $logger->logsFatal()   );
		$this->assertTrue ( $logger->logsUnknown() );
		
		$logger->setLevel( Prb_Logger::WARN );
		$this->assertFalse( $logger->logsDebug()   );
		$this->assertFalse( $logger->logsInfo()    );
		$this->assertTrue ( $logger->logsWarn()    );
		$this->assertTrue ( $logger->logsError()   );
		$this->assertTrue ( $logger->logsFatal()   );
		$this->assertTrue ( $logger->logsUnknown() );
		
		$logger->setLevel( Prb_Logger::ERROR );
		$this->assertFalse( $logger->logsDebug()   );
		$this->assertFalse( $logger->logsInfo()    );
		$this->assertFalse( $logger->logsWarn()    );
		$this->assertTrue ( $logger->logsError()   );
		$this->assertTrue ( $logger->logsFatal()   );
		$this->assertTrue ( $logger->logsUnknown() );
		
		$logger->setLevel( Prb_Logger::FATAL );
		$this->assertFalse( $logger->logsDebug()   );
		$this->assertFalse( $logger->logsInfo()    );
		$this->assertFalse( $logger->logsWarn()    );
		$this->assertFalse( $logger->logsError()   );
		$this->assertTrue ( $logger->logsFatal()   );
		$this->assertTrue ( $logger->logsUnknown() );
		
		$logger->setLevel( Prb_Logger::UNKNOWN );
		$this->assertFalse( $logger->logsDebug()   );
		$this->assertFalse( $logger->logsInfo()    );
		$this->assertFalse( $logger->logsWarn()    );
		$this->assertFalse( $logger->logsError()   );
		$this->assertFalse( $logger->logsFatal()   );
		$this->assertTrue ( $logger->logsUnknown() );
	} // It should know its level
	
	/**
	 * It should log messages of appropriate severity
	 * @author <NAME>
	 * @test
	 */
	public function It_should_log_messages_of_appropriate_severity()
	{
		$io     = Prb_IO::withString();
		$logger = Prb_Logger::with( $io );
		
		$logger->warn( Prb::_String( 'error lol' ) );
		$io->rewind();
		$this->assertTrue( $io->read()->match( '/error lol/' ) );
	} // It should log messages of appropriate severity
	
	/**
	 * It should not log messages of inappropriate severity
	 * @author <NAME>
	 * @test
	 */
	public function It_should_not_log_messages_of_inappropriate_severity()
	{
		$io     = Prb_IO::withString();
		$logger = Prb_Logger::with( $io );
		$logger->setLevel( Prb_Logger::UNKNOWN + 1 );
		$error  = Prb::_String( 'error lol' );
		
		$logger->debug( $error );
		$io->rewind();
		$this->assertFalse( $io->read()->match( '/error lol/' ) );
		
		$logger->info( $error );
		$io->rewind();
		$this->assertFalse( $io->read()->match( '/error lol/' ) );
		
		$logger->warn( $error );
		$io->rewind();
		$this->assertFalse( $io->read()->match( '/error lol/' ) );
		
		$logger->error( $error );
		$io->rewind();
		$this->assertFalse( $io->read()->match( '/error lol/' ) );
		
		$logger->fatal( $error );
		$io->rewind();
		$this->assertFalse( $io->read()->match( '/error lol/' ) );
		
		$logger->unknown( $error );
		$io->rewind();
		$this->assertFalse( $io->read()->match( '/error lol/' ) );
	} // It should not log messages of inappropriate severity
	
	/**
	 * It should alias method add to log
	 * @author <NAME>
	 * @test
	 */
	public function It_should_alias_method_add_to_log()
	{
		$io     = Prb_IO::withString();
		$logger = Prb_Logger::with( $io );
		
		$logger->log( Prb_Logger::WARN, Prb::_String( 'error lol' ) );
		$io->rewind();
		
		$this->assertTrue( $io->read()->match( '/error lol/' ) );
	} // It should alias method add to log
	
	/**
	 * It should allow direct concatenation to the device
	 * @author <NAME>
	 * @test
	 */
	public function It_should_allow_direct_concatenation_to_the_device()
	{
		$io     = Prb_IO::withString();
		$logger = Prb_Logger::with( $io );
		
		$logger->concat( Prb::_String( 'error lol' ) );
		$io->rewind();
		
		$this->assertTrue( $io->read()->match( '/error lol/' ) );
	} // It should allow direct concatenation to the device
	
	/**
	 * It should allow direct setting of the default formatter's datetime format
	 * @author <NAME>
	 * @test
	 */
	public function It_should_allow_direct_setting_of_the_default_formatter_s_datetime_format()
	{
		$io     = Prb_IO::withString();
		$dtf    = Prb::_String( '%H' );
		$logger = Prb_Logger::with( $io );
		
		$logger->setDatetimeFormat( $dtf );
		$this->assertSame( $logger->getDatetimeFormat(), $dtf );
		
		$logger->info( Prb::_String( 'hello' ) );
		$io->rewind();
		$this->assertTrue( $io->read()->match( '/\[\d\d#\d{1,5}\].*hello/' ) );
	} // It should allow direct setting of the default formatter's datetime format
	
	/**
	 * It should allow setting of the formatter to use for logging
	 * @author <NAME>
	 * @test
	 */
	public function It_should_allow_setting_of_the_formatter_to_use_for_logging()
	{
		$mock_formatter = $this->getMock( 'Formatter', array( 'call' ) );
		$mock_formatter->expects( $this->once() )
		               ->method( 'call' )
		               ->will( $this->returnValue( Prb::_String() ) );
		
		$logger = Prb_Logger::with( Prb_IO::withString() );
		$logger->setFormatter( $mock_formatter );
		$logger->log( Prb_Logger::INFO, Prb::_String( 'hello world' ) );
		$this->assertSame( $mock_formatter, $logger->getFormatter() );
	} // It should allow setting of the formatter to use for logging
}
{'fraction_non_alphanumeric': 0.19578489587689218, 'fraction_numerical': 0.000501798109893786, 'mean_word_length': 3.7414750198255353, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 303, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '782874', 'n_tokens_mistral': 4395, 'n_tokens_neox': 4019, 'n_words': 796}