Skip to content

Commit

Permalink
Use real event for test
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu authored and phansys committed Nov 5, 2023
1 parent c5ae7a4 commit 1d367c1
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions tests/Gedmo/Mapping/MappingEventAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Gedmo\Tests\Mapping;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\PrePersistEventArgs;
use Gedmo\Mapping\Event\Adapter\ORM as EventAdapterORM;
use Gedmo\Tests\Mapping\Mock\EventSubscriberCustomMock;
use Gedmo\Tests\Mapping\Mock\EventSubscriberMock;
Expand All @@ -23,23 +23,18 @@ final class MappingEventAdapterTest extends TestCase
{
public function testCustomizedAdapter(): void
{
$emMock = $this->getMockBuilder(EntityManager::class)
->disableOriginalConstructor()
->getMock();
$subscriber = new EventSubscriberCustomMock();
$args = new LifecycleEventArgs(new \stdClass(), $emMock);
$args = new PrePersistEventArgs(new \stdClass(), $this->createStub(EntityManagerInterface::class));

$adapter = $subscriber->getAdapter($args);
static::assertInstanceOf(CustomizedORMAdapter::class, $adapter);
}

public function testCorrectAdapter(): void
{
$emMock = $this->getMockBuilder(EntityManager::class)
->disableOriginalConstructor()
->getMock();
$emMock = $this->createStub(EntityManagerInterface::class);
$subscriber = new EventSubscriberMock();
$args = new LifecycleEventArgs(new \stdClass(), $emMock);
$args = new PrePersistEventArgs(new \stdClass(), $emMock);

$adapter = $subscriber->getAdapter($args);
static::assertInstanceOf(EventAdapterORM::class, $adapter);
Expand All @@ -49,19 +44,14 @@ public function testCorrectAdapter(): void

public function testAdapterBehavior(): void
{
$eventArgsMock = $this->getMockBuilder(LifecycleEventArgs::class)
->disableOriginalConstructor()
->getMock();
$eventArgsMock->expects(static::once())
->method('getObjectManager');
$emMock = $this->createStub(EntityManagerInterface::class);
$entity = new \stdClass();

$eventArgsMock->expects(static::once())
->method('getObject')
->willReturn(new \stdClass());
$args = new PrePersistEventArgs($entity, $emMock);

$eventAdapter = new EventAdapterORM();
$eventAdapter->setEventArgs($eventArgsMock);
$eventAdapter->getObjectManager();
$eventAdapter->getObject();
$eventAdapter->setEventArgs($args);
static::assertSame($eventAdapter->getObjectManager(), $emMock);
static::assertInstanceOf(\stdClass::class, $eventAdapter->getObject());
}
}

0 comments on commit 1d367c1

Please sign in to comment.