ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
IntegrityTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 use ilDBInterface;
30 use ilDBStatement;
31 
32 class 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(self::once())->method('query')->willReturn($statement);
47  $db->expects(self::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(self::once())->method('associations')->willReturn([$association]);
61  $definition->expects(self::once())->method('tableName')->willReturn('table_a');
62  $definition->expects(self::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->assertEquals(17, $result->violations());
70  }
71 }