From eafbdf1b3b60398abaf811f7c9a71cc61ea0dc1c Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Sun, 30 Jun 2013 14:47:25 +0200 Subject: [PATCH 1/4] add syntax-check script --- tests/syntax.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 tests/syntax.sh diff --git a/tests/syntax.sh b/tests/syntax.sh new file mode 100755 index 0000000..d8f1313 --- /dev/null +++ b/tests/syntax.sh @@ -0,0 +1,9 @@ +#! /usr/bin/env bash + +echo "Testing PHP syntax..." +set -o pipefail + +for file in $(find . -name '*.php'); +do + php -l "$file" | sed 's/^/ /' || { echo 'Syntax check failed!'; exit 1; } +done \ No newline at end of file From 590eca8714849da0483f0385350f60e6e2383f96 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Sun, 30 Jun 2013 14:48:03 +0200 Subject: [PATCH 2/4] add script to retrieve package schema --- tests/setup/schema.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tests/setup/schema.sh diff --git a/tests/setup/schema.sh b/tests/setup/schema.sh new file mode 100755 index 0000000..9cd526d --- /dev/null +++ b/tests/setup/schema.sh @@ -0,0 +1,26 @@ +#! /usr/bin/env bash + +# get the current branch +if [ ! -n "$TRAVIS_BRANCH" ] +then + if [ ! -d ".git" ] + then + CURRENT_BRANCH="master" + else + CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` + fi +else + CURRENT_BRANCH="$TRAVIS_BRANCH" +fi + +# check if the current branch also exists on ALD-API +curl -s -f "https://api.github.com/repos/Library-Distribution/ALD-API/branches/$CURRENT_BRANCH" &> /dev/null +if [ $? == 22 ] +then + SCHEMA_BRANCH="master" +else + SCHEMA_BRANCH="$CURRENT_BRANCH" +fi + +# fetch the schema from github +curl -s -f -H "Accept: application/vnd.github.3.raw" -o "package.xsd" "https://api.github.com/repos/Library-Distribution/ALD-API/contents/schema/package.xsd?ref=$SCHEMA_BRANCH" \ No newline at end of file From 8207acfa789bd865642c6e7110afb3e193ef5558 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Sun, 30 Jun 2013 14:50:23 +0200 Subject: [PATCH 3/4] add travis setup --- .travis.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..12cf170 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +language: php +php: + - "5.5" + - "5.4" + - "5.3" + - "5.2" + +before_script: + - ./tests/setup/schema.sh + +script: + - ./tests/syntax.sh + - phpunit --colors tests From 65a1184ca83615c631dfc5fd808495db5f1b6908 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Sun, 30 Jun 2013 16:05:32 +0200 Subject: [PATCH 4/4] add tests for ALDVersionSwitch validation --- tests/ALDVersionSwitchTest.php | 74 ++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/ALDVersionSwitchTest.php diff --git a/tests/ALDVersionSwitchTest.php b/tests/ALDVersionSwitchTest.php new file mode 100644 index 0000000..5225090 --- /dev/null +++ b/tests/ALDVersionSwitchTest.php @@ -0,0 +1,74 @@ + 'error')); + } + + /** + * @dataProvider invalid_ranges + * @expectedException InvalidVersionSwitchException + * @expectedExceptionMessage Invalid version range + */ + public function test_validate_range($data) { + new ALDVersionSwitch($data); + } + + public function invalid_ranges() { + $data = array(array('min' => 1), + array('max' => 2), + array('min' => 1, 'max' => 2, 'dummy' => 'error'), + array('error', 'min' => 1, 'max' => 2), + array('min' => 2, 'max' => 1)); + return array_map(create_function('$a', 'return array(array("version-range" => $a));'), $data); + } + + /** + * @dataProvider invalid_lists + * @expectedException InvalidVersionSwitchException + * @expectedExceptionMessage Invalid version list + */ + public function test_validate_list($data) { + new ALDVersionSwitch($data); + } + + public function invalid_lists() { + $data = array(NULL, + array('a' => '2', '1', 2), + array(1 => 'a', 'b', 'c')); + return array_map(create_function('$a', 'return array(array("version-list" => $a));'), $data); + } + + /** + * @expectedException InvalidVersionSwitchException + * @expectedExceptionMessage Invalid version: must not be NULL + */ + public function test_validate_version() { + new ALDVersionSwitch(array('version' => NULL)); + } +} +?> \ No newline at end of file