StubConnection example


    ];
  }

  /** * Exercise setPrefix() and tablePrefix(). * * @dataProvider providerPrefixRoundTrip */
  public function testPrefixRoundTrip($expected$prefix_info) {
    $mock_pdo = $this->createMock('Drupal\Tests\Core\Database\Stub\StubPDO');
    $connection = new StubConnection($mock_pdo[]);

    // setPrefix() is protected, so we make it accessible with reflection.     $reflection = new \ReflectionClass('Drupal\Tests\Core\Database\Stub\StubConnection');
    $set_prefix = $reflection->getMethod('setPrefix');

    // Set the prefix data.     $set_prefix->invokeArgs($connection[$prefix_info]);
    // Check the round-trip.     foreach ($expected as $table => $prefix) {
      $this->assertEquals($prefix$connection->getPrefix());
    }
  }
/** * A database connection. */
  protected Connection $connection;

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

    $this->connection = new StubConnection($this->createMock(StubPDO::class)[]);
  }

  /** * @covers ::isEventEnabled * @covers ::enableEvents * @covers ::disableEvents */
  public function testEventEnablingAndDisabling(): void {
    $this->connection->enableEvents([
      StatementExecutionStartEvent::class,
      StatementExecutionEndEvent::class,
    ]);

  public function testBuildTags($prefix, array $suffixes, array $expected$glue = ':') {
    $this->assertEquals($expected, Cache::buildTags($prefix$suffixes$glue));
  }

  /** * @covers ::keyFromQuery * @group legacy */
  public function testKeyFromQuery() {
    $this->expectDeprecation('Drupal\Core\Cache\Cache::keyFromQuery is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. No replacement provided. https://www.drupal.org/node/3322044');
    $query = new Select(new StubConnection(new StubPDO()[]), 'dne');
    Cache::keyFromQuery($query);
  }

}
->disableOriginalConstructor()
      ->getMock();
    $contrib_namespace = 'Drupal\mock\Driver\Database\mock';
    $mocked_namespace = $contrib_namespace . '\\Condition';
    class_alias('MockCondition', $mocked_namespace);

    $options['namespace'] = $contrib_namespace;
    $options['prefix'] = '';

    $mockPdo = $this->createMock(StubPDO::class);

    $connection = new StubConnection($mockPdo$options);
    $condition = $connection->condition('AND');
    $this->assertSame('MockCondition', get_class($condition));
  }

}

  public function testExtend(string $expected, string $namespace, string $extend): void {
    $additional_class_loader = new ClassLoader();
    $additional_class_loader->addPsr4("Drupal\\corefake\\Driver\\Database\\corefake\\", __DIR__ . "/../../../../../tests/fixtures/database_drivers/module/corefake/src/Driver/Database/corefake");
    $additional_class_loader->addPsr4("Drupal\\corefake\\Driver\\Database\\corefakeWithAllCustomClasses\\", __DIR__ . "/../../../../../tests/fixtures/database_drivers/module/corefake/src/Driver/Database/corefakeWithAllCustomClasses");
    $additional_class_loader->register(TRUE);

    $mock_pdo = $this->createMock(StubPDO::class);
    $connection = new StubConnection($mock_pdo['namespace' => $namespace]);

    // Tests the method \Drupal\Core\Database\Query\Select::extend().     $select = $connection->select('test')->extend($extend);
    $this->assertEquals($expectedget_class($select));

    // Get an instance of the class \Drupal\Core\Database\Query\SelectExtender.     $select_extender = $connection->select('test')->extend(SelectExtender::class);
    $this->assertEquals(SelectExtender::classget_class($select_extender));

    // Tests the method \Drupal\Core\Database\Query\SelectExtender::extend().     $select_extender_extended = $select_extender->extend($extend);
    

  public function testContribDriverLog() {
    Database::addConnectionInfo('default', 'default', [
      'driver' => 'test',
      'namespace' => 'Drupal\Tests\Core\Database\Stub',
    ]);

    $this->expectDeprecation('Drupal\Core\Database\Log::findCaller() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use Connection::findCallerFromDebugBacktrace(). See https://www.drupal.org/node/3328053');
    $this->expectDeprecation('Drupal\Core\Database\Log::getDebugBacktrace() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3328053');
    $this->expectDeprecation('Drupal\Core\Database\Log::removeDatabaseEntries() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use Connection::removeDatabaseEntriesFromDebugBacktrace(). See https://www.drupal.org/node/3328053');
    $pdo = $this->prophesize(StubPDO::class)->reveal();
    $result = (new StubConnection($pdo[]))->testLogCaller();
    $this->assertSame([
      'file' => __FILE__,
      'line' => 37,
      'function' => 'testContribDriverLog',
      'class' => 'Drupal\Tests\Core\Database\LogTest',
      'type' => '->',
      'args' => [],
    ]$result);

    // Test calling the database log from outside of database code.     $this->expectDeprecation('Drupal\Core\Database\Log::findCaller() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use Connection::findCallerFromDebugBacktrace(). See https://www.drupal.org/node/3328053');
    

  protected $query;

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

    $mockPdo = $this->createMock(StubPDO::class);
    $connection = new StubConnection($mockPdo[]);
    $this->query = new Select($connection, 'test', NULL);
  }

  /** * Checks that invalid sort directions in ORDER BY get converted to ASC. */
  public function testInvalidDirection() {
    $this->query->orderBy('test', 'invalid direction');
    $order_bys = $this->query->getOrderBy();
    $this->assertEquals('ASC', $order_bys['test'], 'Invalid order by direction is converted to ASC.');
  }

  
Home | Imprint | This part of the site doesn't use cookies.