You are here

public function BatchTest::testAddItemException in Akamai 7.3

Verifies that an InvalidArgumentException is thrown when expected.

An exception should be thrown when adding items with differing hostnames.

@covers Drupal\akamai\Batch::addItem

File

tests/BatchTest.php, line 49
Unit tests for the Drupal\akamai\Batch class.

Class

BatchTest

Namespace

Drupal\akamai\Tests

Code

public function testAddItemException() {
  $this
    ->setExpectedException('InvalidArgumentException');

  // Attempt to add two items with differing hostnames.
  $num_items = 2;
  $items = [];
  $batch = new Batch();
  for ($i = 1; $i <= $num_items; $i++) {
    $item = (object) [
      'item_id' => $i,
      'data' => [
        'hostname' => "www{$i}.example.com",
        'paths' => [
          'node/' . $i,
        ],
      ],
    ];
    $items[] = $item;
    $batch
      ->addItem($item);
  }
}