|
1
|
|
|
<?php |
|
2
|
|
|
namespace SRF\Tests\Integration\JSONScript; |
|
3
|
|
|
use SMW\Tests\Integration\JSONScript\JsonTestCaseScriptRunnerTest as SMWJsonTestCaseScriptRunnerTest; |
|
4
|
|
|
/** |
|
5
|
|
|
* @see https://github.com/SemanticMediaWiki/SemanticMediaWiki/tree/master/tests#write-integration-tests-using-json-script |
|
6
|
|
|
* |
|
7
|
|
|
* `JsonTestCaseScriptRunner` provisioned by SMW is a base class allowing to use a JSON |
|
8
|
|
|
* format to create test definitions with the objective to compose "real" content |
|
9
|
|
|
* and test integration with MediaWiki, Semantic MediaWiki, and Scribunto. |
|
10
|
|
|
* |
|
11
|
|
|
* @group SRF |
|
12
|
|
|
* @group SMWExtension |
|
13
|
|
|
* |
|
14
|
|
|
* @license GNU GPL v2+ |
|
15
|
|
|
* @since 2.5 |
|
16
|
|
|
* |
|
17
|
|
|
* @author Stephan Gambke |
|
18
|
|
|
*/ |
|
19
|
|
|
class JsonTestCaseScriptRunnerTest extends SMWJsonTestCaseScriptRunnerTest { |
|
20
|
|
|
/** |
|
21
|
|
|
* @see \SMW\Tests\JsonTestCaseScriptRunner::getTestCaseLocation |
|
22
|
|
|
* @return string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected function getTestCaseLocation() { |
|
25
|
|
|
return __DIR__ . '/TestCases'; |
|
26
|
|
|
} |
|
27
|
|
|
/** |
|
28
|
|
|
* @return string[] |
|
29
|
|
|
* @since 3.0 |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function getPermittedSettings() { |
|
32
|
|
|
$settings = parent::getPermittedSettings(); |
|
33
|
|
|
$settings[] = 'srfgMapProvider'; |
|
34
|
|
|
return $settings; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @see JsonTestCaseScriptRunner::getDependencyDefinitions |
|
39
|
|
|
*/ |
|
40
|
|
|
protected function getDependencyDefinitions() { |
|
41
|
|
|
return [ |
|
|
|
|
|
|
42
|
|
|
'Mermaid' => [ $this, 'checkMermaidDependency' ] |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
public function checkMermaidDependency( $val, &$reason ) { |
|
46
|
|
|
|
|
47
|
|
|
if ( !defined( 'MERMAID_VERSION' ) ) { |
|
48
|
|
|
$reason = "Dependency: Mermaid as requirement is not available!"; |
|
49
|
|
|
return false; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
list( $compare, $requiredVersion ) = explode( ' ', $val ); |
|
53
|
|
|
$version = MERMAID_VERSION; |
|
54
|
|
|
|
|
55
|
|
|
if ( !version_compare( $version, $requiredVersion, $compare ) ) { |
|
56
|
|
|
$reason = "Dependency: Required version of Mermaid($requiredVersion $compare $version) is not available!"; |
|
57
|
|
|
return false; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return true; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
} |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.