Skip to content

Commit 887b4fc

Browse files
committed
rename non-empty parameter methods
1 parent 91e4ba0 commit 887b4fc

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CHANGELOG
77
* Deprecate `!tagged` tag, use `!tagged_iterator` instead
88
* Add a `ContainerBuilder::registerChild()` shortcut method for registering child definitions
99
* Add support for `key-type` in `XmlFileLoader`
10-
* Enable non-empty parameters with `ParameterBag::nonEmpty()` and `ContainerBuilder::nonEmptyParameter()` methods
10+
* Enable non-empty parameters with `ParameterBag::cannotBeEmpty()` and `ContainerBuilder::parameterCannotBeEmpty()` methods
1111

1212
7.1
1313
---

ContainerBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ public function merge(self $container): void
673673
}
674674

675675
foreach ($otherBag->allNonEmpty() as $name => $message) {
676-
$parameterBag->nonEmpty($name, $message);
676+
$parameterBag->cannotBeEmpty($name, $message);
677677
}
678678
}
679679

@@ -768,13 +768,13 @@ public function deprecateParameter(string $name, string $package, string $versio
768768
$this->parameterBag->deprecate($name, $package, $version, $message);
769769
}
770770

771-
public function nonEmptyParameter(string $name, string $message): void
771+
public function parameterCannotBeEmpty(string $name, string $message): void
772772
{
773773
if (!$this->parameterBag instanceof ParameterBag) {
774774
throw new BadMethodCallException(\sprintf('The parameter bag must be an instance of "%s" to call "%s()".', ParameterBag::class, __METHOD__));
775775
}
776776

777-
$this->parameterBag->nonEmpty($name, $message);
777+
$this->parameterBag->cannotBeEmpty($name, $message);
778778
}
779779

780780
/**

ParameterBag/FrozenParameterBag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public function deprecate(string $name, string $package, string $version, string
5555
throw new LogicException('Impossible to call deprecate() on a frozen ParameterBag.');
5656
}
5757

58-
public function nonEmpty(string $name, string $message = 'A non-empty parameter "%s" is required.'): never
58+
public function cannotBeEmpty(string $name, string $message = 'A non-empty parameter "%s" is required.'): never
5959
{
60-
throw new LogicException('Impossible to call nonEmpty() on a frozen ParameterBag.');
60+
throw new LogicException('Impossible to call cannotBeEmpty() on a frozen ParameterBag.');
6161
}
6262

6363
public function remove(string $name): never

ParameterBag/ParameterBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function deprecate(string $name, string $package, string $version, string
133133
$this->deprecatedParameters[$name] = [$package, $version, $message, $name];
134134
}
135135

136-
public function nonEmpty(string $name, string $message): void
136+
public function cannotBeEmpty(string $name, string $message): void
137137
{
138138
$this->nonEmptyParameters[$name] = $message;
139139
}

Tests/Fixtures/containers/container_nonempty_parameters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Symfony\Component\DependencyInjection\Parameter;
55

66
$container = new ContainerBuilder();
7-
$container->nonEmptyParameter('bar', 'Did you forget to configure the "foo.bar" option?');
7+
$container->parameterCannotBeEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
88
$container->register('foo', 'stdClass')
99
->setArguments([new Parameter('bar')])
1010
->setPublic(true)

Tests/ParameterBag/ParameterBagTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
16-
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1716
use Symfony\Component\DependencyInjection\Exception\EmptyParameterValueException;
17+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1818
use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException;
1919
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
2020
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
@@ -201,7 +201,7 @@ public function testGetMissingRequiredParameter()
201201
{
202202
$bag = new ParameterBag();
203203

204-
$bag->nonEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
204+
$bag->cannotBeEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
205205

206206
$this->expectException(ParameterNotFoundException::class);
207207
$this->expectExceptionMessage('You have requested a non-existent parameter "bar". Did you forget to configure the "foo.bar" option?');
@@ -213,7 +213,7 @@ public function testGetNonEmptyParameterThrowsWhenNullValue()
213213
{
214214
$bag = new ParameterBag();
215215
$bag->set('bar', null);
216-
$bag->nonEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
216+
$bag->cannotBeEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
217217

218218
$this->expectException(EmptyParameterValueException::class);
219219
$this->expectExceptionMessage('Did you forget to configure the "foo.bar" option?');
@@ -225,7 +225,19 @@ public function testGetNonEmptyParameterThrowsWhenEmptyStringValue()
225225
{
226226
$bag = new ParameterBag();
227227
$bag->set('bar', '');
228-
$bag->nonEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
228+
$bag->cannotBeEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
229+
230+
$this->expectException(EmptyParameterValueException::class);
231+
$this->expectExceptionMessage('Did you forget to configure the "foo.bar" option?');
232+
233+
$bag->get('bar');
234+
}
235+
236+
public function testGetNonEmptyParameterThrowsWhenEmptyArrayValue()
237+
{
238+
$bag = new ParameterBag();
239+
$bag->set('bar', []);
240+
$bag->cannotBeEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
229241

230242
$this->expectException(EmptyParameterValueException::class);
231243
$this->expectExceptionMessage('Did you forget to configure the "foo.bar" option?');

0 commit comments

Comments
 (0)