Debian Codegraph @

tests/classes/Domains/DomainListTest.php

raw symbols SCIP
1 <?php
2
3 namespace Liuch\DmarcSrg;
4
5 use Liuch\DmarcSrg\Users\UserList;
6 use Liuch\DmarcSrg\Domains\Domain;
7 use Liuch\DmarcSrg\Domains\DomainList;
8
9 class DomainListTest extends \PHPUnit\Framework\TestCase
10 {
11 public function testGettingList(): void
12 {
13 $data = [
14 [ 'id' => 1, 'fqdn' => 'example.org' ],
15 [ 'id' => 2, 'fqdn' => 'example.net' ],
16 [ 'id' => 3, 'fqdn' => 'example.com' ]
17 ];
18 $user = UserList::getUserByName('admin');
19 $result = (new DomainList($user, $this->getDbMapperOnce('list', $data)))->getList();
20 $this->assertSame(false, $result['more']);
21 $list = $result['domains'];
22 $this->assertSame(count($data), count($list));
23 $this->assertContainsOnlyInstancesOf(Domain::class, $list);
24 foreach ($list as $key => $dom) {
25 $di = $data[$key];
26 $this->assertSame($di['id'], $dom->id());
27 $this->assertSame($di['fqdn'], $dom->fqdn());
28 }
29 }
30
31 public function testGettingNames(): void
32 {
33 $user = UserList::getUserByName('admin');
34 $names = [ 'example.org', 'example.net', 'example.com' ];
35 $this->assertSame($names, (new DomainList($user, $this->getDbMapperOnce('names', $names)))->names());
36 }
37
38 private function getDbMapperOnce(string $method, $value): object
39 {
40 $mapper = $this->getMockBuilder(Database\DomainMapperInterface::class)
41 ->disableOriginalConstructor()
42 ->getMock();
43 $mapper->expects($this->once())
44 ->method($method)
45 ->willReturnCallback(function () use ($value) {
46 return $value;
47 });
48
49 $db = $this->getMockBuilder(Database\DatabaseConnector::class)
50 ->disableOriginalConstructor()
51 ->getMock();
52 $db->method('getMapper')
53 ->with('domain')
54 ->willReturn($mapper);
55 return $db;
56 }
57 }