Skip to content

Commit

Permalink
Use instance of mappers
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu authored and OskarStark committed Dec 14, 2020
1 parent b3d29f6 commit 035ecab
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions tests/Event/AdminEventExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
use PHPUnit\Framework\TestCase;
use Sonata\AdminBundle\Admin\AdminExtensionInterface;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\FieldDescriptionCollection;
use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
use Sonata\AdminBundle\Builder\FormContractorInterface;
use Sonata\AdminBundle\Builder\ListBuilderInterface;
use Sonata\AdminBundle\Builder\ShowBuilderInterface;
use Sonata\AdminBundle\Datagrid\DatagridInterface;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
Expand All @@ -26,6 +32,7 @@
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\FormBuilderInterface;

class AdminEventExtensionTest extends TestCase
{
Expand All @@ -38,14 +45,6 @@ public function getExtension(array $args): AdminExtensionInterface
return new AdminEventExtension($eventDispatcher);
}

public function getMapper($class)
{
$mapper = $this->getMockBuilder($class)->disableOriginalConstructor()->getMock();
$mapper->expects($this->once())->method('getAdmin')->willReturn($this->createMock(AdminInterface::class));

return $mapper;
}

public function getConfigureEventClosure(string $type): callable
{
return static function ($event) use ($type): bool {
Expand Down Expand Up @@ -83,7 +82,11 @@ public function testConfigureFormFields(): void
$this->callback($this->getConfigureEventClosure(ConfigureEvent::TYPE_FORM)),
$this->equalTo('sonata.admin.event.configure.form'),
])
->configureFormFields($this->getMapper(FormMapper::class));
->configureFormFields(new FormMapper(
$this->createStub(FormContractorInterface::class),
$this->createStub(FormBuilderInterface::class),
$this->createStub(AdminInterface::class)
));
}

public function testConfigureListFields(): void
Expand All @@ -93,7 +96,11 @@ public function testConfigureListFields(): void
$this->callback($this->getConfigureEventClosure(ConfigureEvent::TYPE_LIST)),
$this->equalTo('sonata.admin.event.configure.list'),
])
->configureListFields($this->getMapper(ListMapper::class));
->configureListFields(new ListMapper(
$this->createStub(ListBuilderInterface::class),
new FieldDescriptionCollection(),
$this->createStub(AdminInterface::class)
));
}

public function testConfigureDatagridFields(): void
Expand All @@ -103,7 +110,11 @@ public function testConfigureDatagridFields(): void
$this->callback($this->getConfigureEventClosure(ConfigureEvent::TYPE_DATAGRID)),
$this->equalTo('sonata.admin.event.configure.datagrid'),
])
->configureDatagridFilters($this->getMapper(DatagridMapper::class));
->configureDatagridFilters(new DatagridMapper(
$this->createStub(DatagridBuilderInterface::class),
$this->createStub(DatagridInterface::class),
$this->createStub(AdminInterface::class)
));
}

public function testConfigureShowFields(): void
Expand All @@ -113,7 +124,11 @@ public function testConfigureShowFields(): void
$this->callback($this->getConfigureEventClosure(ConfigureEvent::TYPE_SHOW)),
$this->equalTo('sonata.admin.event.configure.show'),
])
->configureShowFields($this->getMapper(ShowMapper::class));
->configureShowFields(new ShowMapper(
$this->createStub(ShowBuilderInterface::class),
new FieldDescriptionCollection(),
$this->createStub(AdminInterface::class)
));
}

public function testPreUpdate(): void
Expand Down

0 comments on commit 035ecab

Please sign in to comment.