You are here

public function EntityContext::assertCount in Lightning Core 8

Same name and namespace in other branches
  1. 8.5 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::assertCount()
  2. 8.2 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::assertCount()
  3. 8.3 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::assertCount()
  4. 8.4 tests/contexts/EntityContext.behat.inc \Acquia\LightningExtension\Context\EntityContext::assertCount()

Asserts that entities of a specific type and optional bundle exist.

@Then 1 :entity_type entity should exist @Then 1 :bundle :entity_type entity should exist @Then :n :entity_type entities should exist @Then :n :bundle :entity_type entities should exist

Parameters

string $entity_type: The entity type ID.

int $n: (optional) How many entities are expected to exist.

string $bundle: (optional) The bundle.

Throws

\Behat\Mink\Exception\ExpectationException if the number of existing entities does not match the expected number.

File

tests/contexts/EntityContext.behat.inc, line 182

Class

EntityContext
Contains miscellaneous step definitions for working with Drupal entities.

Namespace

Acquia\LightningExtension\Context

Code

public function assertCount($entity_type, $n = 1, $bundle = NULL) {
  $count = $this
    ->count($entity_type, $bundle);
  if ($count !== (int) $n) {
    $message = sprintf('Expected %s to exist, but there are only %s.', $this
      ->formatCount($entity_type, $n), $this
      ->formatCount($entity_type, $count));
    throw new ExpectationException($message, $this
      ->getSession()
      ->getDriver());
  }
}