modifs.mineures sans commentaires
This commit is contained in:
parent
3def66748b
commit
8cf225ea1e
|
@ -16,7 +16,9 @@ class ValueException extends Exception {
|
|||
foreach ($values as $value) {
|
||||
$parts[] = self::value($value);
|
||||
}
|
||||
return "[".implode(", ", $parts)."]";
|
||||
return "[" . implode(", ", $parts) . "]";
|
||||
} elseif (is_string($value)) {
|
||||
return $value;
|
||||
} else {
|
||||
return var_export($value, true);
|
||||
}
|
||||
|
@ -42,6 +44,11 @@ class ValueException extends Exception {
|
|||
return new static(self::message($value, $message, $kind, $prefix, " is invalid"));
|
||||
}
|
||||
|
||||
static final function unexpected_class($class, string $expected_class) {
|
||||
if (is_object($class)) $class = get_class($class);
|
||||
return new static(self::message($class, null, "class", null, " is invalid, expected $expected_class"));
|
||||
}
|
||||
|
||||
static final function forbidden($value=null, ?string $kind=null, ?string $prefix=null, ?string $message=null): self {
|
||||
return new static(self::message($value, $message, $kind, $prefix, " is forbidden"));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
namespace nulib;
|
||||
|
||||
use nulib\tests\TestCase;
|
||||
|
||||
class ValueExceptionTest extends TestCase {
|
||||
function testUnexpectedClass() {
|
||||
$e = ValueException::unexpected_class(null, self::class);
|
||||
self::assertSame("class is invalid, expected ".self::class, $e->getMessage());
|
||||
|
||||
$e = ValueException::unexpected_class(ValueException::class, self::class);
|
||||
self::assertSame(ValueException::class.": class is invalid, expected ".self::class, $e->getMessage());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue