add initial tests.

This commit is contained in:
Paweł Jędrzejewski 2012-06-17 22:27:42 +02:00
parent 04831e062f
commit c9b8b3be9a
5 changed files with 115 additions and 2 deletions

View file

@ -36,7 +36,7 @@ class Configuration implements ConfigurationInterface
$rootNode $rootNode
->addDefaultsIfNotSet() ->addDefaultsIfNotSet()
->children() ->children()
->scalarNode('storage')->defaultValue('sylius_flow.storage.session')->end() ->scalarNode('storage')->defaultValue('sylius_flow.storage.session')->cannotBeEmpty()->end()
->end() ->end()
; ;

View file

@ -174,6 +174,10 @@ class Process implements ProcessInterface
throw new \InvalidArgumentException(sprintf('Step with name "%s" already exists', $name)); throw new \InvalidArgumentException(sprintf('Step with name "%s" already exists', $name));
} }
if (null === $step->getName()) {
$step->setName($name);
}
$this->steps[$name] = $this->orderedSteps[] = $step; $this->steps[$name] = $this->orderedSteps[] = $step;
} }

View file

@ -0,0 +1,55 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\FlowBundle\Tests\DependencyInjection;
use Sylius\Bundle\FlowBundle\DependencyInjection\SyliusFlowExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Yaml\Parser;
/**
* Dependency injection extension test.
*
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
*/
class SyliusFlowExtensionTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
*/
public function shouldThrowExceptionUnlessStorageConfigured()
{
$extension = new SyliusFlowExtension();
$config = $this->getEmptyConfig();
$config['storage'] = '';
$extension->load(array($config), new ContainerBuilder());
}
/**
* Get empty config for testing.
*
* @return array
*/
protected function getEmptyConfig()
{
$yaml =
<<<EOF
storage: sylius_flow.storage.session
EOF;
$parser = new Parser();
return $parser->parse($yaml);
}
}

View file

@ -0,0 +1,54 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\FlowBundle\Tests\Process;
use Sylius\Bundle\FlowBundle\Process\Context\ProcessContextInterface;
use Sylius\Bundle\FlowBundle\Process\Process;
use Sylius\Bundle\FlowBundle\Process\Step\Step;
/**
* Process test.
*
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
*/
class ProcessTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function shouldKeepStepsInOrderWhileAddingSteps()
{
$process = new Process();
$process->addStep('foo', new TestStep());
$process->addStep('bar', new TestStep());
$process->addStep('foobar', new TestStep());
$correctOrder = array('foo', 'bar', 'foobar');
foreach ($process->getOrderedSteps() as $i => $step) {
$this->assertSame($correctOrder[$i], $step->getName());
}
foreach ($correctOrder as $i => $name) {
$this->assertSame($name, $process->getStepByIndex($i)->getName());
}
}
}
class TestStep extends Step
{
public function displayAction(ProcessContextInterface $context)
{
// pufff.
}
}

View file

@ -9,7 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
if (!file_exists($file = __DIR__.'/../vendor/.composer/autoload.php')) { if (!file_exists($file = __DIR__.'/../vendor/autoload.php')) {
die("Please install dependencies using Composer to run the test suite. \n"); die("Please install dependencies using Composer to run the test suite. \n");
} else { } else {
require_once $file; require_once $file;