class EntityPagerAnalyzerTest in Entity Pager 8
Same name and namespace in other branches
- 2.0.x tests/src/Unit/EntityPagerAnalyzerTest.php \Drupal\Tests\entity_pager\Unit\EntityPagerAnalyzerTest
@coversDefaultClass \Drupal\entity_pager\EntityPagerAnalyzer @group entity_pager
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait- class \Drupal\Tests\entity_pager\Unit\EntityPagerAnalyzerTest
 
Expanded class hierarchy of EntityPagerAnalyzerTest
File
- tests/src/ Unit/ EntityPagerAnalyzerTest.php, line 19 
Namespace
Drupal\Tests\entity_pager\UnitView source
class EntityPagerAnalyzerTest extends UnitTestCase {
  /**
   * Log messages to use in tests.
   *
   * @var string[]
   */
  protected $logs;
  /**
   * Entity pager stub.
   *
   * @var \Drupal\entity_pager\EntityPagerInterface|\PHPUnit\Framework\MockObject\MockObject
   */
  protected $entityPager;
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    $this->entityPager = $this
      ->createMock(EntityPagerInterface::class);
    for ($i = 0; $i < random_int(3, 6); $i++) {
      $this->logs[] = $this
        ->randomMachineName();
    }
  }
  /**
   * @covers ::__construct
   * @covers ::analyze
   */
  public function testAnalyze() {
    $event_dispatcher = $this
      ->createMock(EventDispatcherInterface::class);
    $event_dispatcher
      ->expects($this
      ->once())
      ->method('dispatch')
      ->with(EntityPagerEvents::ENTITY_PAGER_ANALYZE, $this
      ->callback([
      $this,
      'mockSubscriberLog',
    ]));
    // @todo Refactor \Drupal\entity_pager\EntityPagerAnalyzer to use dependency
    //   injection for its logging.
    $logger = $this
      ->createMock(LoggerChannelInterface::class);
    $logger
      ->expects($this
      ->exactly(count($this->logs)))
      ->method('notice')
      ->withConsecutive(...array_map(function ($a) {
      return [
        $a,
      ];
    }, $this->logs));
    $logger_factory = $this
      ->createMock(LoggerChannelFactoryInterface::class);
    $logger_factory
      ->method('get')
      ->willReturn($logger);
    $container = new ContainerBuilder();
    $container
      ->set('logger.factory', $logger_factory);
    \Drupal::setContainer($container);
    $analyzer = new EntityPagerAnalyzer($event_dispatcher);
    $analyzer
      ->analyze($this->entityPager);
  }
  /**
   * Event subscription mock function for ::testAnalyze().
   *
   * @param mixed $event
   *   The analyze event.
   *
   * @return bool
   *   Returns TRUE if given an
   *   \Drupal\entity_pager\Event\EntityPagerAnalyzeEvent, FALSE otherwise.
   */
  public function mockSubscriberLog($event) {
    if ($event instanceof EntityPagerAnalyzeEvent) {
      $event
        ->log($this->logs);
      $this
        ->assertSame($this->entityPager, $event
        ->getEntityPager());
      return TRUE;
    }
    return FALSE;
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| EntityPagerAnalyzerTest:: | protected | property | Entity pager stub. | |
| EntityPagerAnalyzerTest:: | protected | property | Log messages to use in tests. | |
| EntityPagerAnalyzerTest:: | public | function | Event subscription mock function for ::testAnalyze(). | |
| EntityPagerAnalyzerTest:: | protected | function | Overrides UnitTestCase:: | |
| EntityPagerAnalyzerTest:: | public | function | @covers ::__construct @covers ::analyze | |
| PhpunitCompatibilityTrait:: | public | function | Returns a mock object for the specified class using the available method. | |
| PhpunitCompatibilityTrait:: | public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
| UnitTestCase:: | protected | property | The random generator. | |
| UnitTestCase:: | protected | property | The app root. | 1 | 
| UnitTestCase:: | protected | function | Asserts if two arrays are equal by sorting them first. | |
| UnitTestCase:: | protected | function | Mocks a block with a block plugin. | 1 | 
| UnitTestCase:: | protected | function | Returns a stub class resolver. | |
| UnitTestCase:: | public | function | Returns a stub config factory that behaves according to the passed array. | |
| UnitTestCase:: | public | function | Returns a stub config storage that returns the supplied configuration. | |
| UnitTestCase:: | protected | function | Sets up a container with a cache tags invalidator. | |
| UnitTestCase:: | protected | function | Gets the random generator for the utility methods. | |
| UnitTestCase:: | public | function | Returns a stub translation manager that just returns the passed string. | |
| UnitTestCase:: | public | function | Generates a unique random string containing letters and numbers. | 
