/** * Test the Joomla\Log\Log::setInstance method to make sure that if we set a logger instance Joomla\Log\Log is actually going * to use it. We accomplish this by setting an instance of LogInspector and then performing some * operations using Joomla\Log\Log::addLogger() to alter the state of the internal instance. We then check that the * LogInspector instance we created (and set) has the same values we would expect for lookup and configuration * so we can assert that the operations we performed using Joomla\Log\Log::addLogger() were actually performed on our * instance of LogInspector that was set. * * @return void * * @since 1.0 */ public function testSetInstance() { $log = new LogInspector(); Log::setInstance($log); // Add a logger to the Log object. Log::addLogger(array('logger' => 'w3c')); // Get the expected configurations array after adding the single logger. $expectedConfigurations = array('55202c195e23298813df4292c827b241' => array('logger' => 'w3c')); // Get the expected lookup array after adding the single logger. $expectedLookup = array('55202c195e23298813df4292c827b241' => (object) array('priorities' => Log::ALL, 'categories' => array(), 'exclude' => false)); // Get the expected loggers array after adding the single logger (hasn't been instantiated yet so null). $expectedLoggers = null; $this->assertThat($log->configurations, $this->equalTo($expectedConfigurations), 'Line: ' . __LINE__ . '.'); $this->assertThat($log->lookup, $this->equalTo($expectedLookup), 'Line: ' . __LINE__ . '.'); $this->assertThat($log->loggers, $this->equalTo($expectedLoggers), 'Line: ' . __LINE__ . '.'); // Start over so we test that it actually sets the instance appropriately. $log = new LogInspector(); Log::setInstance($log); // Add a logger to the Log object. Log::addLogger(array('logger' => 'database', 'db_type' => 'mysql', 'db_table' => '#__test_table'), Log::ERROR); // Get the expected configurations array after adding the single logger. $expectedConfigurations = array('b67483f5ba61450d173aae527fa4163f' => array('logger' => 'database', 'db_type' => 'mysql', 'db_table' => '#__test_table')); // Get the expected lookup array after adding the single logger. $expectedLookup = array('b67483f5ba61450d173aae527fa4163f' => (object) array('priorities' => Log::ERROR, 'categories' => array(), 'exclude' => false)); // Get the expected loggers array after adding the single logger (hasn't been instantiated yet so null). $expectedLoggers = null; $this->assertThat($log->configurations, $this->equalTo($expectedConfigurations), 'Line: ' . __LINE__ . '.'); $this->assertThat($log->lookup, $this->equalTo($expectedLookup), 'Line: ' . __LINE__ . '.'); $this->assertThat($log->loggers, $this->equalTo($expectedLoggers), 'Line: ' . __LINE__ . '.'); }