|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DoctrineTest\InstantiatorTest\Exception; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Instantiator\Exception\UnexpectedValueException; |
|
6
|
|
|
use DoctrineTest\InstantiatorTestAsset\AbstractClassAsset; |
|
7
|
|
|
use Exception; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use ReflectionClass; |
|
10
|
|
|
use function sprintf; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Tests for {@see \Doctrine\Instantiator\Exception\UnexpectedValueException} |
|
14
|
|
|
* |
|
15
|
|
|
* @covers \Doctrine\Instantiator\Exception\UnexpectedValueException |
|
16
|
|
|
*/ |
|
17
|
|
|
class UnexpectedValueExceptionTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
public function testFromSerializationTriggeredException() : void |
|
20
|
|
|
{ |
|
21
|
|
|
$reflectionClass = new ReflectionClass($this); |
|
22
|
|
|
$previous = new Exception(); |
|
23
|
|
|
$exception = UnexpectedValueException::fromSerializationTriggeredException($reflectionClass, $previous); |
|
24
|
|
|
|
|
25
|
|
|
self::assertInstanceOf(UnexpectedValueException::class, $exception); |
|
26
|
|
|
self::assertSame($previous, $exception->getPrevious()); |
|
27
|
|
|
self::assertSame( |
|
28
|
|
|
'An exception was raised while trying to instantiate an instance of "' |
|
29
|
|
|
. self::class . '" via un-serialization', |
|
30
|
|
|
$exception->getMessage() |
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testFromUncleanUnSerialization() : void |
|
35
|
|
|
{ |
|
36
|
|
|
$reflection = new ReflectionClass(AbstractClassAsset::class); |
|
37
|
|
|
$exception = UnexpectedValueException::fromUncleanUnSerialization($reflection, 'foo', 123, 'bar', 456); |
|
38
|
|
|
|
|
39
|
|
|
self::assertInstanceOf(UnexpectedValueException::class, $exception); |
|
40
|
|
|
self::assertSame( |
|
41
|
|
|
sprintf( |
|
42
|
|
|
'Could not produce an instance of "%s" ' |
|
43
|
|
|
. 'via un-serialization, since an error was triggered in file "bar" at line "456"', |
|
44
|
|
|
AbstractClassAsset::class |
|
45
|
|
|
), |
|
46
|
|
|
$exception->getMessage() |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
$previous = $exception->getPrevious(); |
|
50
|
|
|
|
|
51
|
|
|
self::assertInstanceOf(Exception::class, $previous); |
|
52
|
|
|
self::assertSame('foo', $previous->getMessage()); |
|
53
|
|
|
self::assertSame(123, $previous->getCode()); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|