mirror of
https://github.com/marty-oehme/scripts.git
synced 2024-12-21 15:38:09 +00:00
added tests and travis
This commit is contained in:
parent
1545a4c8a6
commit
935f04d87e
2 changed files with 77 additions and 0 deletions
12
.travis.yml
Normal file
12
.travis.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
sudo: false
|
||||
dist: trusty
|
||||
language: php
|
||||
php:
|
||||
- 7
|
||||
|
||||
script:
|
||||
- php run-tests.php
|
||||
|
||||
notifications:
|
||||
email:
|
||||
- $NOTIFICATION_EMAIL
|
65
run-tests.php
Executable file
65
run-tests.php
Executable file
|
@ -0,0 +1,65 @@
|
|||
#!/bin/env php
|
||||
<?php
|
||||
|
||||
$dirs = array_filter(glob('*'), 'is_dir');
|
||||
$testHelper = new TestHelper();
|
||||
|
||||
foreach ($dirs as $dir) {
|
||||
$testHelper->testDirectory($dir);
|
||||
}
|
||||
|
||||
$errors = $testHelper->errors;
|
||||
if (count($errors) > 0) {
|
||||
foreach($errors as $dir => $scriptErrors) {
|
||||
print "Directory '$dir'\n";
|
||||
|
||||
foreach($scriptErrors as $error) {
|
||||
print " $error\n";
|
||||
}
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
print "No errors were found";
|
||||
|
||||
|
||||
class TestHelper {
|
||||
public $errors = array();
|
||||
|
||||
/**
|
||||
* Tests the files in a directory
|
||||
*/
|
||||
public function testDirectory($dir) {
|
||||
$errors = array();
|
||||
$jsonData = file_get_contents($dir . "/info.json");
|
||||
$data = json_decode($jsonData, true);
|
||||
|
||||
if ($data["name"] == "") {
|
||||
$errors[] = "No name was entered!";
|
||||
}
|
||||
|
||||
if ($data["identifier"] == "") {
|
||||
$errors[] = "No identifier was entered!";
|
||||
}
|
||||
|
||||
if ($data["description"] == "") {
|
||||
$errors[] = "No description was entered!";
|
||||
}
|
||||
|
||||
$script = $data["script"];
|
||||
if ($script == "") {
|
||||
$errors[] = "No script was entered!";
|
||||
} elseif (!file_exists($dir . "/" . $script)) {
|
||||
$errors[] = "Script '$script' doesn't exist!";
|
||||
}
|
||||
|
||||
if ($data["version"] == "") {
|
||||
$errors[] = "No version was entered!";
|
||||
}
|
||||
|
||||
if (count($errors) > 0) {
|
||||
$this->errors[$dir] = $errors;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue