sonata-project /
SonataAdminBundle
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /* |
||
| 6 | * This file is part of the Sonata Project package. |
||
| 7 | * |
||
| 8 | * (c) Thomas Rabaix <[email protected]> |
||
| 9 | * |
||
| 10 | * For the full copyright and license information, please view the LICENSE |
||
| 11 | * file that was distributed with this source code. |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace Sonata\AdminBundle\Tests\Action; |
||
| 15 | |||
| 16 | use PHPUnit\Framework\TestCase; |
||
| 17 | use Prophecy\Argument; |
||
| 18 | use Sonata\AdminBundle\Action\GetShortObjectDescriptionAction; |
||
| 19 | use Sonata\AdminBundle\Action\SetObjectFieldValueAction; |
||
| 20 | use Sonata\AdminBundle\Admin\AbstractAdmin; |
||
| 21 | use Sonata\AdminBundle\Admin\FieldDescriptionInterface; |
||
| 22 | use Sonata\AdminBundle\Admin\Pool; |
||
| 23 | use Sonata\AdminBundle\Model\ModelManagerInterface; |
||
| 24 | use Sonata\AdminBundle\Templating\TemplateRegistryInterface; |
||
| 25 | use Sonata\AdminBundle\Twig\Extension\SonataAdminExtension; |
||
| 26 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||
| 27 | use Symfony\Component\HttpFoundation\Request; |
||
| 28 | use Symfony\Component\HttpFoundation\Response; |
||
| 29 | use Symfony\Component\PropertyAccess\PropertyAccessor; |
||
| 30 | use Symfony\Component\Validator\ConstraintViolation; |
||
| 31 | use Symfony\Component\Validator\ConstraintViolationList; |
||
| 32 | use Symfony\Component\Validator\Validator\ValidatorInterface; |
||
| 33 | use Symfony\Contracts\Translation\TranslatorInterface; |
||
| 34 | use Twig\Environment; |
||
| 35 | use Twig\Loader\ArrayLoader; |
||
| 36 | |||
| 37 | final class SetObjectFieldValueActionTest extends TestCase |
||
| 38 | { |
||
| 39 | /** |
||
| 40 | * @var Pool |
||
| 41 | */ |
||
| 42 | private $pool; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var Environment |
||
| 46 | */ |
||
| 47 | private $twig; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var GetShortObjectDescriptionAction |
||
| 51 | */ |
||
| 52 | private $action; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var AbstractAdmin |
||
| 56 | */ |
||
| 57 | private $admin; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var ValidatorInterface |
||
| 61 | */ |
||
| 62 | private $validator; |
||
| 63 | |||
| 64 | protected function setUp(): void |
||
| 65 | { |
||
| 66 | $this->twig = new Environment(new ArrayLoader([ |
||
| 67 | 'admin_template' => 'renderedTemplate', |
||
| 68 | 'field_template' => 'renderedTemplate', |
||
| 69 | ])); |
||
| 70 | $this->pool = $this->prophesize(Pool::class); |
||
| 71 | $this->admin = $this->prophesize(AbstractAdmin::class); |
||
| 72 | $this->pool->getInstance(Argument::any())->willReturn($this->admin->reveal()); |
||
| 73 | $this->admin->setRequest(Argument::type(Request::class))->shouldBeCalled(); |
||
| 74 | $this->validator = $this->prophesize(ValidatorInterface::class); |
||
| 75 | $this->action = new SetObjectFieldValueAction( |
||
|
0 ignored issues
–
show
|
|||
| 76 | $this->twig, |
||
| 77 | $this->pool->reveal(), |
||
| 78 | $this->validator->reveal() |
||
| 79 | ); |
||
| 80 | } |
||
| 81 | |||
| 82 | public function testSetObjectFieldValueAction(): void |
||
| 83 | { |
||
| 84 | $object = new Foo(); |
||
| 85 | $request = new Request([ |
||
| 86 | 'code' => 'sonata.post.admin', |
||
| 87 | 'objectId' => 42, |
||
| 88 | 'field' => 'enabled', |
||
| 89 | 'value' => 1, |
||
| 90 | 'context' => 'list', |
||
| 91 | ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']); |
||
| 92 | |||
| 93 | $fieldDescription = $this->prophesize(FieldDescriptionInterface::class); |
||
| 94 | $pool = $this->prophesize(Pool::class); |
||
| 95 | $translator = $this->prophesize(TranslatorInterface::class); |
||
| 96 | $propertyAccessor = new PropertyAccessor(); |
||
| 97 | $templateRegistry = $this->prophesize(TemplateRegistryInterface::class); |
||
| 98 | $container = $this->prophesize(ContainerInterface::class); |
||
| 99 | |||
| 100 | $this->admin->getObject(42)->willReturn($object); |
||
| 101 | $this->admin->getCode()->willReturn('sonata.post.admin'); |
||
|
0 ignored issues
–
show
|
|||
| 102 | $this->admin->hasAccess('edit', $object)->willReturn(true); |
||
|
0 ignored issues
–
show
|
|||
| 103 | $this->admin->hasListFieldDescription('enabled')->willReturn(true); |
||
|
0 ignored issues
–
show
|
|||
| 104 | $this->admin->getListFieldDescription('enabled')->willReturn($fieldDescription->reveal()); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Sonata\AdminBundl...ldDescriptionInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 105 | $this->admin->update($object)->shouldBeCalled(); |
||
|
0 ignored issues
–
show
$object is of type object<Sonata\AdminBundle\Tests\Action\Foo>, but the function expects a object<Sonata\AdminBundle\Admin\object>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 106 | $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template'); |
||
| 107 | $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal()); |
||
| 108 | $this->pool->getPropertyAccessor()->willReturn($propertyAccessor); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Symfony\Component...pertyAccessorInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 109 | $this->twig->addExtension(new SonataAdminExtension( |
||
| 110 | $pool->reveal(), |
||
| 111 | $translator->reveal(), |
||
| 112 | $container->reveal() |
||
| 113 | )); |
||
| 114 | $fieldDescription->getOption('editable')->willReturn(true); |
||
| 115 | $fieldDescription->getAdmin()->willReturn($this->admin->reveal()); |
||
|
0 ignored issues
–
show
The method
reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 116 | $fieldDescription->getType()->willReturn('boolean'); |
||
| 117 | $fieldDescription->getTemplate()->willReturn('field_template'); |
||
| 118 | $fieldDescription->getValue(Argument::cetera())->willReturn('some value'); |
||
| 119 | |||
| 120 | $this->validator->validate($object)->willReturn(new ConstraintViolationList([])); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Symfony\Component...ViolationListInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 121 | |||
| 122 | $response = ($this->action)($request); |
||
| 123 | |||
| 124 | $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); |
||
| 125 | } |
||
| 126 | |||
| 127 | public function getTimeZones(): iterable |
||
| 128 | { |
||
| 129 | $default = new \DateTimeZone(date_default_timezone_get()); |
||
| 130 | $custom = new \DateTimeZone('Europe/Rome'); |
||
| 131 | |||
| 132 | return [ |
||
| 133 | 'empty timezone' => [null, $default], |
||
| 134 | 'disabled timezone' => [false, $default], |
||
| 135 | 'default timezone by name' => [$default->getName(), $default], |
||
| 136 | 'default timezone by object' => [$default, $default], |
||
| 137 | 'custom timezone by name' => [$custom->getName(), $custom], |
||
| 138 | 'custom timezone by object' => [$custom, $custom], |
||
| 139 | ]; |
||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @dataProvider getTimeZones |
||
| 144 | */ |
||
| 145 | public function testSetObjectFieldValueActionWithDate($timezone, \DateTimeZone $expectedTimezone): void |
||
| 146 | { |
||
| 147 | $object = new Bafoo(); |
||
| 148 | $request = new Request([ |
||
| 149 | 'code' => 'sonata.post.admin', |
||
| 150 | 'objectId' => 42, |
||
| 151 | 'field' => 'dateProp', |
||
| 152 | 'value' => '2020-12-12', |
||
| 153 | 'context' => 'list', |
||
| 154 | ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']); |
||
| 155 | |||
| 156 | $fieldDescription = $this->prophesize(FieldDescriptionInterface::class); |
||
| 157 | $pool = $this->prophesize(Pool::class); |
||
| 158 | $translator = $this->prophesize(TranslatorInterface::class); |
||
| 159 | $propertyAccessor = new PropertyAccessor(); |
||
| 160 | $templateRegistry = $this->prophesize(TemplateRegistryInterface::class); |
||
| 161 | $container = $this->prophesize(ContainerInterface::class); |
||
| 162 | |||
| 163 | $this->admin->getObject(42)->willReturn($object); |
||
| 164 | $this->admin->getCode()->willReturn('sonata.post.admin'); |
||
|
0 ignored issues
–
show
|
|||
| 165 | $this->admin->hasAccess('edit', $object)->willReturn(true); |
||
|
0 ignored issues
–
show
|
|||
| 166 | $this->admin->hasListFieldDescription('dateProp')->willReturn(true); |
||
|
0 ignored issues
–
show
|
|||
| 167 | $this->admin->getListFieldDescription('dateProp')->willReturn($fieldDescription->reveal()); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Sonata\AdminBundl...ldDescriptionInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 168 | $this->admin->update($object)->shouldBeCalled(); |
||
|
0 ignored issues
–
show
$object is of type object<Sonata\AdminBundle\Tests\Action\Bafoo>, but the function expects a object<Sonata\AdminBundle\Admin\object>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 169 | |||
| 170 | $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template'); |
||
| 171 | $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal()); |
||
| 172 | $this->pool->getPropertyAccessor()->willReturn($propertyAccessor); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Symfony\Component...pertyAccessorInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 173 | $this->twig->addExtension(new SonataAdminExtension( |
||
| 174 | $pool->reveal(), |
||
| 175 | $translator->reveal(), |
||
| 176 | $container->reveal() |
||
| 177 | )); |
||
| 178 | $fieldDescription->getOption('editable')->willReturn(true); |
||
| 179 | $fieldDescription->getOption('timezone')->willReturn($timezone); |
||
| 180 | $fieldDescription->getAdmin()->willReturn($this->admin->reveal()); |
||
|
0 ignored issues
–
show
The method
reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 181 | $fieldDescription->getType()->willReturn('date'); |
||
| 182 | $fieldDescription->getTemplate()->willReturn('field_template'); |
||
| 183 | $fieldDescription->getValue(Argument::cetera())->willReturn('some value'); |
||
| 184 | |||
| 185 | $this->validator->validate($object)->willReturn(new ConstraintViolationList([])); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Symfony\Component...ViolationListInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 186 | |||
| 187 | $response = ($this->action)($request); |
||
| 188 | |||
| 189 | $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); |
||
| 190 | |||
| 191 | $defaultTimezone = new \DateTimeZone(date_default_timezone_get()); |
||
| 192 | $expectedDate = new \DateTime($request->query->get('value'), $expectedTimezone); |
||
| 193 | $expectedDate->setTimezone($defaultTimezone); |
||
| 194 | |||
| 195 | $this->assertInstanceOf(\DateTime::class, $object->getDateProp()); |
||
| 196 | $this->assertSame($expectedDate->format('Y-m-d'), $object->getDateProp()->format('Y-m-d')); |
||
| 197 | $this->assertSame($defaultTimezone->getName(), $object->getDateProp()->getTimezone()->getName()); |
||
| 198 | } |
||
| 199 | |||
| 200 | public function testSetObjectFieldValueActionOnARelationField(): void |
||
| 201 | { |
||
| 202 | $object = new Baz(); |
||
| 203 | $associationObject = new Bar(); |
||
| 204 | $request = new Request([ |
||
| 205 | 'code' => 'sonata.post.admin', |
||
| 206 | 'objectId' => 42, |
||
| 207 | 'field' => 'bar', |
||
| 208 | 'value' => 1, |
||
| 209 | 'context' => 'list', |
||
| 210 | ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']); |
||
| 211 | |||
| 212 | $fieldDescription = $this->prophesize(FieldDescriptionInterface::class); |
||
| 213 | $modelManager = $this->prophesize(ModelManagerInterface::class); |
||
| 214 | $translator = $this->prophesize(TranslatorInterface::class); |
||
| 215 | $propertyAccessor = new PropertyAccessor(); |
||
| 216 | $templateRegistry = $this->prophesize(TemplateRegistryInterface::class); |
||
| 217 | $container = $this->prophesize(ContainerInterface::class); |
||
| 218 | |||
| 219 | $this->admin->getObject(42)->willReturn($object); |
||
| 220 | $this->admin->getCode()->willReturn('sonata.post.admin'); |
||
|
0 ignored issues
–
show
|
|||
| 221 | $this->admin->hasAccess('edit', $object)->willReturn(true); |
||
|
0 ignored issues
–
show
|
|||
| 222 | $this->admin->hasListFieldDescription('bar')->willReturn(true); |
||
|
0 ignored issues
–
show
|
|||
| 223 | $this->admin->getListFieldDescription('bar')->willReturn($fieldDescription->reveal()); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Sonata\AdminBundl...ldDescriptionInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 224 | $this->admin->getClass()->willReturn(\get_class($object)); |
||
|
0 ignored issues
–
show
|
|||
| 225 | $this->admin->update($object)->shouldBeCalled(); |
||
|
0 ignored issues
–
show
$object is of type object<Sonata\AdminBundle\Tests\Action\Baz>, but the function expects a object<Sonata\AdminBundle\Admin\object>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 226 | $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal()); |
||
| 227 | $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template'); |
||
| 228 | $this->admin->getModelManager()->willReturn($modelManager->reveal()); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Sonata\AdminBundl...\ModelManagerInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 229 | $this->twig->addExtension(new SonataAdminExtension( |
||
| 230 | $this->pool->reveal(), |
||
|
0 ignored issues
–
show
The method
reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\Pool>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 231 | $translator->reveal(), |
||
| 232 | $container->reveal() |
||
| 233 | )); |
||
| 234 | $this->pool->getPropertyAccessor()->willReturn($propertyAccessor); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Symfony\Component...pertyAccessorInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 235 | $fieldDescription->getType()->willReturn('choice'); |
||
| 236 | $fieldDescription->getOption('editable')->willReturn(true); |
||
| 237 | $fieldDescription->getOption('class')->willReturn(Bar::class); |
||
| 238 | $fieldDescription->getTargetModel()->willReturn(Bar::class); |
||
| 239 | $fieldDescription->getAdmin()->willReturn($this->admin->reveal()); |
||
|
0 ignored issues
–
show
The method
reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 240 | $fieldDescription->getTemplate()->willReturn('field_template'); |
||
| 241 | $fieldDescription->getValue(Argument::cetera())->willReturn('some value'); |
||
| 242 | $modelManager->find(\get_class($associationObject), 1)->willReturn($associationObject); |
||
| 243 | |||
| 244 | $this->validator->validate($object)->willReturn(new ConstraintViolationList([])); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Symfony\Component...ViolationListInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 245 | |||
| 246 | $response = ($this->action)($request); |
||
| 247 | |||
| 248 | $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); |
||
| 249 | } |
||
| 250 | |||
| 251 | public function testSetObjectFieldValueActionWithViolations(): void |
||
| 252 | { |
||
| 253 | $bar = new Bar(); |
||
| 254 | $object = new Baz(); |
||
| 255 | $object->setBar($bar); |
||
| 256 | $request = new Request([ |
||
| 257 | 'code' => 'sonata.post.admin', |
||
| 258 | 'objectId' => 42, |
||
| 259 | 'field' => 'bar.enabled', |
||
| 260 | 'value' => 1, |
||
| 261 | 'context' => 'list', |
||
| 262 | ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']); |
||
| 263 | |||
| 264 | $fieldDescription = $this->prophesize(FieldDescriptionInterface::class); |
||
| 265 | $propertyAccessor = new PropertyAccessor(); |
||
| 266 | |||
| 267 | $this->pool->getPropertyAccessor()->willReturn($propertyAccessor); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Symfony\Component...pertyAccessorInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 268 | $this->admin->getObject(42)->willReturn($object); |
||
| 269 | $this->admin->hasAccess('edit', $object)->willReturn(true); |
||
|
0 ignored issues
–
show
|
|||
| 270 | $this->admin->hasListFieldDescription('bar.enabled')->willReturn(true); |
||
|
0 ignored issues
–
show
|
|||
| 271 | $this->admin->getListFieldDescription('bar.enabled')->willReturn($fieldDescription->reveal()); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Sonata\AdminBundl...ldDescriptionInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 272 | $this->validator->validate($bar)->willReturn(new ConstraintViolationList([ |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Symfony\Component...ViolationListInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 273 | new ConstraintViolation('error1', null, [], null, 'enabled', null), |
||
| 274 | new ConstraintViolation('error2', null, [], null, 'enabled', null), |
||
| 275 | ])); |
||
| 276 | $fieldDescription->getOption('editable')->willReturn(true); |
||
| 277 | $fieldDescription->getType()->willReturn('boolean'); |
||
| 278 | |||
| 279 | $response = ($this->action)($request); |
||
| 280 | |||
| 281 | $this->assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode()); |
||
| 282 | $this->assertSame(json_encode("error1\nerror2"), $response->getContent()); |
||
| 283 | } |
||
| 284 | |||
| 285 | public function testSetObjectFieldEditableMultipleValue(): void |
||
| 286 | { |
||
| 287 | $object = new StatusMultiple(); |
||
| 288 | $request = new Request([ |
||
| 289 | 'code' => 'sonata.post.admin', |
||
| 290 | 'objectId' => 42, |
||
| 291 | 'field' => 'status', |
||
| 292 | 'value' => [1, 2], |
||
| 293 | 'context' => 'list', |
||
| 294 | ], [], [], [], [], ['REQUEST_METHOD' => Request::METHOD_POST, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']); |
||
| 295 | |||
| 296 | $fieldDescription = $this->prophesize(FieldDescriptionInterface::class); |
||
| 297 | $pool = $this->prophesize(Pool::class); |
||
| 298 | $template = $this->prophesize(Template::class); |
||
|
0 ignored issues
–
show
$template is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 299 | $translator = $this->prophesize(TranslatorInterface::class); |
||
| 300 | $propertyAccessor = new PropertyAccessor(); |
||
| 301 | $templateRegistry = $this->prophesize(TemplateRegistryInterface::class); |
||
| 302 | $container = $this->prophesize(ContainerInterface::class); |
||
| 303 | |||
| 304 | $this->admin->getObject(42)->willReturn($object); |
||
| 305 | $this->admin->getCode()->willReturn('sonata.post.admin'); |
||
|
0 ignored issues
–
show
|
|||
| 306 | $this->admin->hasAccess('edit', $object)->willReturn(true); |
||
|
0 ignored issues
–
show
|
|||
| 307 | $this->admin->hasListFieldDescription('status')->willReturn(true); |
||
|
0 ignored issues
–
show
|
|||
| 308 | $this->admin->getListFieldDescription('status')->willReturn($fieldDescription->reveal()); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Sonata\AdminBundl...ldDescriptionInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 309 | $this->admin->update($object)->shouldBeCalled(); |
||
|
0 ignored issues
–
show
$object is of type object<Sonata\AdminBundl...\Action\StatusMultiple>, but the function expects a object<Sonata\AdminBundle\Admin\object>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 310 | $templateRegistry->getTemplate('base_list_field')->willReturn('admin_template'); |
||
| 311 | $container->get('sonata.post.admin.template_registry')->willReturn($templateRegistry->reveal()); |
||
| 312 | $this->pool->getPropertyAccessor()->willReturn($propertyAccessor); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Symfony\Component...pertyAccessorInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 313 | $this->twig->addExtension(new SonataAdminExtension( |
||
| 314 | $pool->reveal(), |
||
| 315 | $translator->reveal(), |
||
| 316 | $container->reveal() |
||
| 317 | )); |
||
| 318 | $fieldDescription->getOption('editable')->willReturn(true); |
||
| 319 | $fieldDescription->getOption('multiple')->willReturn(true); |
||
| 320 | $fieldDescription->getAdmin()->willReturn($this->admin->reveal()); |
||
|
0 ignored issues
–
show
The method
reveal() does not seem to exist on object<Sonata\AdminBundle\Admin\AbstractAdmin>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 321 | $fieldDescription->getType()->willReturn('boolean'); |
||
| 322 | $fieldDescription->getTemplate()->willReturn('field_template'); |
||
| 323 | $fieldDescription->getValue(Argument::cetera())->willReturn(['some value']); |
||
| 324 | |||
| 325 | $this->validator->validate($object)->willReturn(new ConstraintViolationList([])); |
||
|
0 ignored issues
–
show
The method
willReturn() does not seem to exist on object<Symfony\Component...ViolationListInterface>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 326 | |||
| 327 | $response = ($this->action)($request); |
||
| 328 | |||
| 329 | $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); |
||
| 330 | } |
||
| 331 | } |
||
| 332 |
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..