Commit a7f52913 authored by Freddy's avatar Freddy
Browse files

Merge branch 'tests' into 'master'

Add first PHPUnit test

See merge request Cygnus/Cygnus!24
parents 3d8a4afe 74c2971b
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';
/** TestCore.php
* Allows using Cygnus for testing
* @Author Luke081515 <luke081515@tools.wmflabs.org>
* @Version 1.0
* @Status Beta
*/
class TestCore extends Core {
/** __construct
* @param $loginData (Array)
* $loginData[1] - the site to use
* $loginData[2] - the username to use
* $loginData[3] - the password to use
* $loginData[0] is ignored, since this program is mostly for args
** args[0] is the program name, so useless here
*/
public function __construct($loginData) {
$this->setSite($loginData[1]);
$this->setUsername($loginData[2]);
$this->setPassword($loginData[3]);
$this->initcurlArgs('TestCore', true);
$this->login();
}
/** execute
* @param - $functionData Array
** $functionData[0] is the name of the function to execute
** $functionData - all following values are the params
** Takes up to 10 parameters
* @Author Luke081515
* @returns the return value of the Cygnus function
*/
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
#!/bin/bash
# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && exit 0
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
# Install phpcs
pear install PHP_CodeSniffer
\ No newline at end of file
#!/bin/bash
# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && exit 0
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
pear install PHP_CodeSniffer
#!/bin/bash
# We need to install dependencies only for Docker
[[ ! -e /.dockerenv ]] && exit 0
set -xe
# Install git (the php image doesn't have it) which is required by composer
apt-get update -yqq
apt-get install git wget -yqq
# Install phpunit
wget https://phar.phpunit.de/phpunit-5.7.phar
chmod +x phpunit-5.7.phar
mv phpunit-5.7.phar /usr/local/bin/phpunit
phpunit --version
\ No newline at end of file
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