Last active
August 29, 2015 14:02
-
-
Save elnur/b9c17f4b042b0deae405 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' => '[email protected]', | |
]), | |
])); | |
$this->assertCount(0, $this->companyRepository->findByAdminOrEmployeeEmailDomain('example.com')); | |
} | |
public function testFindByAdminOrEmployeeEmailDomainWithAdminEmailMatching() | |
{ | |
$company = $this->companyRepository->save(ModelFactory::createCompany([ | |
'admin' => ModelFactory::createUser([ | |
'email' => '[email protected]', | |
]), | |
])); | |
$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' => '[email protected]', | |
]), | |
'employees' => [ | |
ModelFactory::createUser([ | |
'email' => '[email protected]', | |
]), | |
], | |
])); | |
$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' => '[email protected]', | |
]), | |
'employees' => [ | |
ModelFactory::createUser([ | |
'email' => '[email protected]', | |
]), | |
ModelFactory::createUser([ | |
'email' => '[email protected]', | |
]), | |
], | |
])); | |
$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' => '[email protected]', | |
]), | |
'pendingEmployees' => [ | |
ModelFactory::createUser([ | |
'email' => '[email protected]', | |
]), | |
], | |
])); | |
$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