1 | <?php |
||
33 | final class AppendFormFieldElementActionTest extends TestCase |
||
34 | { |
||
35 | /** |
||
36 | * @var Pool |
||
37 | */ |
||
38 | private $pool; |
||
39 | |||
40 | /** |
||
41 | * @var Environment |
||
42 | */ |
||
43 | private $twig; |
||
44 | |||
45 | /** |
||
46 | * @var GetShortObjectDescriptionAction |
||
47 | */ |
||
48 | private $action; |
||
49 | |||
50 | /** |
||
51 | * @var AbstractAdmin |
||
52 | */ |
||
53 | private $admin; |
||
54 | |||
55 | /** |
||
56 | * @var ValidatorInterface |
||
57 | */ |
||
58 | private $validator; |
||
59 | |||
60 | /** |
||
61 | * @var AdminHelper |
||
62 | */ |
||
63 | private $helper; |
||
64 | |||
65 | protected function setUp(): void |
||
66 | { |
||
67 | $this->twig = $this->prophesize(Environment::class); |
||
68 | $this->pool = $this->prophesize(Pool::class); |
||
69 | $this->admin = $this->prophesize(AbstractAdmin::class); |
||
70 | $this->pool->getInstance(Argument::any())->willReturn($this->admin->reveal()); |
||
71 | $this->admin->setRequest(Argument::type(Request::class))->shouldBeCalled(); |
||
72 | $this->validator = $this->prophesize(ValidatorInterface::class); |
||
73 | $this->helper = $this->prophesize(AdminHelper::class); |
||
74 | $this->action = new AppendFormFieldElementAction( |
||
|
|||
75 | $this->twig->reveal(), |
||
76 | $this->pool->reveal(), |
||
77 | $this->helper->reveal() |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | public function testAppendFormFieldElementAction(): void |
||
82 | { |
||
83 | $object = new \stdClass(); |
||
84 | $request = new Request([ |
||
85 | 'code' => 'sonata.post.admin', |
||
86 | 'objectId' => 42, |
||
87 | 'elementId' => 'element_42', |
||
88 | 'field' => 'enabled', |
||
89 | 'value' => 1, |
||
90 | 'context' => 'list', |
||
91 | ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST]); |
||
92 | |||
93 | $modelManager = $this->prophesize(ModelManagerInterface::class); |
||
94 | $formView = new FormView(); |
||
95 | $form = $this->prophesize(Form::class); |
||
96 | $renderer = $this->configureFormRenderer(); |
||
97 | |||
98 | $this->admin->getObject(42)->willReturn($object); |
||
99 | $this->admin->getClass()->willReturn(\get_class($object)); |
||
100 | $this->admin->setSubject($object)->shouldBeCalled(); |
||
101 | $this->admin->getFormTheme()->willReturn([$formView]); |
||
102 | $this->helper->appendFormFieldElement($this->admin->reveal(), $object, 'element_42')->willReturn([ |
||
103 | $this->prophesize(FieldDescriptionInterface::class), |
||
104 | $form->reveal(), |
||
105 | ]); |
||
106 | $this->helper->getChildFormView($formView, 'element_42') |
||
107 | ->willReturn($formView); |
||
108 | $modelManager->find(\get_class($object), 42)->willReturn($object); |
||
109 | $form->createView()->willReturn($formView); |
||
110 | $renderer->setTheme($formView, [$formView])->shouldBeCalled(); |
||
111 | $renderer->searchAndRenderBlock($formView, 'widget')->willReturn('block'); |
||
112 | |||
113 | $response = ($this->action)($request); |
||
114 | |||
115 | $this->assertInstanceOf(Response::class, $response); |
||
116 | $this->assertSame($response->getContent(), 'block'); |
||
117 | } |
||
118 | |||
119 | private function configureFormRenderer() |
||
127 | } |
||
128 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..