1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DoctrineTest\InstantiatorTest\Exception; |
4
|
|
|
|
5
|
|
|
use Doctrine\Instantiator\Exception\InvalidArgumentException; |
6
|
|
|
use Doctrine\Instantiator\InstantiatorInterface; |
7
|
|
|
use DoctrineTest\InstantiatorTestAsset\AbstractClassAsset; |
8
|
|
|
use DoctrineTest\InstantiatorTestAsset\SimpleTraitAsset; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use ReflectionClass; |
11
|
|
|
use function sprintf; |
12
|
|
|
use function str_replace; |
13
|
|
|
use function uniqid; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Tests for {@see \Doctrine\Instantiator\Exception\InvalidArgumentException} |
17
|
|
|
* |
18
|
|
|
* @covers \Doctrine\Instantiator\Exception\InvalidArgumentException |
19
|
|
|
*/ |
20
|
|
|
class InvalidArgumentExceptionTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
public function testFromNonExistingTypeWithNonExistingClass() : void |
23
|
|
|
{ |
24
|
|
|
$className = self::class . str_replace('.', '', uniqid('', true)); |
25
|
|
|
$exception = InvalidArgumentException::fromNonExistingClass($className); |
26
|
|
|
|
27
|
|
|
self::assertInstanceOf(InvalidArgumentException::class, $exception); |
28
|
|
|
self::assertSame('The provided class "' . $className . '" does not exist', $exception->getMessage()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testFromNonExistingTypeWithTrait() : void |
32
|
|
|
{ |
33
|
|
|
$exception = InvalidArgumentException::fromNonExistingClass(SimpleTraitAsset::class); |
34
|
|
|
|
35
|
|
|
self::assertSame( |
36
|
|
|
sprintf('The provided type "%s" is a trait, and can not be instantiated', SimpleTraitAsset::class), |
37
|
|
|
$exception->getMessage() |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testFromNonExistingTypeWithInterface() : void |
42
|
|
|
{ |
43
|
|
|
$exception = InvalidArgumentException::fromNonExistingClass(InstantiatorInterface::class); |
44
|
|
|
|
45
|
|
|
self::assertSame( |
46
|
|
|
sprintf( |
47
|
|
|
'The provided type "%s" is an interface, and can not be instantiated', |
48
|
|
|
InstantiatorInterface::class |
49
|
|
|
), |
50
|
|
|
$exception->getMessage() |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testFromAbstractClass() : void |
55
|
|
|
{ |
56
|
|
|
$reflection = new ReflectionClass(AbstractClassAsset::class); |
57
|
|
|
$exception = InvalidArgumentException::fromAbstractClass($reflection); |
58
|
|
|
|
59
|
|
|
self::assertSame( |
60
|
|
|
sprintf( |
61
|
|
|
'The provided class "%s" is abstract, and can not be instantiated', |
62
|
|
|
AbstractClassAsset::class |
63
|
|
|
), |
64
|
|
|
$exception->getMessage() |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|