Skip to content

Instantly share code, notes, and snippets.

@elnur
Last active August 29, 2015 14:02
Show Gist options
  • Save elnur/b9c17f4b042b0deae405 to your computer and use it in GitHub Desktop.
Save elnur/b9c17f4b042b0deae405 to your computer and use it in GitHub Desktop.
<?php
namespace Example\Repository\Doctrine\ORM;
use Example\Test\AbstractIntegrationTest;
use Example\Util\ModelFactory;
class CompanyRepositoryTest extends AbstractIntegrationTest
{
/**
* @var CompanyRepository
*/
private $companyRepository;
protected function setUp()
{
parent::setUp();
$this->companyRepository = $this->getContainer()->get('company_repository');
}
public function testFindByAdminOrEmployeeEmailDomainWithNoMatchingDomain()
{
$this->companyRepository->save(ModelFactory::createCompany([
'admin' => ModelFactory::createUser([
'email' => 'me@other.com',
]),
]));
$this->assertCount(0, $this->companyRepository->findByAdminOrEmployeeEmailDomain('example.com'));
}
public function testFindByAdminOrEmployeeEmailDomainWithAdminEmailMatching()
{
$company = $this->companyRepository->save(ModelFactory::createCompany([
'admin' => ModelFactory::createUser([
'email' => 'me@example.com',
]),
]));
$companies = $this->companyRepository->findByAdminOrEmployeeEmailDomain('example.com');
$this->assertCount(1, $companies);
$this->assertEquals($company->getId(), $companies[0]->getId());
}
public function testFindByAdminOrEmployeeEmailDomainWithEmployeeEmailMatching()
{
$company = $this->companyRepository->save(ModelFactory::createCompany([
'admin' => ModelFactory::createUser([
'email' => 'me@other.com',
]),
'employees' => [
ModelFactory::createUser([
'email' => 'foo@example.com',
]),
],
]));
$companies = $this->companyRepository->findByAdminOrEmployeeEmailDomain('example.com');
$this->assertCount(1, $companies);
$this->assertEquals($company->getId(), $companies[0]->getId());
}
public function testFindByAdminOrEmployeeEmailDomainWithAdminAndSeveralEmployeesEmailsMatching()
{
$company = $this->companyRepository->save(ModelFactory::createCompany([
'admin' => ModelFactory::createUser([
'email' => 'me@example.com',
]),
'employees' => [
ModelFactory::createUser([
'email' => 'foo@example.com',
]),
ModelFactory::createUser([
'email' => 'bar@example.com',
]),
],
]));
$companies = $this->companyRepository->findByAdminOrEmployeeEmailDomain('example.com');
$this->assertCount(1, $companies);
$this->assertEquals($company->getId(), $companies[0]->getId());
}
public function testFindByAdminOrEmployeeEmailDomainDoesNotMatchPendingEmployees()
{
$this->companyRepository->save(ModelFactory::createCompany([
'admin' => ModelFactory::createUser([
'email' => 'me@other.com',
]),
'pendingEmployees' => [
ModelFactory::createUser([
'email' => 'foo@example.com',
]),
],
]));
$this->assertEmpty($this->companyRepository->findByAdminOrEmployeeEmailDomain('example.com'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment