Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 86dc85b

Browse files
committed
-
1 parent 571d467 commit 86dc85b

File tree

8 files changed

+78
-44
lines changed

8 files changed

+78
-44
lines changed

src/Symfony/Component/DependencyInjection/Tests/Compiler/AbstractRecursivePassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ protected function processValue($value, $isRoot = false): mixed
107107

108108
public function testGetConstructorDefinitionNoClass()
109109
{
110-
$this->expectException(RuntimeException::class);
111-
$this->expectExceptionMessage('Invalid service "foo": the class is not set.');
112-
113110
$container = new ContainerBuilder();
114111
$container->register('foo');
115112

113+
$this->expectException(RuntimeException::class);
114+
$this->expectExceptionMessage('Invalid service "foo": the class is not set.');
115+
116116
(new class() extends AbstractRecursivePass {
117117
protected function processValue($value, $isRoot = false): mixed
118118
{

src/Symfony/Component/DependencyInjection/Tests/Compiler/AliasDeprecatedPublicServicesPassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ public function testProcess()
4747
*/
4848
public function testProcessWithMissingAttribute(string $attribute, array $attributes)
4949
{
50-
$this->expectException(InvalidArgumentException::class);
51-
$this->expectExceptionMessage(sprintf('The "%s" attribute is mandatory for the "container.private" tag on the "foo" service.', $attribute));
52-
5350
$container = new ContainerBuilder();
5451
$container
5552
->register('foo')
5653
->addTag('container.private', $attributes);
5754

55+
$this->expectException(InvalidArgumentException::class);
56+
$this->expectExceptionMessage(sprintf('The "%s" attribute is mandatory for the "container.private" tag on the "foo" service.', $attribute));
57+
5858
(new AliasDeprecatedPublicServicesPass())->process($container);
5959
}
6060

src/Symfony/Component/DependencyInjection/Tests/Compiler/AutoAliasServicePassTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,30 @@ class AutoAliasServicePassTest extends TestCase
2121
{
2222
public function testProcessWithMissingParameter()
2323
{
24-
$this->expectException(ParameterNotFoundException::class);
2524
$container = new ContainerBuilder();
2625

2726
$container->register('example')
2827
->addTag('auto_alias', ['format' => '%non_existing%.example']);
2928

3029
$pass = new AutoAliasServicePass();
30+
31+
$this->expectException(ParameterNotFoundException::class);
32+
3133
$pass->process($container);
3234
}
3335

3436
public function testProcessWithMissingFormat()
3537
{
36-
$this->expectException(InvalidArgumentException::class);
3738
$container = new ContainerBuilder();
3839

3940
$container->register('example')
4041
->addTag('auto_alias', []);
4142
$container->setParameter('existing', 'mysql');
4243

4344
$pass = new AutoAliasServicePass();
45+
46+
$this->expectException(InvalidArgumentException::class);
47+
4448
$pass->process($container);
4549
}
4650

src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,13 +609,14 @@ public function testScalarArgsCannotBeAutowired()
609609

610610
public function testUnionScalarArgsCannotBeAutowired()
611611
{
612-
$this->expectException(AutowiringFailedException::class);
613-
$this->expectExceptionMessage('Cannot autowire service "union_scalars": argument "$timeout" of method "Symfony\Component\DependencyInjection\Tests\Compiler\UnionScalars::__construct()" is type-hinted "float|int", you should configure its value explicitly.');
614612
$container = new ContainerBuilder();
615613

616614
$container->register('union_scalars', UnionScalars::class)
617615
->setAutowired(true);
618616

617+
$this->expectException(AutowiringFailedException::class);
618+
$this->expectExceptionMessage('Cannot autowire service "union_scalars": argument "$timeout" of method "Symfony\Component\DependencyInjection\Tests\Compiler\UnionScalars::__construct()" is type-hinted "float|int", you should configure its value explicitly.');
619+
619620
(new AutowirePass())->process($container);
620621
}
621622

src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,21 +264,25 @@ public function testGetCircularReference()
264264

265265
public function testGetSyntheticServiceThrows()
266266
{
267-
$this->expectException(ServiceNotFoundException::class);
268-
$this->expectExceptionMessage('The "request" service is synthetic, it needs to be set at boot time before it can be used.');
269267
require_once __DIR__.'/Fixtures/php/services9_compiled.php';
270268

271269
$container = new \ProjectServiceContainer();
270+
271+
$this->expectException(ServiceNotFoundException::class);
272+
$this->expectExceptionMessage('The "request" service is synthetic, it needs to be set at boot time before it can be used.');
273+
272274
$container->get('request');
273275
}
274276

275277
public function testGetRemovedServiceThrows()
276278
{
277-
$this->expectException(ServiceNotFoundException::class);
278-
$this->expectExceptionMessage('The "inlined" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.');
279279
require_once __DIR__.'/Fixtures/php/services9_compiled.php';
280280

281281
$container = new \ProjectServiceContainer();
282+
283+
$this->expectException(ServiceNotFoundException::class);
284+
$this->expectExceptionMessage('The "inlined" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.');
285+
282286
$container->get('inlined');
283287
}
284288

@@ -400,10 +404,12 @@ public function testCheckExistenceOfAnInternalPrivateService()
400404

401405
public function testRequestAnInternalSharedPrivateService()
402406
{
403-
$this->expectException(ServiceNotFoundException::class);
404-
$this->expectExceptionMessage('You have requested a non-existent service "internal".');
405407
$c = new ProjectServiceContainer();
406408
$c->get('internal_dependency');
409+
410+
$this->expectException(ServiceNotFoundException::class);
411+
$this->expectExceptionMessage('You have requested a non-existent service "internal".');
412+
407413
$c->get('internal');
408414
}
409415

src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ public function testMethodCalls()
118118

119119
public function testExceptionOnEmptyMethodCall()
120120
{
121+
$def = new Definition('stdClass');
122+
121123
$this->expectException(InvalidArgumentException::class);
122124
$this->expectExceptionMessage('Method name cannot be empty.');
123-
$def = new Definition('stdClass');
125+
124126
$def->addMethodCall('');
125127
}
126128

@@ -189,12 +191,14 @@ public function testSetIsDeprecated()
189191
*/
190192
public function testSetDeprecatedWithInvalidDeprecationTemplate($message)
191193
{
192-
$this->expectException(InvalidArgumentException::class);
193194
$def = new Definition('stdClass');
195+
196+
$this->expectException(InvalidArgumentException::class);
197+
194198
$def->setDeprecated('vendor/package', '1.1', $message);
195199
}
196200

197-
public static function invalidDeprecationMessageProvider()
201+
public static function invalidDeprecationMessageProvider(): array
198202
{
199203
return [
200204
"With \rs" => ["invalid \r message %service_id%"],
@@ -274,28 +278,32 @@ public function testSetArgument()
274278

275279
public function testGetArgumentShouldCheckBounds()
276280
{
277-
$this->expectException(\OutOfBoundsException::class);
278281
$def = new Definition('stdClass');
279-
280282
$def->addArgument('foo');
283+
284+
$this->expectException(\OutOfBoundsException::class);
285+
281286
$def->getArgument(1);
282287
}
283288

284289
public function testReplaceArgumentShouldCheckBounds()
285290
{
291+
$def = new Definition('stdClass');
292+
$def->addArgument('foo');
293+
286294
$this->expectException(\OutOfBoundsException::class);
287295
$this->expectExceptionMessage('The index "1" is not in the range [0, 0] of the arguments of class "stdClass".');
288-
$def = new Definition('stdClass');
289296

290-
$def->addArgument('foo');
291297
$def->replaceArgument(1, 'bar');
292298
}
293299

294300
public function testReplaceArgumentWithoutExistingArgumentsShouldCheckBounds()
295301
{
302+
$def = new Definition('stdClass');
303+
296304
$this->expectException(\OutOfBoundsException::class);
297305
$this->expectExceptionMessage('Cannot replace arguments for class "stdClass" if none have been configured yet.');
298-
$def = new Definition('stdClass');
306+
299307
$def->replaceArgument(0, 'bar');
300308
}
301309

src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@ public static function validInts()
196196
*/
197197
public function testGetEnvIntInvalid($value)
198198
{
199+
$processor = new EnvVarProcessor(new Container());
200+
199201
$this->expectException(RuntimeException::class);
200202
$this->expectExceptionMessage('Non-numeric env var');
201-
$processor = new EnvVarProcessor(new Container());
202203

203204
$processor->getEnv('int', 'foo', function ($name) use ($value) {
204205
$this->assertSame('foo', $name);
@@ -246,9 +247,10 @@ public static function validFloats()
246247
*/
247248
public function testGetEnvFloatInvalid($value)
248249
{
250+
$processor = new EnvVarProcessor(new Container());
251+
249252
$this->expectException(RuntimeException::class);
250253
$this->expectExceptionMessage('Non-numeric env var');
251-
$processor = new EnvVarProcessor(new Container());
252254

253255
$processor->getEnv('float', 'foo', function ($name) use ($value) {
254256
$this->assertSame('foo', $name);
@@ -295,9 +297,10 @@ public static function validConsts()
295297
*/
296298
public function testGetEnvConstInvalid($value)
297299
{
300+
$processor = new EnvVarProcessor(new Container());
301+
298302
$this->expectException(RuntimeException::class);
299303
$this->expectExceptionMessage('undefined constant');
300-
$processor = new EnvVarProcessor(new Container());
301304

302305
$processor->getEnv('const', 'foo', function ($name) use ($value) {
303306
$this->assertSame('foo', $name);
@@ -373,9 +376,10 @@ public static function validJson()
373376

374377
public function testGetEnvInvalidJson()
375378
{
379+
$processor = new EnvVarProcessor(new Container());
380+
376381
$this->expectException(RuntimeException::class);
377382
$this->expectExceptionMessage('Syntax error');
378-
$processor = new EnvVarProcessor(new Container());
379383

380384
$processor->getEnv('json', 'foo', function ($name) {
381385
$this->assertSame('foo', $name);
@@ -389,9 +393,10 @@ public function testGetEnvInvalidJson()
389393
*/
390394
public function testGetEnvJsonOther($value)
391395
{
396+
$processor = new EnvVarProcessor(new Container());
397+
392398
$this->expectException(RuntimeException::class);
393399
$this->expectExceptionMessage('Invalid JSON env var');
394-
$processor = new EnvVarProcessor(new Container());
395400

396401
$processor->getEnv('json', 'foo', function ($name) use ($value) {
397402
$this->assertSame('foo', $name);
@@ -413,9 +418,10 @@ public static function otherJsonValues()
413418

414419
public function testGetEnvUnknown()
415420
{
421+
$processor = new EnvVarProcessor(new Container());
422+
416423
$this->expectException(RuntimeException::class);
417424
$this->expectExceptionMessage('Unsupported env var prefix');
418-
$processor = new EnvVarProcessor(new Container());
419425

420426
$processor->getEnv('unknown', 'foo', function ($name) {
421427
$this->assertSame('foo', $name);
@@ -426,9 +432,10 @@ public function testGetEnvUnknown()
426432

427433
public function testGetEnvKeyInvalidKey()
428434
{
435+
$processor = new EnvVarProcessor(new Container());
436+
429437
$this->expectException(RuntimeException::class);
430438
$this->expectExceptionMessage('Invalid env "key:foo": a key specifier should be provided.');
431-
$processor = new EnvVarProcessor(new Container());
432439

433440
$processor->getEnv('key', 'foo', function ($name) {
434441
$this->fail('Should not get here');
@@ -440,9 +447,10 @@ public function testGetEnvKeyInvalidKey()
440447
*/
441448
public function testGetEnvKeyNoArrayResult($value)
442449
{
450+
$processor = new EnvVarProcessor(new Container());
451+
443452
$this->expectException(RuntimeException::class);
444453
$this->expectExceptionMessage('Resolved value of "foo" did not result in an array value.');
445-
$processor = new EnvVarProcessor(new Container());
446454

447455
$processor->getEnv('key', 'index:foo', function ($name) use ($value) {
448456
$this->assertSame('foo', $name);
@@ -466,9 +474,10 @@ public static function noArrayValues()
466474
*/
467475
public function testGetEnvKeyArrayKeyNotFound($value)
468476
{
477+
$processor = new EnvVarProcessor(new Container());
478+
469479
$this->expectException(EnvNotFoundException::class);
470480
$this->expectExceptionMessage('Key "index" not found in');
471-
$processor = new EnvVarProcessor(new Container());
472481

473482
$processor->getEnv('key', 'index:foo', function ($name) use ($value) {
474483
$this->assertSame('foo', $name);
@@ -621,9 +630,10 @@ public static function validNullables()
621630

622631
public function testRequireMissingFile()
623632
{
633+
$processor = new EnvVarProcessor(new Container());
634+
624635
$this->expectException(EnvNotFoundException::class);
625636
$this->expectExceptionMessage('missing-file');
626-
$processor = new EnvVarProcessor(new Container());
627637

628638
$processor->getEnv('require', '/missing-file', fn ($name) => $name);
629639
}
@@ -684,15 +694,15 @@ public function testGetEnvResolveNoMatch()
684694
*/
685695
public function testGetEnvResolveNotScalar($value)
686696
{
687-
$this->expectException(RuntimeException::class);
688-
$this->expectExceptionMessage('Parameter "bar" found when resolving env var "foo" must be scalar');
689-
690697
$container = new ContainerBuilder();
691698
$container->setParameter('bar', $value);
692699
$container->compile();
693700

694701
$processor = new EnvVarProcessor($container);
695702

703+
$this->expectException(RuntimeException::class);
704+
$this->expectExceptionMessage('Parameter "bar" found when resolving env var "foo" must be scalar');
705+
696706
$processor->getEnv('resolve', 'foo', fn () => '%bar%');
697707
}
698708

@@ -877,9 +887,10 @@ public function loadEnvVars(): array
877887

878888
public function testGetEnvInvalidPrefixWithDefault()
879889
{
890+
$processor = new EnvVarProcessor(new Container());
891+
880892
$this->expectException(RuntimeException::class);
881893
$this->expectExceptionMessage('Unsupported env var prefix');
882-
$processor = new EnvVarProcessor(new Container());
883894

884895
$processor->getEnv('unknown', 'default::FAKE', function ($name) {
885896
$this->assertSame('default::FAKE', $name);

src/Symfony/Component/DependencyInjection/Tests/ServiceLocatorTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ public function getServiceLocator(array $factories): ContainerInterface
3434

3535
public function testGetThrowsOnUndefinedService()
3636
{
37-
$this->expectException(NotFoundExceptionInterface::class);
38-
$this->expectExceptionMessage('Service "dummy" not found: the container inside "Symfony\Component\DependencyInjection\Tests\ServiceLocatorTest" is a smaller service locator that only knows about the "foo" and "bar" services.');
3937
$locator = $this->getServiceLocator([
4038
'foo' => fn () => 'bar',
4139
'bar' => fn () => 'baz',
4240
]);
4341

42+
$this->expectException(NotFoundExceptionInterface::class);
43+
$this->expectExceptionMessage('Service "dummy" not found: the container inside "Symfony\Component\DependencyInjection\Tests\ServiceLocatorTest" is a smaller service locator that only knows about the "foo" and "bar" services.');
44+
4445
$locator->get('dummy');
4546
}
4647

@@ -53,26 +54,29 @@ public function testThrowsOnCircularReference()
5354

5455
public function testThrowsInServiceSubscriber()
5556
{
56-
$this->expectException(NotFoundExceptionInterface::class);
57-
$this->expectExceptionMessage('Service "foo" not found: even though it exists in the app\'s container, the container inside "caller" is a smaller service locator that only knows about the "bar" service. Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "SomeServiceSubscriber::getSubscribedServices()".');
5857
$container = new Container();
5958
$container->set('foo', new \stdClass());
6059
$subscriber = new SomeServiceSubscriber();
6160
$subscriber->container = $this->getServiceLocator(['bar' => function () {}]);
6261
$subscriber->container = $subscriber->container->withContext('caller', $container);
6362

63+
$this->expectException(NotFoundExceptionInterface::class);
64+
$this->expectExceptionMessage('Service "foo" not found: even though it exists in the app\'s container, the container inside "caller" is a smaller service locator that only knows about the "bar" service. Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "SomeServiceSubscriber::getSubscribedServices()".');
65+
6466
$subscriber->getFoo();
6567
}
6668

6769
public function testGetThrowsServiceNotFoundException()
6870
{
69-
$this->expectException(ServiceNotFoundException::class);
70-
$this->expectExceptionMessage('Service "foo" not found: even though it exists in the app\'s container, the container inside "foo" is a smaller service locator that is empty... Try using dependency injection instead.');
7171
$container = new Container();
7272
$container->set('foo', new \stdClass());
7373

7474
$locator = new ServiceLocator([]);
7575
$locator = $locator->withContext('foo', $container);
76+
77+
$this->expectException(ServiceNotFoundException::class);
78+
$this->expectExceptionMessage('Service "foo" not found: even though it exists in the app\'s container, the container inside "foo" is a smaller service locator that is empty... Try using dependency injection instead.');
79+
7680
$locator->get('foo');
7781
}
7882

0 commit comments

Comments
 (0)