function InspectorTest::testAssertAllObjects

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Component/Assertion/InspectorTest.php \Drupal\Tests\Component\Assertion\InspectorTest::testAssertAllObjects()
  2. 10 core/tests/Drupal/Tests/Component/Assertion/InspectorTest.php \Drupal\Tests\Component\Assertion\InspectorTest::testAssertAllObjects()
  3. 9 core/tests/Drupal/Tests/Component/Assertion/InspectorTest.php \Drupal\Tests\Component\Assertion\InspectorTest::testAssertAllObjects()
  4. 8.9.x core/tests/Drupal/Tests/Component/Assertion/InspectorTest.php \Drupal\Tests\Component\Assertion\InspectorTest::testAssertAllObjects()

Tests asserting all members are objects.

File

core/tests/Drupal/Tests/Component/Assertion/InspectorTest.php, line 194

Class

InspectorTest
Tests Drupal\Component\Assertion\Inspector.

Namespace

Drupal\Tests\Component\Assertion

Code

public function testAssertAllObjects() : void {
  $this->assertTrue(Inspector::assertAllObjects([
    new \ArrayObject(),
    new \ArrayObject(),
  ]));
  $this->assertFalse(Inspector::assertAllObjects([
    new \ArrayObject(),
    new \ArrayObject(),
    'foo',
  ]));
  $this->assertTrue(Inspector::assertAllObjects([
    new \ArrayObject(),
    new \ArrayObject(),
  ], '\\Traversable'));
  $this->assertFalse(Inspector::assertAllObjects([
    new \ArrayObject(),
    new \ArrayObject(),
    'foo',
  ], '\\Traversable'));
  $this->assertFalse(Inspector::assertAllObjects([
    new \ArrayObject(),
    new StringObject(),
  ], '\\Traversable'));
  $this->assertTrue(Inspector::assertAllObjects([
    new \ArrayObject(),
    new StringObject(),
  ], '\\Traversable', '\\Drupal\\Tests\\Component\\Assertion\\StringObject'));
  $this->assertFalse(Inspector::assertAllObjects([
    new \ArrayObject(),
    new StringObject(),
    new \stdClass(),
  ], '\\ArrayObject', '\\Drupal\\Tests\\Component\\Assertion\\StringObject'));
}

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