ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
IntegrityTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
31
32class IntegrityTest extends TestCase
33{
34 public function testConstruct(): void
35 {
36 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
37 $integrity = new Integrity($db);
38 $this->assertInstanceOf(Integrity::class, $integrity);
39 }
40
41 public function testCheck(): void
42 {
43 $statement = $this->getMockBuilder(ilDBStatement::class)->getMock();
44
45 $db = $this->getMockBuilder(ilDBInterface::class)->getMock();
46 $db->expects($this->once())->method('query')->willReturn($statement);
47 $db->expects($this->once())->method('fetchAssoc')->with($statement)->willReturn(['violations' => '17']);
48
49 $field = $this->getMockBuilder(Field::class)->disableOriginalConstructor()->getMock();
50 $field->method('fieldName')->willReturn('hej');
51
52 $referenceField = $this->getMockBuilder(Field::class)->disableOriginalConstructor()->getMock();
53 $referenceField->method('fieldName')->willReturn('ho');
54
55 $association = $this->getMockBuilder(Association::class)->disableOriginalConstructor()->getMock();
56 $association->method('field')->willReturn($field);
57 $association->method('referenceField')->willReturn($referenceField);
58
59 $definition = $this->getMockBuilder(Definition::class)->disableOriginalConstructor()->getMock();
60 $definition->expects($this->once())->method('associations')->willReturn([$association]);
61 $definition->expects($this->once())->method('tableName')->willReturn('table_a');
62 $definition->expects($this->once())->method('referenceTableName')->willReturn('table_b');
63 $definition->method('ignoreValues')->willReturn(['Some SQL.']);
64
65 $integrity = new Integrity($db);
66
67 $result = $integrity->check($definition);
68 $this->assertInstanceOf(Result::class, $result);
69 $this->assertSame(17, $result->violations());
70 }
71}
Interface ilDBInterface.
Interface ilDBStatement.