Skip to content

Commit

Permalink
Add tests for contains to certify contains() works on the same objec…
Browse files Browse the repository at this point in the history
…t, and not only the value of it's properties
  • Loading branch information
steevanb committed May 15, 2024
1 parent 17b6342 commit c84b8f6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
29 changes: 29 additions & 0 deletions tests/Unit/ObjectCollection/AbstractObjectCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,33 @@ public function testAssertValueTypeInvalidValueNull(): void
/** @phpstan-ignore-next-line Parameter #1 $values ... constructor expects ... array<int, null> given. */
new TestObjectCollection([null]);
}

public function testNotContains(): void
{
$object1 = new TestObject('value 1');
$object2 = new TestObject('value 2');
$object3 = new TestObject('value 3');
$collection = new TestObjectCollection([$object1, $object2]);

static::assertFalse($collection->contains($object3));
}

public function testContainsEquals(): void
{
$object1 = new TestObject('value 1');
$object2 = new TestObject('value 2');
$object3 = new TestObject('value 1');
$collection = new TestObjectCollection([$object1, $object2]);

static::assertFalse($collection->contains($object3));
}

public function testContainsSame(): void
{
$object1 = new TestObject('value 1');
$object2 = new TestObject('value 2');
$collection = new TestObjectCollection([$object1, $object2]);

static::assertTrue($collection->contains($object2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,42 @@ public function testAssertValueTypeNull(): void

static::assertNull($collection->get(0));
}

public function testNotContains(): void
{
$object1 = new TestObject('value 1');
$object2 = new TestObject('value 2');
$object3 = new TestObject('value 3');
$collection = new TestObjectNullableCollection([$object1, $object2]);

static::assertFalse($collection->contains($object3));
}

public function testContainsEquals(): void
{
$object1 = new TestObject('value 1');
$object2 = new TestObject('value 2');
$object3 = new TestObject('value 1');
$collection = new TestObjectNullableCollection([$object1, $object2]);

static::assertFalse($collection->contains($object3));
}

public function testContainsSame(): void
{
$object1 = new TestObject('value 1');
$object2 = new TestObject('value 2');
$collection = new TestObjectNullableCollection([$object1, $object2]);

static::assertTrue($collection->contains($object2));
}

public function testContainsNull(): void
{
$object1 = new TestObject('value 1');
$object2 = new TestObject('value 2');
$collection = new TestObjectNullableCollection([$object1, $object2, null]);

static::assertTrue($collection->contains(null));
}
}
5 changes: 0 additions & 5 deletions tests/Unit/ObjectCollection/TestObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,4 @@ public function getValue(): string
{
return $this->value;
}

public function __toString(): string
{
return $this->value;
}
}

0 comments on commit c84b8f6

Please sign in to comment.