Skip to content

Commit

Permalink
Merge pull request #2348 from deZinc/refactor-admin-clonelistener-test
Browse files Browse the repository at this point in the history
[AdminBundle] refactored the CloneListenerTest
  • Loading branch information
acrobat committed Feb 12, 2019
2 parents 632e408 + 6179e5f commit e04158d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Expand Up @@ -2,29 +2,38 @@

namespace Kunstmaan\AdminBundle\Tests\EventListener;

use Kunstmaan\AdminBundle\Entity\AbstractEntity;
use Kunstmaan\AdminBundle\Entity\DeepCloneInterface;
use Kunstmaan\AdminBundle\Event\DeepCloneAndSaveEvent;
use Kunstmaan\AdminBundle\EventListener\CloneListener;
use Kunstmaan\MediaBundle\Entity\Media;
use PHPUnit\Framework\TestCase;

class CloneListenerTest extends TestCase
{
public function testListener()
public function testOnDeepCloneAndSaveWithAbstractEntity()
{
$listener = new CloneListener();
$user = new Media();
$user->setId(666);
$dc = $this->createMock(DeepCloneInterface::class);
$dc->expects($this->once())->method('deepClone')->willReturn(true);

/** @var AbstractEntity $entityMock */
$entityMock = $this->getMockForAbstractClass(AbstractEntity::class);
$entityMock->setId(747);

$event = $this->createMock(DeepCloneAndSaveEvent::class);
$event->expects($this->any())->method('getClonedEntity')->willReturn($user);
$event->expects($this->any())->method('getClonedEntity')->willReturn($entityMock);

$listener->onDeepCloneAndSave($event);
$this->assertNull($user->getId());
$this->assertNull($entityMock->getId());
}

public function testOnDeepCloneAndSaveWithDeepCloneInterface()
{
$listener = new CloneListener();

$deepCloneInterfaceMock = $this->createMock(DeepCloneInterface::class);
$deepCloneInterfaceMock->expects($this->once())->method('deepClone');

$event = $this->createMock(DeepCloneAndSaveEvent::class);
$event->expects($this->any())->method('getClonedEntity')->willReturn($dc);
$event->expects($this->any())->method('getClonedEntity')->willReturn($deepCloneInterfaceMock);

$listener->onDeepCloneAndSave($event);
}
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Kunstmaan\MediaBundle\Tests\Validator\Constraints;
namespace Kunstmaan\AdminBundle\Tests\Validator\Constraints;

use Kunstmaan\AdminBundle\Validator\Constraints\PasswordRestrictions;
use Kunstmaan\AdminBundle\Validator\Constraints\PasswordRestrictionsValidator;
Expand Down
2 changes: 1 addition & 1 deletion src/Kunstmaan/AdminBundle/composer.json
Expand Up @@ -54,10 +54,10 @@
},
"suggest": {
"kunstmaan/user-management-bundle": "^5.2",
"kunstmaan/media-bundle": "^5.2",
"doctrine/doctrine-migrations-bundle": "^1.3"
},
"require-dev": {
"kunstmaan/media-bundle": "^5.2",
"kunstmaan/menu-bundle": "^5.2",
"kunstmaan/translator-bundle": "^5.2",
"symfony/phpunit-bridge": "^4.2",
Expand Down

0 comments on commit e04158d

Please sign in to comment.