|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ApplicationTest\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Application\Enum\Site; |
|
8
|
|
|
use Application\Model\Institution; |
|
9
|
|
|
use Application\Repository\InstitutionRepository; |
|
10
|
|
|
|
|
11
|
|
|
class InstitutionRepositoryTest extends AbstractRepositoryTest |
|
12
|
|
|
{ |
|
13
|
|
|
private InstitutionRepository $repository; |
|
14
|
|
|
|
|
15
|
|
|
protected function setUp(): void |
|
16
|
|
|
{ |
|
17
|
|
|
parent::setUp(); |
|
18
|
|
|
$this->repository = _em()->getRepository(Institution::class); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testGetOrCreateByName(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$institution = $this->repository->getOrCreateByName('Test institution 5000', Site::Dilps); |
|
24
|
|
|
self::assertSame('Test institution 5000', $institution->getName()); |
|
25
|
|
|
self::assertSame(5000, $institution->getId()); |
|
26
|
|
|
|
|
27
|
|
|
$institution = $this->repository->getOrCreateByName('Test institution 5000 ', Site::Dilps); |
|
28
|
|
|
self::assertSame('Test institution 5000', $institution->getName(), 'whitespace should not matter'); |
|
29
|
|
|
self::assertSame(5000, $institution->getId()); |
|
30
|
|
|
|
|
31
|
|
|
$institution = $this->repository->getOrCreateByName('Test foo', Site::Dilps); |
|
32
|
|
|
self::assertSame('Test foo', $institution->getName()); |
|
33
|
|
|
self::assertNull($institution->getId()); |
|
34
|
|
|
|
|
35
|
|
|
$institution = $this->repository->getOrCreateByName('Test foo ', Site::Dilps); |
|
36
|
|
|
self::assertSame('Test foo', $institution->getName(), 'whitespace should not matter'); |
|
37
|
|
|
self::assertNull($institution->getId()); |
|
38
|
|
|
|
|
39
|
|
|
$institution = $this->repository->getOrCreateByName(' ', Site::Dilps); |
|
40
|
|
|
self::assertNull($institution, 'should not create with empty name'); |
|
41
|
|
|
|
|
42
|
|
|
$institution = $this->repository->getOrCreateByName(null, Site::Dilps); |
|
43
|
|
|
self::assertNull($institution, 'should not create with null name'); |
|
44
|
|
|
|
|
45
|
|
|
$institution = $this->repository->getOrCreateByName('Test institution 5000', Site::Tiresias); |
|
46
|
|
|
self::assertSame('Test institution 5000', $institution->getName()); |
|
47
|
|
|
self::assertSame(Site::Tiresias, $institution->getSite()); |
|
48
|
|
|
self::assertNull($institution->getId(), 'not the same as DILPS one'); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|