You are here

public function ArrayCollectionTest::testExists in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/doctrine/collections/tests/Doctrine/Tests/Common/Collections/ArrayCollectionTest.php \Doctrine\Tests\Common\Collections\ArrayCollectionTest::testExists()

File

vendor/doctrine/collections/tests/Doctrine/Tests/Common/Collections/ArrayCollectionTest.php, line 239

Class

ArrayCollectionTest
Tests for { @covers \Doctrine\Common\Collections\ArrayCollection

Namespace

Doctrine\Tests\Common\Collections

Code

public function testExists() {
  $elements = array(
    1,
    'A' => 'a',
    2,
    'null' => null,
    3,
    'A2' => 'a',
    'zero' => 0,
  );
  $collection = new ArrayCollection($elements);
  $this
    ->assertTrue($collection
    ->exists(function ($key, $element) {
    return $key == 'A' && $element == 'a';
  }), "Element exists");
  $this
    ->assertFalse($collection
    ->exists(function ($key, $element) {
    return $key == 'non-existent' && $element == 'non-existent';
  }), "Element not exists");
}