UserRepositoryTest added.

This commit is contained in:
Alexey Skobkin 2017-01-09 22:36:19 +03:00
parent 973207d543
commit 00b7c1d2f5
1 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,89 @@
<?php
namespace Tests\Skobkin\PointToolsBundle\Repository;
use Doctrine\ORM\EntityManager;
use Skobkin\Bundle\PointToolsBundle\DTO\TopUserDTO;
use Skobkin\Bundle\PointToolsBundle\Entity\User;
use Skobkin\Bundle\PointToolsBundle\Repository\UserRepository;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class UserRepositoryTest extends KernelTestCase
{
/**
* @var EntityManager
*/
private $em;
/**
* @var UserRepository
*/
private $userRepo;
protected function setUp()
{
self::bootKernel();
$this->em = static::$kernel->getContainer()->get('doctrine')->getManager();
$this->userRepo = $this->em->getRepository('SkobkinPointToolsBundle:User');
}
public function testFindAll()
{
$users = $this->userRepo->findAll();
$this->assertCount(5, $users, 'Not exactly 5 users in the databas');
}
public function testFindOneByLogin()
{
/** @var User $user */
$user = $this->userRepo->findOneBy(['login' => 'testuser']);
$this->assertNotNull($user, 'testuser not found');
$this->assertEquals(99999, $user->getId());
$this->assertEquals('Test User 1', $user->getName());
}
public function testFindUserByLogin()
{
$testUser = $this->userRepo->findUserByLogin('testuser');
$this->assertNotNull($testUser, 'Testuser not found in repository');
$this->assertEquals(99999, $testUser->getId(), 'Testuser ID is not 99999');
}
public function testFindUsersLikeLogin()
{
// Searching LIKE %stus% (testuserX)
$users = $this->userRepo->findUsersLikeLogin('stus');
$this->assertCount(5, $users, 'Repository found not exactly 5 users');
}
public function testGetUsersCount()
{
$count = $this->userRepo->getUsersCount();
$this->assertEquals(5, $count, 'Counted not exactly 5 users');
}
public function testFindUserSubscribersById()
{
$subscribers = $this->userRepo->findUserSubscribersById(99999);
$this->assertGreaterThanOrEqual(2, count($subscribers), 'Less than 2 subscribers found');
$this->assertLessThanOrEqual(5, count($subscribers), 'More than 5 subscribers found');
}
public function testGetTopUsers()
{
$topUsers = $this->userRepo->getTopUsers();
$this->assertCount(5, $topUsers, 'Found not exactly 5 top users');
foreach ($topUsers as $topUser) {
$this->assertInternalType(TopUserDTO::class, $topUser, 'Invalid type returned');
}
}
}