Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kunicmarko20 authored and jordisala1991 committed Feb 14, 2018
1 parent 1c43164 commit c540777
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tests/Controller/HelperControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Twig\Environment;
use Twig\Template;

class AdminControllerHelper_Foo
{
Expand Down Expand Up @@ -199,18 +201,27 @@ public function testSetObjectFieldValueAction()
], [], [], [], [], ['REQUEST_METHOD' => 'POST', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']);

$fieldDescription = $this->prophesize(FieldDescriptionInterface::class);
$adminExtension = $this->prophesize(SonataAdminExtension::class);
$pool = $this->prophesize(Pool::class);
$template = $this->prophesize(Template::class);
$translator = $this->prophesize(TranslatorInterface::class);
$propertyAccessor = new PropertyAccessor();

$this->admin->getObject(42)->willReturn($object);
$this->admin->hasAccess('edit', $object)->willReturn(true);
$this->admin->getListFieldDescription('enabled')->willReturn($fieldDescription->reveal());
$this->admin->update($object)->shouldBeCalled();
$this->admin->getTemplate('base_list_field')->willReturn('admin_template');
$this->pool->getPropertyAccessor()->willReturn($propertyAccessor);
$this->twig->getExtension(SonataAdminExtension::class)->willReturn($adminExtension->reveal());
$this->twig->getExtension(SonataAdminExtension::class)->willReturn(
new SonataAdminExtension($pool->reveal(), null, $translator->reveal())
);
$this->twig->loadTemplate('admin_template')->willReturn($template->reveal());
$this->twig->isDebug()->willReturn(false);
$fieldDescription->getOption('editable')->willReturn(true);
$fieldDescription->getAdmin()->willReturn($this->admin->reveal());
$fieldDescription->getType()->willReturn('boolean');
$fieldDescription->getTemplate()->willReturn(false);
$fieldDescription->getValue(Argument::cetera())->willReturn('some value');
$this->validator->validate($object)->willReturn(new ConstraintViolationList([]));

$response = $this->controller->setObjectFieldValueAction($request);
Expand All @@ -235,7 +246,9 @@ public function testSetObjectFieldValueActionOnARelationField()
$managerRegistry = $this->prophesize(ManagerRegistry::class);
$objectManager = $this->prophesize(ObjectManager::class);
$classMetadata = $this->prophesize(ClassMetadata::class);
$adminExtension = $this->prophesize(SonataAdminExtension::class);
$pool = $this->prophesize(Pool::class);
$template = $this->prophesize(Template::class);
$translator = $this->prophesize(TranslatorInterface::class);
$propertyAccessor = new PropertyAccessor();

$this->admin->getObject(42)->willReturn($object);
Expand All @@ -246,14 +259,19 @@ public function testSetObjectFieldValueActionOnARelationField()
$this->admin->update($object)->shouldBeCalled();
$this->admin->getTemplate('base_list_field')->willReturn('admin_template');
$this->validator->validate($object)->willReturn(new ConstraintViolationList([]));
$this->twig->getExtension(SonataAdminExtension::class)->willReturn($adminExtension->reveal());
$this->twig->getExtension(SonataAdminExtension::class)->willReturn(
new SonataAdminExtension($pool->reveal(), null, $translator->reveal())
);
$this->twig->loadTemplate('field_template')->willReturn($template->reveal());
$this->twig->isDebug()->willReturn(false);
$this->pool->getContainer()->willReturn($container->reveal());
$this->pool->getPropertyAccessor()->willReturn($propertyAccessor);
$fieldDescription->getType()->willReturn('choice');
$fieldDescription->getOption('editable')->willReturn(true);
$fieldDescription->getOption('class')->willReturn(AdminControllerHelper_Bar::class);
$fieldDescription->getAdmin()->willReturn($this->admin->reveal());
$fieldDescription->getTemplate()->willReturn('field_template');
$fieldDescription->getValue(Argument::cetera())->willReturn('some value');
$container->get('doctrine_orm')->willReturn($managerRegistry->reveal());
$managerRegistry->getManager()->willReturn($objectManager->reveal());
$objectManager->getClassMetadata(get_class($object))->willReturn($classMetadata->reveal());
Expand Down

0 comments on commit c540777

Please sign in to comment.