Skip to content

Commit 9ca859e

Browse files
author
smoench
committed
fix isA*Of exception messages
1 parent 1838a0f commit 9ca859e

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/Assert.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ public static function isAOf($value, $class, $message = '')
467467

468468
if (!\is_a($value, $class, \is_string($value))) {
469469
static::reportInvalidArgument(sprintf(
470-
$message ?: 'Expected an instance of this class or to this class among his parents %2$s. Got: %s',
471-
static::typeToString($value),
470+
$message ?: 'Expected an instance of this class or to this class among its parents "%2$s". Got: %s',
471+
static::valueToString($value),
472472
$class
473473
));
474474
}
@@ -493,8 +493,8 @@ public static function isNotA($value, $class, $message = '')
493493

494494
if (\is_a($value, $class, \is_string($value))) {
495495
static::reportInvalidArgument(sprintf(
496-
$message ?: 'Expected an instance of this class or to this class among his parents other than %2$s. Got: %s',
497-
static::typeToString($value),
496+
$message ?: 'Expected an instance of this class or to this class among its parents other than "%2$s". Got: %s',
497+
static::valueToString($value),
498498
$class
499499
));
500500
}
@@ -521,9 +521,9 @@ public static function isAnyOf($value, array $classes, $message = '')
521521
}
522522

523523
static::reportInvalidArgument(sprintf(
524-
$message ?: 'Expected an any of instance of this class or to this class among his parents other than %2$s. Got: %s',
525-
static::typeToString($value),
526-
\implode(', ', \array_map(array('static', 'valueToString'), $classes))
524+
$message ?: 'Expected an instance of any of this classes or any of those classes among their parents "%2$s". Got: %s',
525+
static::valueToString($value),
526+
\implode(', ', $classes)
527527
));
528528
}
529529

tests/AssertTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ public function getStringConversions()
717717
*/
718718
public function testConvertValuesToStrings($method, $args, $exceptionMessage)
719719
{
720-
$this->expectException('\InvalidArgumentException', $exceptionMessage);
720+
$this->expectException('\InvalidArgumentException');
721721
$this->expectExceptionMessage($exceptionMessage);
722722

723723
call_user_func_array(array('Webmozart\Assert\Assert', $method), $args);
@@ -729,6 +729,27 @@ public function testAnUnknownMethodThrowsABadMethodCall()
729729

730730
Assert::nonExistentMethod();
731731
}
732+
733+
public function getInvalidIsAOfCases()
734+
{
735+
return array(
736+
array(array('stdClass', 123), 'Expected class as a string. Got: integer'),
737+
array(array('Iterator', 'ArrayIterator'), 'Expected an instance of this class or to this class among his parents "ArrayIterator". Got: "Iterator"'),
738+
array(array(123, 'Iterator'), 'Expected an instance of this class or to this class among his parents "Iterator". Got: 123'),
739+
array(array(array(), 'Iterator'), 'Expected an instance of this class or to this class among his parents "Iterator". Got: array'),
740+
);
741+
}
742+
743+
/**
744+
* @dataProvider getInvalidIsAOfCases
745+
*/
746+
public function testIsAOfExceptionMessages($args, $exceptionMessage)
747+
{
748+
$this->expectException('\InvalidArgumentException');
749+
$this->expectExceptionMessage($exceptionMessage);
750+
751+
call_user_func_array(array('Webmozart\Assert\Assert', 'isAOf'), $args);
752+
}
732753
}
733754

734755
/**

0 commit comments

Comments
 (0)