Skip to content

[Config] Throw an exception when using cannotBeEmpty() with numeric or boolean nodes #16816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Config\Definition\Builder;

use Symfony\Component\Config\Definition\BooleanNode;
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;

/**
* This class provides a fluent interface for defining a node.
Expand Down Expand Up @@ -39,4 +40,14 @@ protected function instantiateNode()
{
return new BooleanNode($this->name, $this->parent);
}

/**
* {@inheritdoc}
*
* @throws InvalidDefinitionException
*/
public function cannotBeEmpty()
{
throw new InvalidDefinitionException('->cannotBeEmpty() is not applicable to BooleanNodeDefinition.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Config\Definition\Builder;

use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;

/**
* Abstract class that contains common code of integer and float node definitions.
*
Expand Down Expand Up @@ -58,4 +60,14 @@ public function min($min)

return $this;
}

/**
* {@inheritdoc}
*
* @throws InvalidDefinitionException
*/
public function cannotBeEmpty()
{
throw new InvalidDefinitionException('->cannotBeEmpty() is not applicable to NumericNodeDefinition.');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Config\Tests\Definition\Builder;

use Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition;

class BooleanNodeDefinitionTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
* @expectedExceptionMessage ->cannotBeEmpty() is not applicable to BooleanNodeDefinition.
*/
public function testCannotBeEmptyThrowsAnException()
{
$def = new BooleanNodeDefinition('foo');
$def->cannotBeEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,14 @@ public function testFloatValidMinMaxAssertion()
$node = $def->min(3.0)->max(7e2)->getNode();
$this->assertEquals(4.5, $node->finalize(4.5));
}

/**
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
* @expectedExceptionMessage ->cannotBeEmpty() is not applicable to NumericNodeDefinition.
*/
public function testCannotBeEmptyThrowsAnException()
{
$def = new NumericNodeDefinition('foo');
$def->cannotBeEmpty();
}
}