You are here

public function TestDeprecatedTestHooks::testHookTestGroupStarted in Drupal 8

@expectedDeprecation The deprecated hook hook_test_group_started() is implemented in these functions: simpletest_deprecation_test_test_group_started(). Convert your test to a PHPUnit-based one and implement test listeners. See https://www.drupal.org/node/2934242

File

core/modules/simpletest/tests/src/Kernel/TestDeprecatedTestHooks.php, line 39

Class

TestDeprecatedTestHooks
Test the deprecation messages for Simpletest test hooks.

Namespace

Drupal\Tests\simpletest\Kernel

Code

public function testHookTestGroupStarted() {

  // Mock a database connection enough for simpletest_run_tests().
  $insert = $this
    ->getMockBuilder(Insert::class)
    ->disableOriginalConstructor()
    ->setMethods([
    'execute',
    'useDefaults',
  ])
    ->getMock();
  $insert
    ->expects($this
    ->any())
    ->method('useDefaults')
    ->willReturn($insert);
  $insert
    ->expects($this
    ->any())
    ->method('execute')
    ->willReturn(__METHOD__);
  $connection = $this
    ->getMockBuilder(Connection::class)
    ->disableOriginalConstructor()
    ->setMethods([
    'insert',
  ])
    ->getMockForAbstractClass();
  $connection
    ->expects($this
    ->once())
    ->method('insert')
    ->willReturn($insert);

  // Mock public stream wrapper enough for simpletest_run_tests().
  $public = $this
    ->getMockBuilder(PublicStream::class)
    ->disableOriginalConstructor()
    ->setMethods([])
    ->getMock();

  // Set up the container.
  $this->container
    ->set('database', $connection);
  $this->container
    ->set('stream_wrapper.public', $public);

  // Make sure our mocked database is in use by expecting a test ID that is
  // __METHOD__.
  $this
    ->assertEquals(__METHOD__, simpletest_run_tests([
    static::class,
  ]));
}