Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
74 changes: 74 additions & 0 deletions tests/ALDVersionSwitchTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
require_once 'PHPUnit/Framework/TestCase.php';
require_once dirname(__FILE__) . '/../ALDVersionSwitch.php';

class ALDVersionSwitchTest extends PHPUnit_Framework_TestCase {

/**
* @dataProvider empty_switches
* @expectedException InvalidVersionSwitchException
* @expectedExceptionMessage Invalid switch data
*/
public function test_validate_empty($data) {
new ALDVersionSwitch($data);
}

public function empty_switches() {
$data = array(NULL,
array(),
'abc',
1);
return array_map(create_function('$a', 'return array($a);'), $data);
}

/**
* @expectedException InvalidVersionSwitchException
* @expectedExceptionMessage Invalid switch data: unsupported fields
*/
public function test_validate_unknown() {
new ALDVersionSwitch(array('dummy' => '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));
}
}
?>
26 changes: 26 additions & 0 deletions tests/setup/schema.sh
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 9 additions & 0 deletions tests/syntax.sh
Original file line number Diff line number Diff line change
@@ -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