point-tools/tests/Skobkin/PointToolsBundle/Repository/UserRepositoryTest.php

100 lines
3.1 KiB
PHP
Raw Permalink Normal View History

2017-01-09 19:36:19 +00:00
<?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(6, $users, 'Not exactly 6 users in the databas');
2017-01-09 19:36:19 +00:00
}
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(2, $users, 'Repository found not exactly 5 users');
2017-01-09 19:36:19 +00:00
}
public function testGetUsersCount()
{
$count = $this->userRepo->getUsersCount();
$this->assertEquals(6, $count, 'Counted not exactly 5 users');
2017-01-09 19:36:19 +00:00
}
public function testFindUserSubscribersById()
{
$subscribers = $this->userRepo->findUserSubscribersById(99999);
$this->assertCount(4, $subscribers, 'Not exactly 4 subscribers found for user#99999');
$subscribers = $this->userRepo->findUserSubscribersById(99998);
$this->assertCount(2, $subscribers, 'Not exactly 2 subscribers found for user#99998');
$subscribers = $this->userRepo->findUserSubscribersById(99997);
$this->assertCount(1, $subscribers, 'Not exactly 1 subscriber found for user#99997');
$subscribers = $this->userRepo->findUserSubscribersById(99996);
$this->assertCount(0, $subscribers, 'Not exactly 0 subscribers found for user#99996');
$subscribers = $this->userRepo->findUserSubscribersById(99995);
$this->assertCount(0, $subscribers, 'Not exactly 0 subscribers found for user#99995');
2017-01-09 19:36:19 +00:00
}
public function testGetTopUsers()
{
$topUsers = $this->userRepo->getTopUsers();
$this->assertCount(3, $topUsers, 'Found not exactly 3 top users');
2017-01-09 19:36:19 +00:00
foreach ($topUsers as $topUser) {
2017-01-09 20:09:14 +00:00
$this->assertEquals(TopUserDTO::class, get_class($topUser), 'Invalid type returned');
2017-01-09 19:36:19 +00:00
}
}
}