Skip to content
Snippets Groups Projects
Commit db5867f1 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

fix tests for newer PHPUnit. fixes #1643

getMock is deprecated in new PHPUnit versions and createMock is the
recommended replacement. However that one is not available in older
PHPUnit releases. Since we still support older PHP releases we have to
support older PHPUnit releases as well.

This add some compatibility functions to our TestCase class and replaces
all calls to getMock. Tested with PHPUnit 4.6.6 and 5.5.0.
parent d6c7b502
No related branches found
No related tags found
No related merge requests found
...@@ -127,4 +127,33 @@ abstract class DokuWikiTest extends PHPUnit_Framework_TestCase { ...@@ -127,4 +127,33 @@ abstract class DokuWikiTest extends PHPUnit_Framework_TestCase {
global $INPUT; global $INPUT;
$INPUT = new Input(); $INPUT = new Input();
} }
/**
* Compatibility for older PHPUnit versions
*
* @param string $originalClassName
* @return PHPUnit_Framework_MockObject_MockObject
*/
protected function createMock($originalClassName) {
if(is_callable(array('parent', 'createMock'))) {
return parent::createMock($originalClassName);
} else {
return $this->getMock($originalClassName);
}
}
/**
* Compatibility for older PHPUnit versions
*
* @param string $originalClassName
* @param array $methods
* @return PHPUnit_Framework_MockObject_MockObject
*/
protected function createPartialMock($originalClassName, array $methods) {
if(is_callable(array('parent', 'createPartialMock'))) {
return parent::createPartialMock($originalClassName, $methods);
} else {
return $this->getMock($originalClassName, $methods);
}
}
} }
...@@ -158,20 +158,20 @@ class TestParser { ...@@ -158,20 +158,20 @@ class TestParser {
class TestOfLexer extends DokuWikiTest { class TestOfLexer extends DokuWikiTest {
function testNoPatterns() { function testNoPatterns() {
$handler = $this->getMock('TestParser'); $handler = $this->createMock('TestParser');
$handler->expects($this->never())->method('accept'); $handler->expects($this->never())->method('accept');
$lexer = new Doku_Lexer($handler); $lexer = new Doku_Lexer($handler);
$this->assertFalse($lexer->parse("abcdef")); $this->assertFalse($lexer->parse("abcdef"));
} }
function testEmptyPage() { function testEmptyPage() {
$handler = $this->getMock('TestParser'); $handler = $this->createMock('TestParser');
$handler->expects($this->never())->method('accept'); $handler->expects($this->never())->method('accept');
$lexer = new Doku_Lexer($handler); $lexer = new Doku_Lexer($handler);
$lexer->addPattern("a+"); $lexer->addPattern("a+");
$this->assertTrue($lexer->parse("")); $this->assertTrue($lexer->parse(""));
} }
function testSinglePattern() { function testSinglePattern() {
$handler = $this->getMock('TestParser'); $handler = $this->createMock('TestParser');
$handler->expects($this->at(0))->method('accept') $handler->expects($this->at(0))->method('accept')
->with("aaa", DOKU_LEXER_MATCHED, 0)->will($this->returnValue(true)); ->with("aaa", DOKU_LEXER_MATCHED, 0)->will($this->returnValue(true));
$handler->expects($this->at(1))->method('accept') $handler->expects($this->at(1))->method('accept')
...@@ -194,7 +194,7 @@ class TestOfLexer extends DokuWikiTest { ...@@ -194,7 +194,7 @@ class TestOfLexer extends DokuWikiTest {
$this->assertTrue($lexer->parse("aaaxayyyaxaaaz")); $this->assertTrue($lexer->parse("aaaxayyyaxaaaz"));
} }
function testMultiplePattern() { function testMultiplePattern() {
$handler = $this->getMock('TestParser', array('accept')); $handler = $this->createPartialMock('TestParser', array('accept'));
$target = array("a", "b", "a", "bb", "x", "b", "a", "xxxxxx", "a", "x"); $target = array("a", "b", "a", "bb", "x", "b", "a", "xxxxxx", "a", "x");
$positions = array(0, 1, 2, 3, 5, 6, 7, 8, 14, 15); $positions = array(0, 1, 2, 3, 5, 6, 7, 8, 14, 15);
for ($i = 0; $i < count($target); $i++) { for ($i = 0; $i < count($target); $i++) {
...@@ -210,7 +210,7 @@ class TestOfLexer extends DokuWikiTest { ...@@ -210,7 +210,7 @@ class TestOfLexer extends DokuWikiTest {
class TestOfLexerModes extends DokuWikiTest { class TestOfLexerModes extends DokuWikiTest {
function testIsolatedPattern() { function testIsolatedPattern() {
$handler = $this->getMock('TestParser'); $handler = $this->createMock('TestParser');
$handler->expects($this->at(0))->method('a') $handler->expects($this->at(0))->method('a')
->with("a", DOKU_LEXER_MATCHED,0)->will($this->returnValue(true)); ->with("a", DOKU_LEXER_MATCHED,0)->will($this->returnValue(true));
$handler->expects($this->at(1))->method('a') $handler->expects($this->at(1))->method('a')
...@@ -233,7 +233,7 @@ class TestOfLexerModes extends DokuWikiTest { ...@@ -233,7 +233,7 @@ class TestOfLexerModes extends DokuWikiTest {
$this->assertTrue($lexer->parse("abaabxbaaaxaaaax")); $this->assertTrue($lexer->parse("abaabxbaaaxaaaax"));
} }
function testModeChange() { function testModeChange() {
$handler = $this->getMock('TestParser'); $handler = $this->createMock('TestParser');
$handler->expects($this->at(0))->method('a') $handler->expects($this->at(0))->method('a')
->with("a", DOKU_LEXER_MATCHED,0)->will($this->returnValue(true)); ->with("a", DOKU_LEXER_MATCHED,0)->will($this->returnValue(true));
$handler->expects($this->at(1))->method('a') $handler->expects($this->at(1))->method('a')
...@@ -268,7 +268,7 @@ class TestOfLexerModes extends DokuWikiTest { ...@@ -268,7 +268,7 @@ class TestOfLexerModes extends DokuWikiTest {
$this->assertTrue($lexer->parse("abaabaaa:ababbabbba")); $this->assertTrue($lexer->parse("abaabaaa:ababbabbba"));
} }
function testNesting() { function testNesting() {
$handler = $this->getMock('TestParser'); $handler = $this->createMock('TestParser');
$handler->expects($this->at(0))->method('a') $handler->expects($this->at(0))->method('a')
->with("aa", DOKU_LEXER_MATCHED,0)->will($this->returnValue(true)); ->with("aa", DOKU_LEXER_MATCHED,0)->will($this->returnValue(true));
$handler->expects($this->at(1))->method('a') $handler->expects($this->at(1))->method('a')
...@@ -301,7 +301,7 @@ class TestOfLexerModes extends DokuWikiTest { ...@@ -301,7 +301,7 @@ class TestOfLexerModes extends DokuWikiTest {
$this->assertTrue($lexer->parse("aabaab(bbabb)aab")); $this->assertTrue($lexer->parse("aabaab(bbabb)aab"));
} }
function testSingular() { function testSingular() {
$handler = $this->getMock('TestParser'); $handler = $this->createMock('TestParser');
$handler->expects($this->at(0))->method('a') $handler->expects($this->at(0))->method('a')
->with("aa", DOKU_LEXER_MATCHED,0)->will($this->returnValue(true)); ->with("aa", DOKU_LEXER_MATCHED,0)->will($this->returnValue(true));
$handler->expects($this->at(1))->method('b') $handler->expects($this->at(1))->method('b')
...@@ -320,7 +320,7 @@ class TestOfLexerModes extends DokuWikiTest { ...@@ -320,7 +320,7 @@ class TestOfLexerModes extends DokuWikiTest {
$this->assertTrue($lexer->parse("aabaaxxbbbxx")); $this->assertTrue($lexer->parse("aabaaxxbbbxx"));
} }
function testUnwindTooFar() { function testUnwindTooFar() {
$handler = $this->getMock('TestParser'); $handler = $this->createMock('TestParser');
$handler->expects($this->at(0))->method('a') $handler->expects($this->at(0))->method('a')
->with("aa", DOKU_LEXER_MATCHED,0)->will($this->returnValue(true)); ->with("aa", DOKU_LEXER_MATCHED,0)->will($this->returnValue(true));
$handler->expects($this->at(1))->method('a') $handler->expects($this->at(1))->method('a')
...@@ -335,7 +335,7 @@ class TestOfLexerModes extends DokuWikiTest { ...@@ -335,7 +335,7 @@ class TestOfLexerModes extends DokuWikiTest {
class TestOfLexerHandlers extends DokuWikiTest { class TestOfLexerHandlers extends DokuWikiTest {
function testModeMapping() { function testModeMapping() {
$handler = $this->getMock('TestParser'); $handler = $this->createMock('TestParser');
$handler->expects($this->at(0))->method('a') $handler->expects($this->at(0))->method('a')
->with("aa", DOKU_LEXER_MATCHED,0)->will($this->returnValue(true)); ->with("aa", DOKU_LEXER_MATCHED,0)->will($this->returnValue(true));
$handler->expects($this->at(1))->method('a') $handler->expects($this->at(1))->method('a')
...@@ -376,7 +376,7 @@ class TestOfLexerByteIndices extends DokuWikiTest { ...@@ -376,7 +376,7 @@ class TestOfLexerByteIndices extends DokuWikiTest {
function testIndex() { function testIndex() {
$doc = "aaa<file>bcd</file>eee"; $doc = "aaa<file>bcd</file>eee";
$handler = $this->getMock('TestParserByteIndex'); $handler = $this->createMock('TestParserByteIndex');
$handler->expects($this->any())->method('ignore')->will($this->returnValue(true)); $handler->expects($this->any())->method('ignore')->will($this->returnValue(true));
$handler->expects($this->at(1))->method('caught') $handler->expects($this->at(1))->method('caught')
->with("<file>", DOKU_LEXER_ENTER, strpos($doc,'<file>'))->will($this->returnValue(true)); ->with("<file>", DOKU_LEXER_ENTER, strpos($doc,'<file>'))->will($this->returnValue(true));
...@@ -402,7 +402,7 @@ class TestOfLexerByteIndices extends DokuWikiTest { ...@@ -402,7 +402,7 @@ class TestOfLexerByteIndices extends DokuWikiTest {
function testIndexLookaheadEqual() { function testIndexLookaheadEqual() {
$doc = "aaa<file>bcd</file>eee"; $doc = "aaa<file>bcd</file>eee";
$handler = $this->getMock('TestParserByteIndex'); $handler = $this->createMock('TestParserByteIndex');
$handler->expects($this->any())->method('ignore')->will($this->returnValue(true)); $handler->expects($this->any())->method('ignore')->will($this->returnValue(true));
$handler->expects($this->at(1))->method('caught') $handler->expects($this->at(1))->method('caught')
->with("<file>", DOKU_LEXER_ENTER, strpos($doc,'<file>'))->will($this->returnValue(true)); ->with("<file>", DOKU_LEXER_ENTER, strpos($doc,'<file>'))->will($this->returnValue(true));
...@@ -428,7 +428,7 @@ class TestOfLexerByteIndices extends DokuWikiTest { ...@@ -428,7 +428,7 @@ class TestOfLexerByteIndices extends DokuWikiTest {
function testIndexLookaheadNotEqual() { function testIndexLookaheadNotEqual() {
$doc = "aaa<file>bcd</file>eee"; $doc = "aaa<file>bcd</file>eee";
$handler = $this->getMock('TestParserByteIndex'); $handler = $this->createMock('TestParserByteIndex');
$handler->expects($this->any())->method('ignore')->will($this->returnValue(true)); $handler->expects($this->any())->method('ignore')->will($this->returnValue(true));
$handler->expects($this->at(1))->method('caught') $handler->expects($this->at(1))->method('caught')
->with("<file>", DOKU_LEXER_ENTER, strpos($doc,'<file>'))->will($this->returnValue(true)); ->with("<file>", DOKU_LEXER_ENTER, strpos($doc,'<file>'))->will($this->returnValue(true));
...@@ -454,7 +454,7 @@ class TestOfLexerByteIndices extends DokuWikiTest { ...@@ -454,7 +454,7 @@ class TestOfLexerByteIndices extends DokuWikiTest {
function testIndexLookbehindEqual() { function testIndexLookbehindEqual() {
$doc = "aaa<file>bcd</file>eee"; $doc = "aaa<file>bcd</file>eee";
$handler = $this->getMock('TestParserByteIndex'); $handler = $this->createMock('TestParserByteIndex');
$handler->expects($this->any())->method('ignore')->will($this->returnValue(true)); $handler->expects($this->any())->method('ignore')->will($this->returnValue(true));
$handler->expects($this->at(1))->method('caught') $handler->expects($this->at(1))->method('caught')
->with("<file>", DOKU_LEXER_ENTER, strpos($doc,'<file>'))->will($this->returnValue(true)); ->with("<file>", DOKU_LEXER_ENTER, strpos($doc,'<file>'))->will($this->returnValue(true));
...@@ -480,7 +480,7 @@ class TestOfLexerByteIndices extends DokuWikiTest { ...@@ -480,7 +480,7 @@ class TestOfLexerByteIndices extends DokuWikiTest {
function testIndexLookbehindNotEqual() { function testIndexLookbehindNotEqual() {
$doc = "aaa<file>bcd</file>eee"; $doc = "aaa<file>bcd</file>eee";
$handler = $this->getMock('TestParserByteIndex'); $handler = $this->createMock('TestParserByteIndex');
$handler->expects($this->any())->method('ignore')->will($this->returnValue(true)); $handler->expects($this->any())->method('ignore')->will($this->returnValue(true));
$handler->expects($this->at(1))->method('caught') $handler->expects($this->at(1))->method('caught')
->with("<file>", DOKU_LEXER_ENTER, strpos($doc,'<file>'))->will($this->returnValue(true)); ->with("<file>", DOKU_LEXER_ENTER, strpos($doc,'<file>'))->will($this->returnValue(true));
...@@ -511,7 +511,7 @@ class TestOfLexerByteIndices extends DokuWikiTest { ...@@ -511,7 +511,7 @@ class TestOfLexerByteIndices extends DokuWikiTest {
$doc = "ALL FOOLS ARE FOO"; $doc = "ALL FOOLS ARE FOO";
$pattern = '\bFOO\b'; $pattern = '\bFOO\b';
$handler = $this->getMock('TestParserByteIndex'); $handler = $this->createMock('TestParserByteIndex');
$handler->expects($this->any())->method('ignore')->will($this->returnValue(true)); $handler->expects($this->any())->method('ignore')->will($this->returnValue(true));
$matches = array(); $matches = array();
...@@ -527,5 +527,3 @@ class TestOfLexerByteIndices extends DokuWikiTest { ...@@ -527,5 +527,3 @@ class TestOfLexerByteIndices extends DokuWikiTest {
} }
} }
?>
...@@ -144,7 +144,7 @@ class remote_test extends DokuWikiTest { ...@@ -144,7 +144,7 @@ class remote_test extends DokuWikiTest {
parent::setUp(); parent::setUp();
// mock plugin controller to return our test plugins // mock plugin controller to return our test plugins
$pluginManager = $this->getMock('Doku_Plugin_Controller'); $pluginManager = $this->createMock('Doku_Plugin_Controller');
$pluginManager->method('getList')->willReturn(array('testplugin', 'testplugin2')); $pluginManager->method('getList')->willReturn(array('testplugin', 'testplugin2'));
$pluginManager->method('load')->willReturnCallback( $pluginManager->method('load')->willReturnCallback(
function($type, $plugin) { function($type, $plugin) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment