Commit 4e5c756a authored by Luke081515's avatar Luke081515
Browse files

Add first PHPUnit test

* Add PHP7.1 for lint
* Add unit as stage for CI
* Add a test of readPage
* Add a script to execute the read test with args
* Args have been added at gitlab as secret variables
* Add TestCore.php, which allows easy executing of tests
* Add BotCoreReadTest, which currently checks if readPage returns the expected value. Will get more soon.
parent 53435071
stages:
- lint
- codesniffer
- unit
lint:lint-php5.4:
stage: lint
image: php:5.4
before_script:
- bash ci/docker_install.sh > /dev/null
- bash ci/docker_install-lint.sh > /dev/null
script:
- bash ci/phplint.sh ./
......@@ -14,7 +15,7 @@ lint:lint-php5.6:
stage: lint
image: php:5.6
before_script:
- bash ci/docker_install.sh > /dev/null
- bash ci/docker_install-lint.sh > /dev/null
script:
- bash ci/phplint.sh ./
......@@ -22,7 +23,15 @@ lint:lint-php7.0:
stage: lint
image: php:7.0
before_script:
- bash ci/docker_install.sh > /dev/null
- bash ci/docker_install-lint.sh > /dev/null
script:
- bash ci/phplint.sh ./
lint:lint-php7.1:
stage: lint
image: php:7.1
before_script:
- bash ci/docker_install-lint.sh > /dev/null
script:
- bash ci/phplint.sh ./
......@@ -30,7 +39,15 @@ codesniffer:
stage: codesniffer
image: php:5.6
before_script:
- bash ci/docker_install.sh > /dev/null
- bash ci/docker_install-cs.sh > /dev/null
script:
- bash ci/phpcs.sh
allow_failure: true
unit:testRead:
stage: unit
image: php:5.6
before_script:
- bash ci/docker_install-unit.sh > /dev/null
script:
- bash ci/phpunit.sh
<?php
require_once __DIR__ . '/BotCore.php';
/** Debug.php
* * @Author Luke081515 <luke081515@tools.wmflabs.org>
* @Version 0.1
* @Status Alpha
*/
class TestCore extends Core {
public function __construct($loginData) {
$this->setSite($loginData[1]);
$this->setUsername($loginData[2]);
$this->setPassword($loginData[3]);
$this->initcurlArgs('TestCore', true);
$this->login();
}
public function execute($functionData) {
$functionName = $functionData[0];
switch(count($functionData)) {
case 1:
return $this->$functionName();
case 2:
return $this->$functionName($functionData[1]);
case 3:
return $this->$functionName($functionData[1], $functionData[2]);
case 4:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3]);
case 5:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4]);
case 6:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4],
$functionData[5]);
case 7:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4],
$functionData[5], $functionData[6]);
case 8:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4],
$functionData[5], $functionData[6], $functionData[7]);
case 9:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4],
$functionData[5], $functionData[6], $functionData[7], $functionData[8]);
case 10:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4],
$functionData[5], $functionData[6], $functionData[7], $functionData[8], $functionData[9]);
case 11:
return $this->$functionName($functionData[1], $functionData[2], $functionData[3], $functionData[4],
$functionData[5], $functionData[6], $functionData[7], $functionData[8], $functionData[9],
$functionData[10]);
default:
return null;
}
}
}
?>
\ No newline at end of file
......@@ -7,7 +7,7 @@ set -xe
# Install git (the php image doesn't have it) which is required by composer
apt-get update -yqq
apt-get install git -yqq
apt-get install git wget -yqq
# Install phpunit
wget https://phar.phpunit.de/phpunit-5.7.phar
......
cp Password.example.php Password.php
phpunit ./tests/BotCoreReadTest.php $readSite $readUser $readPwd
\ No newline at end of file
......@@ -44,7 +44,6 @@
<rule ref="Squiz.PHP.EmbeddedPhp"/>
<rule ref="Squiz.PHP.Eval"/>
<rule ref="Squiz.PHP.ForbiddenFunctions"/>
<rule ref="Squiz.PHP.GlobalKeyword"/>
<rule ref="Squiz.PHP.Heredoc"/>
<rule ref="Squiz.PHP.InnerFunctions"/>
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
......
<?php
require_once __DIR__ . '/../TestCore.php';
use PHPUnit\Framework\TestCase;
/**
* @covers BotCore
* Tests for all read function
*/
final class BotCoreReadTest extends TestCase {
public function testReadPageSuccessful() {
global $argv;
$i = 0;
for ($j = 1; isset($argv[$j]); $j++) {
$params[$i] = $argv[$j];
$i++;
}
$Core = new TestCore($params);
$expected = "#WEITERLEITUNG [[Wikipedia:Hauptseite]]";
$actually = $Core->execute(array("readPage", "Hauptseite"));
$this->assertEquals($expected, $actually);
}
}
?>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment