addLogger example


  public function testSubmitFormWithException() {
    /** @var \Drupal\Core\Messenger\MessengerInterface $messenger */
    $messenger = \Drupal::service('messenger');

    $workspaceOperationFactory = $this->createMock(WorkspaceOperationFactory::class);
    $entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
    $logger = $this->createMock(LoggerInterface::class);
    /** @var \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory */
    $loggerFactory = \Drupal::service('logger.factory');
    $loggerFactory->addLogger($logger);

    $workspace = $this->createMock(Workspace::class);
    $workspacePublisher = $this->createMock(WorkspacePublisherInterface::class);

    $workspace
      ->expects($this->any())
      ->method('label');

    $workspace
      ->expects($this->once())
      ->method('publish')
      
return $this->channels[$channel];
  }

  /** * {@inheritdoc} */
  public function addLogger(LoggerInterface $logger$priority = 0) {
    // Store it so we can pass it to potential new logger instances.     $this->loggers[$priority][] = $logger;
    // Add the logger to already instantiated channels.     foreach ($this->channels as $channel) {
      $channel->addLogger($logger$priority);
    }
  }

}

  protected $history = [];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->installConfig('system');
    $this->container->get('logger.factory')->addLogger($this);
  }

  /** * Tests contrib advisories that should be displayed. * * @param mixed[] $feed_item * The feed item to test. 'title' and 'link' are omitted from this array * because they do not need to vary between test cases. * @param string|null $existing_version * The existing version of the module. * * @dataProvider providerShowAdvisories */
->willReturn(['default' => 'doctrine.orm.default_entity_manager']);
        $registry->expects($this->any())
            ->method('getConnection')
            ->willReturn($connection);

        $this->expectDeprecation('Since symfony/doctrine-bridge 6.4: Not passing an instance of "Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder" as "$debugDataHolder" to "Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector::__construct()" is deprecated.');
        $collector = new DoctrineDataCollector($registry);
        $logger = $this->createMock(DebugStack::class);
        $logger->queries = $queries;

        $this->expectDeprecation('Since symfony/doctrine-bridge 6.4: "Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector::addLogger()" is deprecated. Pass an instance of "Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder" to the constructor instead.');
        $collector->addLogger('default', $logger);

        return $collector;
    }
}

class StringRepresentableClass
{
    public function __toString(): string
    {
        return 'string representation';
    }
}
// Ensure that the theme system does not log any errors about missing theme     // hooks when rendering the link.     $logger = $this->prophesize(LoggerInterface::class);
    $logger->log(
      RfcLogLevel::WARNING,
      'Theme hook %hook not found.',
      Argument::withEntry('%hook', 'link')
    )->shouldNotBeCalled();

    $this->container->get('logger.factory')
      ->get('theme')
      ->addLogger($logger->reveal());
  }

  /** * Tests the views area display_link handler. */
  public function testAreaDisplayLink() {
    $view = Views::getView('test_view');

    // Assert only path-based displays are available in the display link     // settings form.     $view->setDisplay('page_1');
    

  public function testLog(callable $expected, Request $request = NULL, AccountInterface $current_user = NULL) {
    $channel = new LoggerChannel('test');
    $message = $this->randomMachineName();
    $logger = $this->createMock('Psr\Log\LoggerInterface');
    $logger->expects($this->once())
      ->method('log')
      ->with($this->anything()$message$this->callback($expected));
    $channel->addLogger($logger);
    if ($request) {
      $requestStack = new RequestStack();
      $requestStack->push($request);
      $channel->setRequestStack($requestStack);
    }
    if ($current_user) {
      $channel->setCurrentUser($current_user);
    }
    $channel->log(rand(0, 7)$message);
  }

  

  protected static $modules = ['system'];

  /** * Tests watchdog_exception() deprecation. */
  public function testWatchdogException(): void {
    $logger = new TestLogger();
    /** @var \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory */
    $loggerFactory = \Drupal::service('logger.factory');
    $loggerFactory->addLogger($logger);
    $this->expectDeprecation('watchdog_exception() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use \Drupal\Core\Utility\Error::logException() instead. See https://www.drupal.org/node/2932520');
    $e = new \RuntimeException("foo");
    watchdog_exception('test', $e);
    $this->assertTrue($logger->hasRecordThatContains(Error::DEFAULT_ERROR_MESSAGE, RfcLogLevel::ERROR));
  }

}


    $key_value_factory = new KeyValueMemoryFactory();
    $this->keyValue = $key_value_factory->get('media');

    $this->currentTime = time();
    $time = $this->prophesize('\Drupal\Component\Datetime\TimeInterface');
    $time->getCurrentTime()->willReturn($this->currentTime);

    $this->logger = $this->prophesize('\Psr\Log\LoggerInterface');
    $logger_factory = new LoggerChannelFactory();
    $logger_factory->addLogger($this->logger->reveal());

    $this->responses = new MockHandler();
    $client = new Client([
      'handler' => HandlerStack::create($this->responses),
    ]);
    $this->repository = new ProviderRepository(
      $client,
      $config_factory,
      $time->reveal(),
      $key_value_factory,
      $logger_factory
    );
Home | Imprint | This part of the site doesn't use cookies.