Skip to content

Commit

Permalink
Merge pull request #34 from stekycz/improvement/tests
Browse files Browse the repository at this point in the history
Improvement/tests
  • Loading branch information
stekycz committed Aug 19, 2014
2 parents 2134e94 + 78c7065 commit 9130d7f
Show file tree
Hide file tree
Showing 22 changed files with 149 additions and 83 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
tests export-ignore
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
1 change: 0 additions & 1 deletion Cronner/CriticalSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public function leave($label)
return FALSE;
}

$this->locks[$label] = NULL;
fclose($this->locks[$label]);
unset($this->locks[$label]);

Expand Down
6 changes: 3 additions & 3 deletions Cronner/DI/CronnerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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);
}
}

Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
File renamed without changes.
File renamed without changes.
124 changes: 124 additions & 0 deletions tests/CronnerTests/DI/CronnerExtension.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

/**
* Test: stekycz\Cronner\DI\CronnerExtension
*
* @testCase stekycz\Cronner\tests\DI\CronnerExtensionTest
*/

namespace stekycz\Cronner\tests\DI;

use Nette;
use stekycz\Cronner\DI\CronnerExtension;
use Tester\Assert;



require_once(__DIR__ . "/../bootstrap.php");

/**
* @author Martin Štekl <[email protected]>
*/
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());
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand Down
7 changes: 3 additions & 4 deletions tests/bootstrap.php → tests/CronnerTests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

use Mockista\Registry;
use Nette\Utils\FileSystem;

$autoloader = require_once __DIR__ . '/../vendor/autoload.php';
$autoloader = require_once __DIR__ . '/../../vendor/autoload.php';

define("TEST_DIR", __DIR__);
define("TEMP_DIR", TEST_DIR . '/tmp/' . getmypid());
FileSystem::createDir(TEMP_DIR);
define("TEMP_DIR", TEST_DIR . '/../tmp/' . (isset($_SERVER['argv']) ? md5(serialize($_SERVER['argv'])) : getmypid()));
Tester\Environment::setup();

function run(Tester\TestCase $testCase)
{
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions tests/Run.bat

This file was deleted.

3 changes: 2 additions & 1 deletion tests/composer-nette-2.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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",
Expand Down
3 changes: 2 additions & 1 deletion tests/composer-nette-2.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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",
Expand Down
3 changes: 2 additions & 1 deletion tests/composer-nette-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 0 additions & 11 deletions tests/php.ini-win

This file was deleted.

45 changes: 0 additions & 45 deletions tests/run.sh

This file was deleted.

0 comments on commit 9130d7f

Please sign in to comment.