function CommentStatisticsUnitTest::setUp

Same name and namespace in other branches
  1. 9 core/modules/comment/tests/src/Unit/CommentStatisticsUnitTest.php \Drupal\Tests\comment\Unit\CommentStatisticsUnitTest::setUp()
  2. 8.9.x core/modules/comment/tests/src/Unit/CommentStatisticsUnitTest.php \Drupal\Tests\comment\Unit\CommentStatisticsUnitTest::setUp()
  3. 11.x core/modules/comment/tests/src/Unit/CommentStatisticsUnitTest.php \Drupal\Tests\comment\Unit\CommentStatisticsUnitTest::setUp()

Sets up required mocks and the CommentStatistics service under test.

Overrides UnitTestCase::setUp

File

core/modules/comment/tests/src/Unit/CommentStatisticsUnitTest.php, line 56

Class

CommentStatisticsUnitTest
@coversDefaultClass \Drupal\comment\CommentStatistics[[api-linebreak]] @group comment

Namespace

Drupal\Tests\comment\Unit

Code

protected function setUp() : void {
  parent::setUp();
  $this->statement = $this->getMockBuilder('Drupal\\sqlite\\Driver\\Database\\sqlite\\Statement')
    ->disableOriginalConstructor()
    ->getMock();
  $this->statement
    ->expects($this->any())
    ->method('fetchObject')
    ->willReturnCallback([
    $this,
    'fetchObjectCallback',
  ]);
  $this->select = $this->getMockBuilder('Drupal\\Core\\Database\\Query\\Select')
    ->disableOriginalConstructor()
    ->getMock();
  $this->select
    ->expects($this->any())
    ->method('fields')
    ->willReturnSelf();
  $this->select
    ->expects($this->any())
    ->method('condition')
    ->willReturnSelf();
  $this->select
    ->expects($this->any())
    ->method('execute')
    ->willReturn($this->statement);
  $this->database = $this->getMockBuilder('Drupal\\Core\\Database\\Connection')
    ->disableOriginalConstructor()
    ->getMock();
  $this->database
    ->expects($this->once())
    ->method('select')
    ->willReturn($this->select);
  $this->commentStatistics = new CommentStatistics($this->database, $this->createMock('Drupal\\Core\\Session\\AccountInterface'), $this->createMock(EntityTypeManagerInterface::class), $this->createMock('Drupal\\Core\\State\\StateInterface'), $this->createMock(TimeInterface::class), $this->database);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.