Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use real event for test #2718

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Comment on lines -64 to +55
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are testing behavior, instead of expecting that the EventArgs::getObjectManager() and EventArgs::getObject() are called, we can check with the result of these calls.

}
}