|
12 | 12 | namespace Sg\DatatablesBundle\Tests; |
13 | 13 |
|
14 | 14 | use Doctrine\ORM\EntityManager; |
| 15 | +use ReflectionClass; |
| 16 | +use Sg\DatatablesBundle\Datatable\AbstractDatatable; |
15 | 17 | use Sg\DatatablesBundle\Tests\Datatables\PostDatatable; |
16 | 18 | use Symfony\Component\Routing\RouterInterface; |
17 | 19 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
@@ -64,6 +66,50 @@ public function testCreate() |
64 | 66 | $table->buildDatatable(); |
65 | 67 | } |
66 | 68 |
|
| 69 | + public function testInvalidName() |
| 70 | + { |
| 71 | + /** @noinspection PhpUndefinedMethodInspection */ |
| 72 | + $authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class); |
| 73 | + /** @noinspection PhpUndefinedMethodInspection */ |
| 74 | + $securityToken = $this->createMock(TokenStorageInterface::class); |
| 75 | + /** @noinspection PhpUndefinedMethodInspection */ |
| 76 | + $translator = $this->createMock(TranslatorInterface::class); |
| 77 | + /** @noinspection PhpUndefinedMethodInspection */ |
| 78 | + $router = $this->createMock(RouterInterface::class); |
| 79 | + /** @noinspection PhpUndefinedMethodInspection */ |
| 80 | + $twig = $this->createMock(Environment::class); |
| 81 | + |
| 82 | + /** @noinspection PhpUndefinedMethodInspection */ |
| 83 | + $em = $this->getMockBuilder(EntityManager::class) |
| 84 | + ->disableOriginalConstructor() |
| 85 | + ->setMethods( |
| 86 | + ['getClassMetadata'] |
| 87 | + ) |
| 88 | + ->getMock() |
| 89 | + ; |
| 90 | + |
| 91 | + // @noinspection PhpUndefinedMethodInspection |
| 92 | + $em->expects(static::any()) |
| 93 | + ->method('getClassMetadata') |
| 94 | + ->willReturn($this->getClassMetadataMock()) |
| 95 | + ; |
| 96 | + |
| 97 | + $mock = $this->getMockBuilder(AbstractDatatable::class) |
| 98 | + ->disableOriginalConstructor() |
| 99 | + ->setMethods(['getName']) |
| 100 | + ->getMockForAbstractClass() |
| 101 | + ; |
| 102 | + $mock->expects(static::any()) |
| 103 | + ->method('getName') |
| 104 | + ->willReturn('invalid.name') |
| 105 | + ; |
| 106 | + |
| 107 | + $refledtionClass = new ReflectionClass(AbstractDatatable::class); |
| 108 | + $constructor = $refledtionClass->getConstructor(); |
| 109 | + $this->expectException(\LogicException::class); |
| 110 | + $constructor->invoke($mock, $authorizationChecker, $securityToken, $translator, $router, $em, $twig); |
| 111 | + } |
| 112 | + |
67 | 113 | public function getClassMetadataMock() |
68 | 114 | { |
69 | 115 | /** @noinspection PhpUndefinedMethodInspection */ |
|
0 commit comments