You are here

protected function CommentStatisticsUnitTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 57
Contains \Drupal\Tests\comment\Unit\CommentStatisticsUnitTest.

Class

CommentStatisticsUnitTest
@coversDefaultClass \Drupal\comment\CommentStatistics @group comment

Namespace

Drupal\Tests\comment\Unit

Code

protected function setUp() {
  $this->statement = $this
    ->getMockBuilder('Drupal\\Core\\Database\\Driver\\sqlite\\Statement')
    ->disableOriginalConstructor()
    ->getMock();
  $this->statement
    ->expects($this
    ->any())
    ->method('fetchObject')
    ->will($this
    ->returnCallback(array(
    $this,
    'fetchObjectCallback',
  )));
  $this->select = $this
    ->getMockBuilder('Drupal\\Core\\Database\\Query\\Select')
    ->disableOriginalConstructor()
    ->getMock();
  $this->select
    ->expects($this
    ->any())
    ->method('fields')
    ->will($this
    ->returnSelf());
  $this->select
    ->expects($this
    ->any())
    ->method('condition')
    ->will($this
    ->returnSelf());
  $this->select
    ->expects($this
    ->any())
    ->method('execute')
    ->will($this
    ->returnValue($this->statement));
  $this->database = $this
    ->getMockBuilder('Drupal\\Core\\Database\\Connection')
    ->disableOriginalConstructor()
    ->getMock();
  $this->database
    ->expects($this
    ->once())
    ->method('select')
    ->will($this
    ->returnValue($this->select));
  $this->commentStatistics = new CommentStatistics($this->database, $this
    ->getMock('Drupal\\Core\\Session\\AccountInterface'), $this
    ->getMock('Drupal\\Core\\Entity\\EntityManagerInterface'), $this
    ->getMock('Drupal\\Core\\State\\StateInterface'));
}