Skip to content

Commit

Permalink
Improved error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Feb 18, 2024
1 parent 0fd76e8 commit 8beef48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Vector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ public function __construct($value)
}
}

if (!is_array($value) || !array_is_list($value)) {
if (!is_array($value)) {
throw new \InvalidArgumentException("Expected array");
}

if (!array_is_list($value)) {
throw new \InvalidArgumentException("Expected array to be a list");
}

$this->value = $value;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/PhpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public function testInvalidInteger()
new Vector(1);
}

public function testInvalidObject()
public function testInvalidArray()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Expected array');
$this->expectExceptionMessage('Expected array to be a list');

new Vector(['a' => 1]);
}
Expand Down

0 comments on commit 8beef48

Please sign in to comment.