ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilServicesActiveRecordConnectorTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
25 {
30  protected $db_mock;
31 
32  protected function setUp(): void
33  {
34  global $DIC;
35  $this->dic_backup = is_object($DIC) ? clone $DIC : $DIC;
36 
37  $DIC = new Container();
38  $DIC['ilDB'] = $this->db_mock = $this->createMock(ilDBInterface::class);
39  }
40 
41  protected function tearDown(): void
42  {
43  global $DIC;
44  $DIC = $this->dic_backup;
45  }
46 
47  public function testDbConnector(): void
48  {
49  $test_ar = new ilBiblEntry();
50  $this->db_mock->expects($this->once())
51  ->method('nextId')
53  ->willReturn(1);
54 
55  $connector = new arConnectorDB($this->db_mock);
56  $this->assertEquals(1, $connector->nextID($test_ar));
57 
58  $this->db_mock->expects($this->once())
59  ->method('tableExists')
61  ->willReturn(true);
62  $this->assertEquals(true, $connector->checkTableExists($test_ar));
63 
64  $this->db_mock->expects($this->once())
65  ->method('tableColumnExists')
66  ->with(ilBiblEntry::TABLE_NAME, 'data_id')
67  ->willReturn(true);
68  $this->assertEquals(true, $connector->checkFieldExists($test_ar, 'data_id'));
69  }
70 
71  public function testConnectorMap(): void
72  {
73  $cache_connector = new arConnectorCache(new arConnectorDB($this->db_mock));
74  $ar = new class () extends ActiveRecord {
84  protected int $id = 0;
85  };
86  arConnectorMap::register($ar, $cache_connector);
87  $this->assertEquals($cache_connector, arConnectorMap::get($ar));
88  }
89 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static register(ActiveRecord $ar, arConnector $connector)
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:31
global $DIC
Definition: feed.php:28
Class ilGSStorageCache.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static get(ActiveRecord $ar)