/** * @param Equatable[] $items */ public function __construct(array $items = []) { foreach ($items as $item) { if (!$item instanceof Equatable) { throw InvalidArgumentException::invalidTypeInArray('items', Equatable::class, $item); } $this->items[] = $item; } }
/** * @test */ public function it_creates_an_invalidTypeInArray_exception_mentioning_the_type_of_an_object() { $exception = InvalidArgumentException::invalidTypeInArray('someArgument', 'string', new stdClass()); $this->assertInstanceOf(InvalidArgumentException::class, $exception); $this->assertSame('Each value in argument $someArgument must be of type string, stdClass given', $exception->getMessage()); }