Completed
Push — master ( 7f8003...c8692d )
by mw
08:28
created

ScribuntoLuaEngineTestBase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 76
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A getScribuntoLuaLibrary() 0 3 1
A run() 0 6 1
A overrideMwServices() 0 36 1
1
<?php
2
3
namespace SMW\Scribunto\Tests;
4
5
use SMW\Scribunto\ScribuntoLuaLibrary;
6
7
/**
8
 * Encapsulation of the Scribunto_LuaEngineTestBase class
9
 *
10
 * @license GNU GPL v2+
11
 * @since 1.0
12
 *
13
 * @author mwjames
14
 */
15
abstract class ScribuntoLuaEngineTestBase extends \Scribunto_LuaEngineTestBase
16
{
17
	/**
18
	 * @var \SMW\Scribunto\ScribuntoLuaLibrary
19
	 */
20
	private $scribuntoLuaLibrary;
21
22
	protected function setUp() {
23
		parent::setUp();
24
25
		/** @noinspection PhpParamsInspection */
26
		$this->scribuntoLuaLibrary = new ScribuntoLuaLibrary(
27
			$this->getEngine()
28
		);
29
	}
30
31
	/**
32
	 * Accesses an instance of class {@see ScribuntoLuaLibrary}
33
	 *
34
	 * @return ScribuntoLuaLibrary ScribuntoLuaLibrary
35
	 */
36
	public function getScribuntoLuaLibrary() {
37
		return $this->scribuntoLuaLibrary;
38
	}
39
40
	/**
41
	 * Only needed for MW 1.31
42
	 */
43
	public function run( \PHPUnit_Framework_TestResult $result = null ) {
44
		// MW 1.31
45
		$this->setCliArg( 'use-normal-tables', true );
46
47
		parent::run( $result );
48
	}
49
50
	/**
51
	 * @see Scribunto_LuaEngineTestBase -> MediaWikiTestCase
52
	 */
53
	protected function overrideMwServices( $configOverrides = null, array $services = [] ) {
54
55
		/**
56
		 * `MediaWikiTestCase` isolates the result with  `MediaWikiTestResult` which
57
		 * ecapsultes the commandline args and since we need to use "real" tables
58
		 * as part of "use-normal-tables" we otherwise end-up with the `CloneDatabase`
59
		 * to create TEMPORARY  TABLE by default as in:
60
		 *
61
		 * CREATE TEMPORARY  TABLE `unittest_smw_di_blob` (LIKE `smw_di_blob`) and
62
		 * because of the TEMPORARY TABLE, MySQL (not MariaDB) will complain
63
		 * about things like:
64
		 *
65
		 * SELECT p.smw_title AS prop, o_id AS id0, o0.smw_title AS v0, o0.smw_namespace
66
		 * AS v1, o0.smw_iw AS v2, o0.smw_sortkey AS v3, o0.smw_subobject AS v4,
67
		 * o0.smw_sort AS v5 FROM `unittest_smw_di_wikipage` INNER JOIN
68
		 * `unittest_smw_object_ids` AS p ON p_id=p.smw_id INNER JOIN
69
		 * `unittest_smw_object_ids` AS o0 ON o_id=o0.smw_id WHERE (s_id='29') AND
70
		 * (p.smw_iw!=':smw') AND (p.smw_iw!=':smw-delete')
71
		 *
72
		 * Function: SMW\SQLStore\EntityStore\SemanticDataLookup::fetchSemanticDataFromTable
73
		 * Error: 1137 Can't reopen table: 'p' ()
74
		 *
75
		 * The reason is that `unittest_smw_object_ids` was created as TEMPORARY TABLE
76
		 * and p is referencing to a TEMPORARY TABLE as well which isn't allowed in
77
		 * MySQL.
78
		 *
79
		 * "You cannot refer to a TEMPORARY table more than once in the same query" [0]
80
		 *
81
		 * [0] https://dev.mysql.com/doc/refman/8.0/en/temporary-table-problems.html
82
		 */
83
84
		// MW 1.32+
85
		$this->setCliArg( 'use-normal-tables', true );
86
87
		parent::overrideMwServices( $configOverrides, $services );
88
	}
89
90
}
91