TestLogger example


  protected TestLogger $logger;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->fixtures = new RoutingFixtures();
    $this->state = new State(new KeyValueMemoryFactory());
    $this->logger = new TestLogger();
  }

  /** * Confirms that the dumper can be instantiated successfully. */
  public function testCreate() {
    $connection = Database::getConnection();
    $dumper = new MatcherDumper($connection$this->state, $this->logger);

    $class_name = 'Drupal\Core\Routing\MatcherDumper';
    $this->assertInstanceOf($class_name$dumper);
  }
class LegacyBootstrapTest extends KernelTestBase {

  /** * {@inheritdoc} */
  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));
  }

}

  protected LoggerInterface $logger;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->mockConfigFactory = $this->getConfigFactoryStub(['update.settings' => ['fetch_url' => 'http://www.example.com']]);
    $this->mockHttpClient = $this->createMock('\GuzzleHttp\ClientInterface');
    $settings = new Settings([]);
    $this->logger = new TestLogger();
    $this->updateFetcher = new UpdateFetcher($this->mockConfigFactory, $this->mockHttpClient, $settings$this->logger);
    $this->testProject = [
      'name' => 'update_test',
      'project_type' => '',
      'info' => [
        'version' => '',
        'project status url' => 'https://www.example.com',
      ],
      'includes' => ['module1' => 'Module 1', 'module2' => 'Module 2'],
    ];
  }

  

  protected function setUp(): void {
    parent::setUp();
    $this->fixtures = new RoutingFixtures();
    $this->state = new State(new KeyValueMemoryFactory());
    $this->currentPath = new CurrentPathStack(new RequestStack());
    $this->cache = new MemoryBackend();
    $this->pathProcessor = \Drupal::service('path_processor_manager');
    $this->cacheTagsInvalidator = \Drupal::service('cache_tags.invalidator');
    $this->installEntitySchema('path_alias');

    $this->logger = new TestLogger();
  }

  /** * {@inheritdoc} */
  public function register(ContainerBuilder $container) {
    parent::register($container);

    // Read the incoming path alias for these tests.     if ($container->hasDefinition('path_alias.path_processor')) {
      $definition = $container->getDefinition('path_alias.path_processor');
      
Home | Imprint | This part of the site doesn't use cookies.