diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c3822b4 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +.gitattributes export-ignore +.gitignore export-ignore +.travis.yml export-ignore +tests export-ignore diff --git a/.travis.yml b/.travis.yml index 4f0a14f..9088dfd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,9 @@ before_script: - php ./tests/prepare-composer.php - composer self-update - composer install --dev --prefer-source --no-interaction - - chmod +x ./tests/run.sh + - ./vendor/bin/parallel-lint -e php,phpt --exclude vendor . -script: VERBOSE=true ./tests/run.sh -s ./tests/ +script: ./vendor/bin/tester -c ./tests/php.ini-unix ./tests/CronnerTests/ + +after_failure: + - 'for i in $(find ./tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done' diff --git a/Cronner/CriticalSection.php b/Cronner/CriticalSection.php index 564b65e..01e3291 100644 --- a/Cronner/CriticalSection.php +++ b/Cronner/CriticalSection.php @@ -83,7 +83,6 @@ public function leave($label) return FALSE; } - $this->locks[$label] = NULL; fclose($this->locks[$label]); unset($this->locks[$label]); diff --git a/Cronner/DI/CronnerExtension.php b/Cronner/DI/CronnerExtension.php index cd8bd63..4330bf4 100644 --- a/Cronner/DI/CronnerExtension.php +++ b/Cronner/DI/CronnerExtension.php @@ -42,7 +42,7 @@ public function loadConfiguration() $container = $this->getContainerBuilder(); $config = $this->getConfig($this->defaults); - Validators::assert($config['timestampStorage'], 'string|null', 'Timestamp storage definition'); + Validators::assert($config['timestampStorage'], 'string|object|null', 'Timestamp storage definition'); Validators::assert($config['maxExecutionTime'], 'integer|null', 'Script max execution time'); Validators::assert($config['criticalSectionTempDir'], 'string', 'Critical section files directory path'); @@ -60,7 +60,7 @@ public function loadConfiguration() if (is_string($config['timestampStorage']) && $container->getServiceName($config['timestampStorage'])) { $storage->setFactory($config['timestampStorage']); } else { - $storage->setClass($config['timestampStorage']->value, $config['timestampStorage']->attributes); + $storage->setClass($config['timestampStorage']->entity, $config['timestampStorage']->arguments); } } @@ -76,7 +76,7 @@ public function loadConfiguration() $storage, $criticalSection, $config['maxExecutionTime'], - !$config['debugMode'], + array_key_exists('debugMode', $config) ? !$config['debugMode'] : TRUE, )); foreach (array_keys($container->findByTag(self::TASKS_TAG)) as $serviceName) { diff --git a/composer.json b/composer.json index f6a62ca..899c969 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ }, "require-dev": { "nette/tester": "~1.2", - "janmarek/mockista": "~1.0" + "janmarek/mockista": "~1.0", + "jakub-onderka/php-parallel-lint": "~0.7" }, "suggest": { "kdyby/events": "Events for Nette Framework", diff --git a/tests/CriticalSection.phpt b/tests/CronnerTests/CriticalSection.phpt similarity index 100% rename from tests/CriticalSection.phpt rename to tests/CronnerTests/CriticalSection.phpt diff --git a/tests/Cronner.phpt b/tests/CronnerTests/Cronner.phpt similarity index 100% rename from tests/Cronner.phpt rename to tests/CronnerTests/Cronner.phpt diff --git a/tests/CronnerTests/DI/CronnerExtension.phpt b/tests/CronnerTests/DI/CronnerExtension.phpt new file mode 100644 index 0000000..fd406a9 --- /dev/null +++ b/tests/CronnerTests/DI/CronnerExtension.phpt @@ -0,0 +1,124 @@ + + */ +class CronnerExtensionTest extends \TestCase +{ + + public function testDefaultConfiguration() + { + $compiler = new CompilerMock(); + $compiler->addExtension('cronner', $cronner = new CronnerExtension()); + + $compiler->config = array(); + + $cronner->loadConfiguration(); + + $timestampStorage = $compiler->getContainerBuilder()->getDefinition('cronner.timestampStorage'); + $criticalSection = $compiler->getContainerBuilder()->getDefinition('cronner.criticalSection'); + $runner = $compiler->getContainerBuilder()->getDefinition('cronner.runner'); + + Assert::same('stekycz\Cronner\TimestampStorage\FileStorage', $timestampStorage->getClass()); + Assert::same('stekycz\Cronner\CriticalSection', $criticalSection->getClass()); + Assert::same('stekycz\Cronner\Cronner', $runner->getClass()); + } + + + + public function testCompleteConfiguration() + { + $compiler = new CompilerMock(); + $compiler->addExtension('cronner', $cronner = new CronnerExtension()); + + $compiler->config = array( + 'cronner' => array( + 'timestampStorage' => new Nette\DI\Statement('stekycz\Cronner\TimestampStorage\DummyStorage', array(TEMP_DIR . '/cronner')), + 'maxExecutionTime' => 120, + 'criticalSectionTempDir' => '%tempDir%/cronner', + ) + ); + + $cronner->loadConfiguration(); + + $timestampStorage = $compiler->getContainerBuilder()->getDefinition('cronner.timestampStorage'); + $criticalSection = $compiler->getContainerBuilder()->getDefinition('cronner.criticalSection'); + $runner = $compiler->getContainerBuilder()->getDefinition('cronner.runner'); + + Assert::same('stekycz\Cronner\TimestampStorage\DummyStorage', $timestampStorage->getClass()); + Assert::same('stekycz\Cronner\CriticalSection', $criticalSection->getClass()); + Assert::same('stekycz\Cronner\Cronner', $runner->getClass()); + } + +} + + + +class CompilerMock extends Nette\DI\Compiler +{ + + /** + * @var Nette\DI\ContainerBuilder + */ + public $containerBuilder; + + /** + * @var array + */ + public $config = array(); + + + + public function __construct() + { + $this->containerBuilder = new Nette\DI\ContainerBuilder(); + $this->containerBuilder->parameters = array( + 'appDir' => __DIR__ . '/../..', + 'wwwDir' => __DIR__ . '/../..', + 'tempDir' => TEMP_DIR, + 'debugMode' => FALSE, + 'productionMode' => TRUE, + ); + } + + + + /** + * @return array + */ + public function getConfig() + { + return $this->config; + } + + + + /** + * @return Nette\DI\ContainerBuilder + */ + public function getContainerBuilder() + { + return $this->containerBuilder; + } + +} + + + +run(new CronnerExtensionTest()); diff --git a/tests/Tasks/Parameters.phpt b/tests/CronnerTests/Tasks/Parameters.phpt similarity index 100% rename from tests/Tasks/Parameters.phpt rename to tests/CronnerTests/Tasks/Parameters.phpt diff --git a/tests/Tasks/ParametersParsing.phpt b/tests/CronnerTests/Tasks/ParametersParsing.phpt similarity index 100% rename from tests/Tasks/ParametersParsing.phpt rename to tests/CronnerTests/Tasks/ParametersParsing.phpt diff --git a/tests/Tasks/Parser.phpt b/tests/CronnerTests/Tasks/Parser.phpt similarity index 100% rename from tests/Tasks/Parser.phpt rename to tests/CronnerTests/Tasks/Parser.phpt diff --git a/tests/Tasks/Task.phpt b/tests/CronnerTests/Tasks/Task.phpt similarity index 98% rename from tests/Tasks/Task.phpt rename to tests/CronnerTests/Tasks/Task.phpt index 88a7e3f..56456f3 100644 --- a/tests/Tasks/Task.phpt +++ b/tests/CronnerTests/Tasks/Task.phpt @@ -54,6 +54,7 @@ class TaskTest extends \TestCase $method = new Method($this->object, 'test01'); $task = new Task($this->object, $method, $timestampStorage); $task($now); + Assert::$counter++; // Hack for nette tester } diff --git a/tests/TimestampStorage/FileStorage.phpt b/tests/CronnerTests/TimestampStorage/FileStorage.phpt similarity index 98% rename from tests/TimestampStorage/FileStorage.phpt rename to tests/CronnerTests/TimestampStorage/FileStorage.phpt index a9e1c3e..0e9305a 100644 --- a/tests/TimestampStorage/FileStorage.phpt +++ b/tests/CronnerTests/TimestampStorage/FileStorage.phpt @@ -59,6 +59,7 @@ class FileStorageTest extends \TestCase $this->storage->setTaskName('Test task 1'); $this->storage->setTaskName(NULL); $this->storage->setTaskName(); + Assert::$counter++; // Hack for nette tester } diff --git a/tests/bootstrap.php b/tests/CronnerTests/bootstrap.php similarity index 69% rename from tests/bootstrap.php rename to tests/CronnerTests/bootstrap.php index aad7fc2..16c8bd7 100644 --- a/tests/bootstrap.php +++ b/tests/CronnerTests/bootstrap.php @@ -1,13 +1,12 @@ &2 - echo "php composer.phar update --dev." >&2 - exit 2 -fi - -# Path to php.ini if passed as argument option -phpIni= -while getopts ":c:" opt; do - case $opt in - c) phpIni="$OPTARG" - ;; - - :) echo "Missing argument for -$OPTARG option" >&2 - exit 2 - ;; - esac -done - -for i in $(find . -name \*.actual); do rm -f "$i"; done -find "$dir/tmp/" -mindepth 1 -maxdepth 1 -depth \( ! -iname ".*" \) -exec rm -rf {} \; - -# Runs tests with script's arguments, add default php.ini if not specified -# Doubled -c option intentionally -if [ -n "$phpIni" ]; then - php -c "$phpIni" "$runnerScript" -j 20 "$@" -else - php -c "$dir/php.ini-unix" "$runnerScript" -j 20 -c "$dir/php.ini-unix" "$@" -fi -error=$? - -# Print *.actual content if tests failed -if [ "${VERBOSE-false}" != "false" -a $error -ne 0 ]; then - echo - for i in $(find . -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done -fi - -exit $error