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 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 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 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