/
ControllerEventTest.php
77 lines (65 loc) · 2.35 KB
/
ControllerEventTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpKernel\Tests\Event;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Tests\Fixtures\Attribute\Bar;
use Symfony\Component\HttpKernel\Tests\Fixtures\Attribute\Baz;
use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\AttributeController;
use Symfony\Component\HttpKernel\Tests\TestHttpKernel;
class ControllerEventTest extends TestCase
{
/**
* @dataProvider provideGetAttributes
*/
public function testGetAttributes(callable $controller)
{
$event = new ControllerEvent(new TestHttpKernel(), $controller, new Request(), HttpKernelInterface::MAIN_REQUEST);
$expected = [
Bar::class => [
new Bar('class'),
new Bar('method'),
],
Baz::class => [
new Baz(),
],
];
$this->assertEquals($expected, $event->getAttributes());
}
/**
* @dataProvider provideGetAttributes
*/
public function testGetAttributesByClassName(callable $controller)
{
$event = new ControllerEvent(new TestHttpKernel(), $controller, new Request(), HttpKernelInterface::MAIN_REQUEST);
$expected = [
new Bar('class'),
new Bar('method'),
];
$this->assertEquals($expected, $event->getAttributes(Bar::class));
}
/**
* @dataProvider provideGetAttributes
*/
public function testGetAttributesByInvalidClassName(callable $controller)
{
$event = new ControllerEvent(new TestHttpKernel(), $controller, new Request(), HttpKernelInterface::MAIN_REQUEST);
$this->assertEquals([], $event->getAttributes(\stdClass::class));
}
public static function provideGetAttributes()
{
yield [[new AttributeController(), '__invoke']];
yield [new AttributeController()];
yield [(new AttributeController())->__invoke(...)];
yield [#[Bar('class'), Bar('method'), Baz] static function () {}];
}
}