ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilDatabaseAtomRunTest Class Reference

TestCase for the ilDatabaseAtomBaseTest. More...

+ Inheritance diagram for ilDatabaseAtomRunTest:
+ Collaboration diagram for ilDatabaseAtomRunTest:

Public Member Functions

 tearDown ()
 
 testConnection ()
 
 setupTable ()
 
 testTableExists ()
 
 testWriteWithTransactions ()
 
 testWriteWithLocks ()
 
 testWriteWithLocksAndAlias ()
 
 testWriteWithMultipleLocksAndAlias ()
 
 testWriteWithMultipleLocksWithAndWithoutAlias ()
 
 testNoTables ()
 
 testNoQueries ()
 
 testUpdateDuringTransaction ()
 
 testUpdateDuringLock ()
 

Protected Member Functions

 setUp ()
 
 getInsertQueryCallable ()
 
 getTableLocksForDbInterface ()
 
 getResultFromDB ()
 
 getExpectedResult ()
 

Protected Attributes

 $backupGlobals = false
 
 $ilDBInterfaceGalera
 
 $ilDBInterfaceGaleraSecond
 
 $ilDBInterfaceInnoDB
 
 $ilDBInterfaceInnoDBSecond
 

Detailed Description

TestCase for the ilDatabaseAtomBaseTest.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
1.0.0

needsInstalledILIAS

Definition at line 32 of file ilDatabaseAtomRunTest.php.

Member Function Documentation

◆ getExpectedResult()

ilDatabaseAtomRunTest::getExpectedResult ( )
protected
Returns
array

Definition at line 309 of file ilDatabaseAtomRunTest.php.

References array.

Referenced by testWriteWithLocks(), testWriteWithLocksAndAlias(), testWriteWithMultipleLocksAndAlias(), testWriteWithMultipleLocksWithAndWithoutAlias(), and testWriteWithTransactions().

309  {
310  return array(
311  0 => array(
312  'id' => '1',
313  'is_online' => '1',
314  ),
315  1 => array(
316  'id' => '2',
317  'is_online' => '0',
318  ),
319  );
320  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getInsertQueryCallable()

ilDatabaseAtomRunTest::getInsertQueryCallable ( )
protected
Returns

Definition at line 260 of file ilDatabaseAtomRunTest.php.

References $ilDB, $query, and array.

Referenced by testNoTables(), testWriteWithLocks(), testWriteWithLocksAndAlias(), testWriteWithMultipleLocksAndAlias(), testWriteWithMultipleLocksWithAndWithoutAlias(), and testWriteWithTransactions().

260  {
261  $query = function (ilDBInterface $ilDB) {
262  $ilDB->insert('il_db_tests_atom', array(
263  'id' => array( 'integer', $ilDB->nextId('il_db_tests_atom') ),
264  'is_online' => array( 'integer', 1 ),
265  ));
266  $ilDB->insert('il_db_tests_atom', array(
267  'id' => array( 'integer', $ilDB->nextId('il_db_tests_atom') ),
268  'is_online' => array( 'integer', 0 ),
269  ));
270  };
271 
272  return $query;
273  }
Interface ilDBInterface.
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ getResultFromDB()

ilDatabaseAtomRunTest::getResultFromDB ( )
protected
Returns
array

Definition at line 295 of file ilDatabaseAtomRunTest.php.

References $d, $res, $results, and array.

Referenced by testWriteWithLocks(), testWriteWithLocksAndAlias(), testWriteWithMultipleLocksAndAlias(), testWriteWithMultipleLocksWithAndWithoutAlias(), and testWriteWithTransactions().

295  {
296  $res = $this->ilDBInterfaceGalera->query('SELECT * FROM il_db_tests_atom');
297  $results = array();
298  while ($d = $this->ilDBInterfaceGalera->fetchAssoc($res)) {
299  $results[] = $d;
300  }
301 
302  return $results;
303  }
for($col=0; $col< 50; $col++) $d
$results
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getTableLocksForDbInterface()

ilDatabaseAtomRunTest::getTableLocksForDbInterface ( )
protected
Returns
array

Definition at line 279 of file ilDatabaseAtomRunTest.php.

References array, and ilAtomQuery\LOCK_WRITE.

279  {
280  $tables = array(
281  array(
282  'name' => 'il_db_tests_atom',
283  'type' => ilAtomQuery::LOCK_WRITE,
284  'sequence' => true,
285  ),
286  );
287 
288  return $tables;
289  }
Create styles array
The data for the language used.

◆ setUp()

ilDatabaseAtomRunTest::setUp ( )
protected

Definition at line 56 of file ilDatabaseAtomRunTest.php.

References setupTable(), ilDBConstants\TYPE_GALERA, and ilDBConstants\TYPE_PDO_MYSQL_INNODB.

56  {
57  require_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
58  ilUnitUtil::performInitialisation();
59 
60  global $ilClientIniFile;
61  $this->ilDBInterfaceGalera = ilDBWrapperFactory::getWrapper(ilDBConstants::TYPE_GALERA);
62  $this->ilDBInterfaceGalera->initFromIniFile($ilClientIniFile);
63  $this->ilDBInterfaceGalera->connect();
64 
65  $this->ilDBInterfaceGaleraSecond = ilDBWrapperFactory::getWrapper(ilDBConstants::TYPE_GALERA);
66  $this->ilDBInterfaceGaleraSecond->initFromIniFile($ilClientIniFile);
67  $this->ilDBInterfaceGaleraSecond->connect();
68 
69  $this->ilDBInterfaceInnoDB = ilDBWrapperFactory::getWrapper(ilDBConstants::TYPE_PDO_MYSQL_INNODB);
70  $this->ilDBInterfaceInnoDB->initFromIniFile($ilClientIniFile);
71  $this->ilDBInterfaceInnoDB->connect();
72 
73  $this->ilDBInterfaceInnoDBSecond = ilDBWrapperFactory::getWrapper(ilDBConstants::TYPE_PDO_MYSQL_INNODB);
74  $this->ilDBInterfaceInnoDBSecond->initFromIniFile($ilClientIniFile);
75  $this->ilDBInterfaceInnoDBSecond->connect();
76 
77  $this->setupTable();
78  }
+ Here is the call graph for this function:

◆ setupTable()

ilDatabaseAtomRunTest::setupTable ( )

Definition at line 94 of file ilDatabaseAtomRunTest.php.

References array.

Referenced by setUp().

94  {
95  if ($this->ilDBInterfaceGalera->sequenceExists('il_db_tests_atom')) {
96  $this->ilDBInterfaceGalera->dropSequence('il_db_tests_atom');
97  }
98  $this->ilDBInterfaceGalera->createTable('il_db_tests_atom', $fields = array(
99  'id' => array(
100  'type' => 'integer',
101  'length' => 4,
102  'notnull' => true,
103  ),
104  'is_online' => array(
105  'type' => 'integer',
106  'length' => 1,
107  'notnull' => false,
108  ),
109  ), true);
110  $this->ilDBInterfaceGalera->addPrimaryKey('il_db_tests_atom', array( 'id' ));
111  $this->ilDBInterfaceGalera->createSequence('il_db_tests_atom');
112  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ tearDown()

ilDatabaseAtomRunTest::tearDown ( )

Definition at line 81 of file ilDatabaseAtomRunTest.php.

81  {
82  $this->ilDBInterfaceGalera->dropSequence('il_db_tests_atom');
83  $this->ilDBInterfaceGalera->dropTable('il_db_tests_atom');
84  }

◆ testConnection()

ilDatabaseAtomRunTest::testConnection ( )

Definition at line 87 of file ilDatabaseAtomRunTest.php.

87  {
88  $this->assertTrue($this->ilDBInterfaceGalera->connect(true));
89  $this->assertTrue($this->ilDBInterfaceGaleraSecond->connect(true));
90  $this->assertTrue($this->ilDBInterfaceInnoDB->connect(true));
91  }

◆ testNoQueries()

ilDatabaseAtomRunTest::testNoQueries ( )

Definition at line 186 of file ilDatabaseAtomRunTest.php.

186  {
187  $this->setExpectedException('ilDatabaseException');
188  $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
189  $ilAtomQuery->addTableLock('il_db_tests_atom');
190 
191  $ilAtomQuery->run();
192  }

◆ testNoTables()

ilDatabaseAtomRunTest::testNoTables ( )

Definition at line 177 of file ilDatabaseAtomRunTest.php.

References getInsertQueryCallable().

177  {
178  $this->setExpectedException('ilDatabaseException');
179  $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
180  $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
181 
182  $ilAtomQuery->run();
183  }
+ Here is the call graph for this function:

◆ testTableExists()

ilDatabaseAtomRunTest::testTableExists ( )

Definition at line 115 of file ilDatabaseAtomRunTest.php.

115  {
116  $this->assertTrue($this->ilDBInterfaceGalera->tableExists('il_db_tests_atom'));
117  }

◆ testUpdateDuringLock()

ilDatabaseAtomRunTest::testUpdateDuringLock ( )

Definition at line 224 of file ilDatabaseAtomRunTest.php.

References $d, $query, $res, array, and ilAtomQuery\LOCK_WRITE.

224  {
225  $this->ilDBInterfaceInnoDB->insert('il_db_tests_atom', array(
226  'id' => array( 'integer', $this->ilDBInterfaceInnoDB->nextId('il_db_tests_atom') ),
227  'is_online' => array( 'integer', 1 ),
228  ));
229  // Start a Transaction with one instance and update the same entry as another instance
230  $this->ilDBInterfaceInnoDB->lockTables(array( array( 'name' => 'il_db_tests_atom', 'type' => ilAtomQuery::LOCK_WRITE ) ));
231  $this->ilDBInterfaceInnoDB->update('il_db_tests_atom', array(
232  'is_online' => array( 'integer', 5 ),
233  ), array( 'id' => array( 'integer', 1 ) ));
234 
235  // Update the same entry with another instance (which currently fails due to missing multi-thread in PHP)
236  // $this->ilDBInterfaceInnoDBSecond->update('il_db_tests_atom', array(
237  // 'is_online' => array( 'integer', 6 ),
238  // ), array( 'id' => array( 'integer', 1 ) ), true);
239 
240  // Unlock Tables
241  $this->ilDBInterfaceInnoDB->unlockTables();
242 
243  // Check
244  $query = 'SELECT is_online FROM il_db_tests_atom WHERE id = ' . $this->ilDBInterfaceInnoDB->quote(1, 'integer');
245  $res = $this->ilDBInterfaceInnoDB->query($query);
246  $d = $this->ilDBInterfaceInnoDB->fetchAssoc($res);
247 
248  $this->assertEquals(5, $d['is_online']);
249  }
for($col=0; $col< 50; $col++) $d
Create styles array
The data for the language used.

◆ testUpdateDuringTransaction()

ilDatabaseAtomRunTest::testUpdateDuringTransaction ( )

Definition at line 195 of file ilDatabaseAtomRunTest.php.

References $d, $query, $res, and array.

195  {
196  $this->ilDBInterfaceGalera->insert('il_db_tests_atom', array(
197  'id' => array( 'integer', $this->ilDBInterfaceGalera->nextId('il_db_tests_atom') ),
198  'is_online' => array( 'integer', 1 ),
199  ));
200 
201  // Start a Transaction with one instance and update the same entry as another instance
202  $this->ilDBInterfaceGalera->beginTransaction();
203  $this->ilDBInterfaceGalera->update('il_db_tests_atom', array(
204  'is_online' => array( 'integer', 5 ),
205  ), array( 'id' => array( 'integer', 1 ) ));
206 
207  // Update the same entry with another instance (which currently fails due to missing multi-thread in PHP)
208  // $this->ilDBInterfaceGaleraSecond->update('il_db_tests_atom', array(
209  // 'is_online' => array( 'integer', 6 ),
210  // ), array( 'id' => array( 'integer', 1 ) ), true);
211 
212  // Commit the other
213  $this->ilDBInterfaceGalera->commit();
214 
215  // Check
216  $query = 'SELECT is_online FROM il_db_tests_atom WHERE id = ' . $this->ilDBInterfaceGalera->quote(1, 'integer');
217  $res = $this->ilDBInterfaceGalera->query($query);
218  $d = $this->ilDBInterfaceGalera->fetchAssoc($res);
219 
220  $this->assertEquals(5, $d['is_online']);
221  }
for($col=0; $col< 50; $col++) $d
Create styles array
The data for the language used.

◆ testWriteWithLocks()

ilDatabaseAtomRunTest::testWriteWithLocks ( )

Definition at line 131 of file ilDatabaseAtomRunTest.php.

References getExpectedResult(), getInsertQueryCallable(), and getResultFromDB().

131  {
132  $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
133  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true);
134  $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
135 
136  $ilAtomQuery->run();
137 
138  $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
139  }
+ Here is the call graph for this function:

◆ testWriteWithLocksAndAlias()

ilDatabaseAtomRunTest::testWriteWithLocksAndAlias ( )

Definition at line 142 of file ilDatabaseAtomRunTest.php.

References getExpectedResult(), getInsertQueryCallable(), and getResultFromDB().

142  {
143  $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
144  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true)->aliasName('my_alias');
145  $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
146 
147  $ilAtomQuery->run();
148 
149  $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
150  }
+ Here is the call graph for this function:

◆ testWriteWithMultipleLocksAndAlias()

ilDatabaseAtomRunTest::testWriteWithMultipleLocksAndAlias ( )

Definition at line 153 of file ilDatabaseAtomRunTest.php.

References getExpectedResult(), getInsertQueryCallable(), and getResultFromDB().

153  {
154  $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
155  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true)->aliasName('my_alias');
156  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true)->aliasName('my_second_alias');
157  $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
158 
159  $ilAtomQuery->run();
160 
161  $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
162  }
+ Here is the call graph for this function:

◆ testWriteWithMultipleLocksWithAndWithoutAlias()

ilDatabaseAtomRunTest::testWriteWithMultipleLocksWithAndWithoutAlias ( )

Definition at line 165 of file ilDatabaseAtomRunTest.php.

References getExpectedResult(), getInsertQueryCallable(), and getResultFromDB().

165  {
166  $ilAtomQuery = $this->ilDBInterfaceInnoDB->buildAtomQuery();
167  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true);
168  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true)->aliasName('my_alias');
169  $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
170 
171  $ilAtomQuery->run();
172 
173  $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
174  }
+ Here is the call graph for this function:

◆ testWriteWithTransactions()

ilDatabaseAtomRunTest::testWriteWithTransactions ( )

Definition at line 120 of file ilDatabaseAtomRunTest.php.

References getExpectedResult(), getInsertQueryCallable(), and getResultFromDB().

120  {
121  $ilAtomQuery = $this->ilDBInterfaceGalera->buildAtomQuery();
122  $ilAtomQuery->addTableLock('il_db_tests_atom')->lockSequence(true);
123  $ilAtomQuery->addQueryCallable($this->getInsertQueryCallable());
124 
125  $ilAtomQuery->run();
126 
127  $this->assertEquals($this->getExpectedResult(), $this->getResultFromDB());
128  }
+ Here is the call graph for this function:

Field Documentation

◆ $backupGlobals

ilDatabaseAtomRunTest::$backupGlobals = false
protected

Definition at line 37 of file ilDatabaseAtomRunTest.php.

◆ $ilDBInterfaceGalera

ilDatabaseAtomRunTest::$ilDBInterfaceGalera
protected

Definition at line 41 of file ilDatabaseAtomRunTest.php.

◆ $ilDBInterfaceGaleraSecond

ilDatabaseAtomRunTest::$ilDBInterfaceGaleraSecond
protected

Definition at line 45 of file ilDatabaseAtomRunTest.php.

◆ $ilDBInterfaceInnoDB

ilDatabaseAtomRunTest::$ilDBInterfaceInnoDB
protected

Definition at line 49 of file ilDatabaseAtomRunTest.php.

◆ $ilDBInterfaceInnoDBSecond

ilDatabaseAtomRunTest::$ilDBInterfaceInnoDBSecond
protected

Definition at line 53 of file ilDatabaseAtomRunTest.php.


The documentation for this class was generated from the following file: