Set up environment for CI

phpcs-errors:0 phpunit-status:successful
This commit is contained in:
Joshua Ramon Enslin 2019-11-12 22:32:37 +01:00 committed by Stefan Rohde-Enslin
parent d1f9982dc3
commit ace247fc35
6 changed files with 147 additions and 2 deletions

32
.git.template Normal file
View File

@ -0,0 +1,32 @@
# If applied, this commit will ...
# Why was this change necessary? Improvements brought about by the
# change.
# End
# Format
# --------------------
# (If applied, this commit will...) <subject> (Max 72 char)
# |<---- Preferably using up to 50 chars --->|<------------------->|
# Example:
# Implement automated commit messages
# (Optional) Explain why this change is being made
# |<---- Try To Limit Each Line to a Maximum Of 72 Characters ---->|
# (Optional) Provide links or keys to any relevant tickets, articles or other resources
# Example: Github issue #23
# --- COMMIT END ---
#
# Remember to:
# * Capitalize the subject line
# * Use the imperative mood in the subject line
# * Do not end the subject line with a period
# * Separate subject from body with a blank line
# * Use the body to explain what and why vs. how
# * Can use multiple lines with "-" or "*" for bullet points in body
# --------------------
# Continuous integration messages

6
.gitignore vendored
View File

@ -1,7 +1,9 @@
*.swp
*.swo
.phpunit.result.cache
/doxygen
/pdf
/tex
/tmp
/composer.lock
/vendor

5
composer.json Normal file
View File

@ -0,0 +1,5 @@
{
"require-dev": {
"phpunit/phpunit": "^8.4"
}
}

View File

@ -0,0 +1,40 @@
#!/bin/bash
# Ensure that phpcs is available on the system.
if ! [ -x "$(command -v phpcs)" ]; then
echo "This script needs phpcs installed to run!"
exit 1;
fi
# Load environment and load list of relevant instances.
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
# Run PHPCS
PHPCS_RESULT=$(phpcs --standard=~/Rules/md_Rules/md_phpcs_rules.xml "$SCRIPT_DIR/../*.php" | grep " | " | wc -l)
for i in "$SCRIPT_DIR/../"*; do
if [ "$(echo $i | grep -v "musdb" | wc -l)" = "0" ]; then
continue
fi
PHPCS_RESULT=$(echo "$(phpcs --standard=~/Rules/md_Rules/md_phpcs_rules.xml $i/*.php | grep " | " | wc -l) + $PHPCS_RESULT" | bc)
done
# PHPCS_RESULT=$(echo "$(phpcs --standard=~/Rules/md_Rules/md_phpcs_rules.xml "$SCRIPT_DIR/../*/*.php" | grep " | " | wc -l) + $PHPCS_RESULT" | bc)
echo "phpcs-errors:$PHPCS_RESULT";
# Run PHPUnit
PHPUNIT_TEST_BASE_DIR="/var/www/vhosts/museum-digital.de/about.museum-digital.de"
$(php $PHPUNIT_TEST_BASE_DIR/vendor/bin/phpunit --stderr -c $PHPUNIT_TEST_BASE_DIR/tests/config.xml --testdox $PHPUNIT_TEST_BASE_DIR/tests)
PHPUNIT_EC=$?
echo ""
if [ "$PHPUNIT_EC" = "1" ]; then
echo "phpunit-status:failing";
else
echo "phpunit-status:successful";
fi

37
tests/config.xml Normal file
View File

@ -0,0 +1,37 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/|version|/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
cacheResult="true"
cacheTokens="true"
colors="false"
convertErrorsToExceptions="false"
convertNoticesToExceptions="false"
convertWarningsToExceptions="false"
forceCoversAnnotation="false"
printerClass="PHPUnit\TextUI\ResultPrinter"
processIsolation="true"
stopOnError="true"
stopOnFailure="true"
stopOnIncomplete="true"
stopOnSkipped="true"
stopOnRisky="true"
testSuiteLoaderClass="PHPUnit\Runner\StandardTestSuiteLoader"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
verbose="false">
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../home/</directory>
<directory suffix=".php">../inc/</directory>
<!-- <file>/path/to/file</file>
<exclude>
<directory suffix=".php">/path/to/files</directory>
<file>/path/to/file</file>
</exclude>-->
</whitelist>
</filter>
</phpunit>

29
tests/startPageTest.php Normal file
View File

@ -0,0 +1,29 @@
<?PHP
/**
* This script contains tests for the home page.
*
* @author Joshua Ramon Enslin <joshua@jrenslin.de>
*/
declare(strict_types=1);
// phpcs:disable
use PHPUnit\Framework\TestCase;
final class StartPageTest extends TestCase {
public function testHTMLOutput():void {
include __DIR__ . "/../index.php";
$output = $this->getActualOutput();
$this->assertEquals(
true,
is_string($output)
);
ob_clean();
}
}