Optimized test for UserSourceDirector

This commit is contained in:
Kevin Frantz 2019-01-13 14:08:21 +01:00
parent 2837df25f8
commit d01a5f2dbd

View File

@ -2,37 +2,41 @@
namespace Tests\Unit\Domain\UserManagement; namespace Tests\Unit\Domain\UserManagement;
use App\Domain\UserManagement\UserIdentityManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use App\DBAL\Types\SystemSlugType; use App\DBAL\Types\SystemSlugType;
use App\Entity\User; use App\Entity\User;
use App\Domain\UserManagement\UserSourceDirector;
use App\Repository\Source\SourceRepository;
use App\Entity\Source\AbstractSource;
class UserIdentityManagerTest extends KernelTestCase /**
* @author kevinfrantz
*/
class UserSourceDirectorTest extends KernelTestCase
{ {
/** /**
* @var EntityManagerInterface * @var SourceRepository
*/ */
private $entityManager; private $sourceRepository;
public function setUp(): void public function setUp(): void
{ {
self::bootKernel(); self::bootKernel();
$this->entityManager = self::$container->get('doctrine.orm.default_entity_manager'); $this->sourceRepository = self::$container->get('doctrine.orm.default_entity_manager')->getRepository(AbstractSource::class);
} }
public function testGuestUser(): void public function testGuestUser(): void
{ {
$origineUser = null; $origineUser = null;
$userIdentityManager = new UserIdentityManager($this->entityManager, $origineUser); $userIdentityManager = new UserSourceDirector($this->sourceRepository, $origineUser);
$expectedUser = $userIdentityManager->getUser(); $expectedUser = $userIdentityManager->getUser();
$this->assertEquals(SystemSlugType::GUEST_USER, $expectedUser->getSource()->getSlug()); $this->assertEquals(SystemSlugType::GUEST_USER, $expectedUser->getSource()->getSlug());
} }
public function testUser(): void public function testUser(): void
{ {
$origineUser = new User(); $origineUser = $this->createMock(User::class);
$userIdentityManager = new UserIdentityManager($this->entityManager, $origineUser); $userIdentityManager = new UserSourceDirector($this->sourceRepository, $origineUser);
$expectedUser = $userIdentityManager->getUser(); $expectedUser = $userIdentityManager->getUser();
$this->assertEquals($origineUser, $expectedUser); $this->assertEquals($origineUser, $expectedUser);
} }