Inheritance: extends Loops\Logger\Logger, implements Loops\Logger\LoggerInterface
Exemple #1
0
 protected function setUp()
 {
     parent::setUp();
     self::$logs = array();
     $this->config = $this->getMockBuilder('\\OC\\SystemConfig')->disableOriginalConstructor()->getMock();
     $this->logger = new Log('Test\\Logger', $this->config);
 }
 /**
  * @magentoDataFixture Magento/User/_files/user_with_role.php
  */
 public function testLaunch()
 {
     $this->markTestSkipped("MAGETWO-42710: Improve Sample Data Integration Test (InstallerTest)");
     $setupFactory = $this->getMockBuilder('Magento\\SampleData\\Model\\SetupFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $setupFactory->expects($this->any())->method('create')->will($this->returnCallback([$this, 'createSetupModel']));
     \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->configure(['preferences' => ['Magento\\SampleData\\Helper\\Fixture' => 'Magento\\SampleData\\Helper\\TestFixture']]);
     /** @var \Magento\SampleData\Model\Installer $installer */
     $installer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\SampleData\\Model\\Installer');
     /** @var \Magento\SampleData\Model\Logger $sampleDataLogger */
     $sampleDataLogger = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\SampleData\\Model\\Logger');
     $sampleDataLogger->setSubject(TestLogger::factory());
     ob_start();
     $installer->run('adminUser');
     $result = ob_get_clean();
     $this->assertContains('Installing theme', $result);
     $this->assertContains('Installing customers', $result);
     $this->assertContains('Installing CMS pages', $result);
     $this->assertContains('Installing catalog attributes', $result);
     $this->assertContains('Installing categories', $result);
     $this->assertContains('Installing simple products', $result);
     $this->assertContains('Installing configurable products', $result);
     $this->assertContains('Installing bundle products', $result);
     $this->assertContains('Installing grouped products', $result);
     $this->assertContains('Installing Tablerate', $result);
     $this->assertContains('Installing taxes', $result);
     $this->assertContains('Installing CMS blocks', $result);
     $this->assertContains('Installing orders', $result);
     $this->assertContains('Installing sales rules', $result);
     $this->assertContains('Installing product reviews', $result);
     $this->assertContains('Installing Widgets', $result);
 }
 /**
  * @param string      $methodName
  * @param array       $args
  * @param bool        $expected
  * @param string|null $message
  *
  * @dataProvider provideAssertTestCases
  */
 public function testAsserts($methodName, array $args, $expected, $message = null)
 {
     $mock = new MemcachedMock();
     $mock->setThrowExceptionsOnFailure(false);
     $logger = new TestLogger();
     $mock->setLogger(new MemcachedLogger($logger));
     $mockReflection = new \ReflectionClass($mock);
     $method = $mockReflection->getMethod($methodName);
     $this->assertInstanceOf('\\ReflectionMethod', $method, sprintf('Failed to find method "%s".', $methodName));
     $this->assertSame('GeckoPackages\\MemcacheMock\\MemcachedMock', $method->getDeclaringClass()->getName());
     $this->assertTrue($method->isPrivate(), sprintf('Expected method "%s" to be private.', $methodName));
     $method->setAccessible(true);
     $this->assertSame($expected, $method->invokeArgs($mock, $args), sprintf('Expected return value mismatch for "%s".', $methodName));
     if (null !== $message) {
         $failures = $logger->getErrorLog();
         $this->assertInternalType('array', $failures);
         $this->assertCount(1, $failures, 'Expected 1 assert failure.');
         $this->assertSame($message, $failures[0][0], 'Assert message not as expected.');
     }
 }
Exemple #4
0
 /**
  * Test info log
  */
 public function testLogsFatal()
 {
     $l = new TestLogger(dirname(__FILE__) . '/logs', 0);
     $this->expectOutputString('[FATAL] ' . date('c') . ' - ' . "Test Info\r\n");
     $l->error('Test Info');
     $l->fatal('Test Info');
 }
 /**
  * @dataProvider provideHandlers
  * @param string $handler php serialize_handler to use
  */
 public function testSessionHandling($handler)
 {
     $this->hideDeprecated('$_SESSION');
     $reset[] = $this->getResetter($rProp);
     $this->setMwGlobals(array('wgSessionProviders' => array(array('class' => 'DummySessionProvider')), 'wgObjectCacheSessionExpiry' => 2));
     $store = new \HashBagOStuff();
     $logger = new \TestLogger(true, function ($m) {
         return preg_match('/^SessionBackend a{32} /', $m) ? null : $m;
     });
     $manager = new SessionManager(array('store' => $store, 'logger' => $logger));
     PHPSessionHandler::install($manager);
     $wrap = \TestingAccessWrapper::newFromObject($rProp->getValue());
     $reset[] = new \ScopedCallback(array($wrap, 'setEnableFlags'), array($wrap->enable ? $wrap->warn ? 'warn' : 'enable' : 'disable'));
     $wrap->setEnableFlags('warn');
     \MediaWiki\suppressWarnings();
     ini_set('session.serialize_handler', $handler);
     \MediaWiki\restoreWarnings();
     if (ini_get('session.serialize_handler') !== $handler) {
         $this->markTestSkipped("Cannot set session.serialize_handler to \"{$handler}\"");
     }
     // Session IDs for testing
     $sessionA = str_repeat('a', 32);
     $sessionB = str_repeat('b', 32);
     $sessionC = str_repeat('c', 32);
     // Set up garbage data in the session
     $_SESSION['AuthenticationSessionTest'] = 'bogus';
     session_id($sessionA);
     session_start();
     $this->assertSame(array(), $_SESSION);
     $this->assertSame($sessionA, session_id());
     // Set some data in the session so we can see if it works.
     $rand = mt_rand();
     $_SESSION['AuthenticationSessionTest'] = $rand;
     $expect = array('AuthenticationSessionTest' => $rand);
     session_write_close();
     $this->assertSame(array(array(LogLevel::WARNING, 'Something wrote to $_SESSION!')), $logger->getBuffer());
     // Screw up $_SESSION so we can tell the difference between "this
     // worked" and "this did nothing"
     $_SESSION['AuthenticationSessionTest'] = 'bogus';
     // Re-open the session and see that data was actually reloaded
     session_start();
     $this->assertSame($expect, $_SESSION);
     // Make sure session_reset() works too.
     if (function_exists('session_reset')) {
         $_SESSION['AuthenticationSessionTest'] = 'bogus';
         session_reset();
         $this->assertSame($expect, $_SESSION);
     }
     // Re-fill the session, then test that session_destroy() works.
     $_SESSION['AuthenticationSessionTest'] = $rand;
     session_write_close();
     session_start();
     $this->assertSame($expect, $_SESSION);
     session_destroy();
     session_id($sessionA);
     session_start();
     $this->assertSame(array(), $_SESSION);
     session_write_close();
     // Test that our session handler won't clone someone else's session
     session_id($sessionB);
     session_start();
     $this->assertSame($sessionB, session_id());
     $_SESSION['id'] = 'B';
     session_write_close();
     session_id($sessionC);
     session_start();
     $this->assertSame(array(), $_SESSION);
     $_SESSION['id'] = 'C';
     session_write_close();
     session_id($sessionB);
     session_start();
     $this->assertSame(array('id' => 'B'), $_SESSION);
     session_write_close();
     session_id($sessionC);
     session_start();
     $this->assertSame(array('id' => 'C'), $_SESSION);
     session_destroy();
     session_id($sessionB);
     session_start();
     $this->assertSame(array('id' => 'B'), $_SESSION);
     // Test merging between Session and $_SESSION
     session_write_close();
     $session = $manager->getEmptySession();
     $session->set('Unchanged', 'setup');
     $session->set('Unchanged, null', null);
     $session->set('Changed in $_SESSION', 'setup');
     $session->set('Changed in Session', 'setup');
     $session->set('Changed in both', 'setup');
     $session->set('Deleted in Session', 'setup');
     $session->set('Deleted in $_SESSION', 'setup');
     $session->set('Deleted in both', 'setup');
     $session->set('Deleted in Session, changed in $_SESSION', 'setup');
     $session->set('Deleted in $_SESSION, changed in Session', 'setup');
     $session->persist();
     $session->save();
     session_id($session->getId());
     session_start();
     $session->set('Added in Session', 'Session');
     $session->set('Added in both', 'Session');
     $session->set('Changed in Session', 'Session');
     $session->set('Changed in both', 'Session');
     $session->set('Deleted in $_SESSION, changed in Session', 'Session');
     $session->remove('Deleted in Session');
     $session->remove('Deleted in both');
     $session->remove('Deleted in Session, changed in $_SESSION');
     $session->save();
     $_SESSION['Added in $_SESSION'] = '$_SESSION';
     $_SESSION['Added in both'] = '$_SESSION';
     $_SESSION['Changed in $_SESSION'] = '$_SESSION';
     $_SESSION['Changed in both'] = '$_SESSION';
     $_SESSION['Deleted in Session, changed in $_SESSION'] = '$_SESSION';
     unset($_SESSION['Deleted in $_SESSION']);
     unset($_SESSION['Deleted in both']);
     unset($_SESSION['Deleted in $_SESSION, changed in Session']);
     session_write_close();
     $this->assertEquals(array('Added in Session' => 'Session', 'Added in $_SESSION' => '$_SESSION', 'Added in both' => 'Session', 'Unchanged' => 'setup', 'Unchanged, null' => null, 'Changed in Session' => 'Session', 'Changed in $_SESSION' => '$_SESSION', 'Changed in both' => 'Session', 'Deleted in Session, changed in $_SESSION' => '$_SESSION', 'Deleted in $_SESSION, changed in Session' => 'Session'), iterator_to_array($session));
     $session->clear();
     $session->set(42, 'forty-two');
     $session->set('forty-two', 42);
     $session->set('wrong', 43);
     $session->persist();
     $session->save();
     session_start();
     $this->assertArrayHasKey('forty-two', $_SESSION);
     $this->assertSame(42, $_SESSION['forty-two']);
     $this->assertArrayHasKey('wrong', $_SESSION);
     unset($_SESSION['wrong']);
     session_write_close();
     $this->assertEquals(array(42 => 'forty-two', 'forty-two' => 42), iterator_to_array($session));
     // Test that write doesn't break if the session is invalid
     $session = $manager->getEmptySession();
     $session->persist();
     session_id($session->getId());
     session_start();
     $this->mergeMwGlobalArrayValue('wgHooks', array('SessionCheckInfo' => array(function (&$reason) {
         $reason = 'Testing';
         return false;
     })));
     $this->assertNull($manager->getSessionById($session->getId(), true), 'sanity check');
     session_write_close();
     $this->mergeMwGlobalArrayValue('wgHooks', array('SessionCheckInfo' => array()));
     $this->assertNotNull($manager->getSessionById($session->getId(), true), 'sanity check');
 }
 protected function setUp()
 {
     parent::setUp();
     self::$logs = array();
     $this->logger = new Log('Test\\Logger');
 }
Exemple #7
0
    protected function getPriority($priority)
    {
        return '*' . $priority . '*';
    }
}
// option: format
$t->diag('option: format');
unlink($file);
$logger = new TestLogger($dispatcher, array('file' => $file));
$logger->log('foo');
$t->is(file_get_contents($file), strftime($logger->getTimeFormat()) . ' symfony [*6*] foo' . PHP_EOL, '->initialize() can take a format option');
unlink($file);
$logger = new TestLogger($dispatcher, array('file' => $file, 'format' => '%message%'));
$logger->log('foo');
$t->is(file_get_contents($file), 'foo', '->initialize() can take a format option');
// option: time_format
$t->diag('option: time_format');
unlink($file);
$logger = new TestLogger($dispatcher, array('file' => $file, 'time_format' => '%Y %m %d'));
$logger->log('foo');
$t->is(file_get_contents($file), strftime($logger->getTimeFormat()) . ' symfony [*6*] foo' . PHP_EOL, '->initialize() can take a format option');
// option: type
$t->diag('option: type');
unlink($file);
$logger = new TestLogger($dispatcher, array('file' => $file, 'type' => 'foo'));
$logger->log('foo');
$t->is(file_get_contents($file), strftime($logger->getTimeFormat()) . ' foo [*6*] foo' . PHP_EOL, '->initialize() can take a format option');
// ->shutdown()
$t->diag('->shutdown()');
$logger->shutdown();
unlink($file);
Exemple #8
0
 public function setUp()
 {
     self::$logs = array();
     $this->logger = new Log('Test\\Logger');
 }