Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Oct 2, 2018
1 parent 9d2446c commit 5050698
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 16 deletions.
1 change: 0 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ final class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('setono_cron_expression');

return $treeBuilder;
}
Expand Down
4 changes: 0 additions & 4 deletions DependencyInjection/SetonoCronExpressionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
namespace Setono\CronExpressionBundle\DependencyInjection;

use Setono\CronExpressionBundle\Doctrine\DBAL\Types\CronExpressionType;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

final class SetonoCronExpressionExtension extends Extension implements PrependExtensionInterface
{
Expand All @@ -18,8 +16,6 @@ final class SetonoCronExpressionExtension extends Extension implements PrependEx
*/
public function load(array $config, ContainerBuilder $container): void
{
$config = $this->processConfiguration($this->getConfiguration([], $container), $config);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Form/DataTransformer/CronExpressionToPartsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private function convertCronParts(array $cronArray): string
{
$cronString = join(',', $cronArray);

return $cronString ?: '*';
return '' !== $cronString ? $cronString : '*';
}

private function convertCronString(string $cronString): array
Expand Down
4 changes: 4 additions & 0 deletions Tests/Doctrine/DBAL/Types/CronExpressionTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Setono\CronExpressionBundle\Tests\Doctrine\DBAL\Types;

use Cron\CronExpression;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -23,6 +24,9 @@ final class CronExpressionTypeTest extends TestCase
*/
private $platform;

/**
* @throws DBALException
*/
protected function setUp()
{
if (!Type::hasType('cron_expression')) {
Expand Down
53 changes: 44 additions & 9 deletions Tests/Form/Type/CronExpressionTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,51 @@ class CronExpressionTypeTest extends TypeTestCase
/**
* @test
*/
public function submit(): void
public function submitWithAllSet(): void
{
$formData = array(
'minutes' => '0',
'hours' => '12',
'days' => '1',
'months' => '6',
'weekdays' => '3',
);
$this->_submit([
'minutes' => ['0'],
'hours' => ['12'],
'days' => ['1'],
'months' => ['6'],
'weekdays' => ['3'],
], '0 12 1 6 3');
}

/**
* @test
*/
public function submitMultipleMinutes(): void
{
$this->_submit([
'minutes' => ['0', '13'],
'hours' => ['12'],
'days' => ['1'],
'months' => ['6'],
'weekdays' => ['3'],
], '0,13 12 1 6 3');
}

/**
* @test
*/
public function submitMinutesOnly(): void
{
$this->_submit([
'minutes' => ['0'],
], '0 * * * *');
}

/**
* @test
*/
public function submitEmpty(): void
{
$this->_submit([], '* * * * *');
}

private function _submit(array $formData, string $expected): void
{
$form = $this->factory->create(CronExpressionType::class);

// submit the data to the form directly
Expand All @@ -41,6 +76,6 @@ public function submit(): void
$cronExpression = $form->getData();

$this->assertInstanceOf(CronExpression::class, $cronExpression);
$this->assertSame('0 12 1 6 3', $cronExpression->getExpression());
$this->assertSame($expected, $cronExpression->getExpression());
}
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
stopOnFailure="false">
<testsuites>
<testsuite name="SetonoCronExpressionBundle Test Suite">
<directory>tests</directory>
<directory>Tests</directory>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit 5050698

Please sign in to comment.