1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Symplify\ActionAutowire\Tests; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver; |
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
10
|
|
|
use Symplify\ActionAutowire\DependencyInjection\ServiceLocator; |
11
|
|
|
use Symplify\ActionAutowire\Tests\CompleteSource\SomeService; |
12
|
|
|
use Symplify\ActionAutowire\Tests\Controller\SomeController; |
13
|
|
|
|
14
|
|
|
final class CompleteTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var ServiceLocator |
18
|
|
|
*/ |
19
|
|
|
private $serviceLocator; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var ControllerResolver |
23
|
|
|
*/ |
24
|
|
|
private $controllerResolver; |
25
|
|
|
|
26
|
|
|
protected function setUp() |
27
|
|
|
{ |
28
|
|
|
$kernel = new AppKernel(); |
29
|
|
|
$kernel->boot(); |
30
|
|
|
|
31
|
|
|
$this->serviceLocator = $kernel->getContainer() |
32
|
|
|
->get('symplify.action_autowire.service_locator'); |
33
|
|
|
|
34
|
|
|
$this->controllerResolver = $kernel->getContainer() |
35
|
|
|
->get('debug.controller_resolver'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testServiceLocator() |
39
|
|
|
{ |
40
|
|
|
$this->assertInstanceOf(SomeService::class, $this->serviceLocator->getByType(SomeService::class)); |
41
|
|
|
|
42
|
|
|
$this->assertFalse($this->serviceLocator->getByType('missing')); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testGetAutowiredControllerAction() |
46
|
|
|
{ |
47
|
|
|
$request = new Request(); |
48
|
|
|
$request->attributes->set('_controller', SomeController::class . '::someServiceAwareAction'); |
49
|
|
|
|
50
|
|
|
$controller = $this->controllerResolver->getController($request); |
51
|
|
|
$arguments = $this->controllerResolver->getArguments($request, $controller); |
|
|
|
|
52
|
|
|
|
53
|
|
|
$this->assertInstanceOf(SomeService::class, $arguments[0]); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.