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

Skip to content

Commit 581eec2

Browse files
committed
-
1 parent 38ca525 commit 581eec2

5 files changed

+94
-74
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,29 @@ class CheckCircularReferencesPassTest extends TestCase
2424
{
2525
public function testProcess()
2626
{
27-
$this->expectException(ServiceCircularReferenceException::class);
2827
$container = new ContainerBuilder();
2928
$container->register('a')->addArgument(new Reference('b'));
3029
$container->register('b')->addArgument(new Reference('a'));
3130

31+
$this->expectException(ServiceCircularReferenceException::class);
32+
3233
$this->process($container);
3334
}
3435

3536
public function testProcessWithAliases()
3637
{
37-
$this->expectException(ServiceCircularReferenceException::class);
3838
$container = new ContainerBuilder();
3939
$container->register('a')->addArgument(new Reference('b'));
4040
$container->setAlias('b', 'c');
4141
$container->setAlias('c', 'a');
4242

43+
$this->expectException(ServiceCircularReferenceException::class);
44+
4345
$this->process($container);
4446
}
4547

4648
public function testProcessWithFactory()
4749
{
48-
$this->expectException(ServiceCircularReferenceException::class);
4950
$container = new ContainerBuilder();
5051

5152
$container
@@ -56,23 +57,25 @@ public function testProcessWithFactory()
5657
->register('b', 'stdClass')
5758
->setFactory([new Reference('a'), 'getInstance']);
5859

60+
$this->expectException(ServiceCircularReferenceException::class);
61+
5962
$this->process($container);
6063
}
6164

6265
public function testProcessDetectsIndirectCircularReference()
6366
{
64-
$this->expectException(ServiceCircularReferenceException::class);
6567
$container = new ContainerBuilder();
6668
$container->register('a')->addArgument(new Reference('b'));
6769
$container->register('b')->addArgument(new Reference('c'));
6870
$container->register('c')->addArgument(new Reference('a'));
6971

72+
$this->expectException(ServiceCircularReferenceException::class);
73+
7074
$this->process($container);
7175
}
7276

7377
public function testProcessDetectsIndirectCircularReferenceWithFactory()
7478
{
75-
$this->expectException(ServiceCircularReferenceException::class);
7679
$container = new ContainerBuilder();
7780

7881
$container->register('a')->addArgument(new Reference('b'));
@@ -83,17 +86,20 @@ public function testProcessDetectsIndirectCircularReferenceWithFactory()
8386

8487
$container->register('c')->addArgument(new Reference('a'));
8588

89+
$this->expectException(ServiceCircularReferenceException::class);
90+
8691
$this->process($container);
8792
}
8893

8994
public function testDeepCircularReference()
9095
{
91-
$this->expectException(ServiceCircularReferenceException::class);
9296
$container = new ContainerBuilder();
9397
$container->register('a')->addArgument(new Reference('b'));
9498
$container->register('b')->addArgument(new Reference('c'));
9599
$container->register('c')->addArgument(new Reference('b'));
96100

101+
$this->expectException(ServiceCircularReferenceException::class);
102+
97103
$this->process($container);
98104
}
99105

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ class CheckDefinitionValidityPassTest extends TestCase
2121
{
2222
public function testProcessDetectsSyntheticNonPublicDefinitions()
2323
{
24-
$this->expectException(RuntimeException::class);
2524
$container = new ContainerBuilder();
2625
$container->register('a')->setSynthetic(true)->setPublic(false);
2726

27+
$this->expectException(RuntimeException::class);
28+
2829
$this->process($container);
2930
}
3031

3132
public function testProcessDetectsNonSyntheticNonAbstractDefinitionWithoutClass()
3233
{
33-
$this->expectException(RuntimeException::class);
3434
$container = new ContainerBuilder();
3535
$container->register('a')->setSynthetic(false)->setAbstract(false);
3636

37+
$this->expectException(RuntimeException::class);
38+
3739
$this->process($container);
3840
}
3941

@@ -92,10 +94,12 @@ public function testValidTags()
9294
*/
9395
public function testInvalidTags(string $name, array $attributes, string $message)
9496
{
95-
$this->expectException(RuntimeException::class);
9697
$this->expectExceptionMessage($message);
9798
$container = new ContainerBuilder();
9899
$container->register('a', 'class')->addTag($name, $attributes);
100+
101+
$this->expectException(RuntimeException::class);
102+
99103
$this->process($container);
100104
}
101105

@@ -121,21 +125,23 @@ public static function provideInvalidTags(): iterable
121125

122126
public function testDynamicPublicServiceName()
123127
{
124-
$this->expectException(EnvParameterException::class);
125128
$container = new ContainerBuilder();
126129
$env = $container->getParameterBag()->get('env(BAR)');
127130
$container->register("foo.$env", 'class')->setPublic(true);
128131

132+
$this->expectException(EnvParameterException::class);
133+
129134
$this->process($container);
130135
}
131136

132137
public function testDynamicPublicAliasName()
133138
{
134-
$this->expectException(EnvParameterException::class);
135139
$container = new ContainerBuilder();
136140
$env = $container->getParameterBag()->get('env(BAR)');
137141
$container->setAlias("foo.$env", 'class')->setPublic(true);
138142

143+
$this->expectException(EnvParameterException::class);
144+
139145
$this->process($container);
140146
}
141147

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ public function testProcess()
4141

4242
public function testProcessThrowsExceptionOnInvalidReference()
4343
{
44-
$this->expectException(ServiceNotFoundException::class);
4544
$container = new ContainerBuilder();
4645

4746
$container
4847
->register('a', '\stdClass')
4948
->addArgument(new Reference('b'))
5049
;
5150

51+
$this->expectException(ServiceNotFoundException::class);
52+
5253
$this->process($container);
5354
}
5455

5556
public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinition()
5657
{
57-
$this->expectException(ServiceNotFoundException::class);
5858
$container = new ContainerBuilder();
5959

6060
$def = new Definition();
@@ -65,6 +65,8 @@ public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinitio
6565
->addArgument($def)
6666
;
6767

68+
$this->expectException(ServiceNotFoundException::class);
69+
6870
$this->process($container);
6971
}
7072

@@ -84,34 +86,36 @@ public function testProcessDefinitionWithBindings()
8486

8587
public function testWithErroredServiceLocator()
8688
{
87-
$this->expectException(ServiceNotFoundException::class);
88-
$this->expectExceptionMessage('The service "foo" in the container provided to "bar" has a dependency on a non-existent service "baz".');
8989
$container = new ContainerBuilder();
9090

9191
ServiceLocatorTagPass::register($container, ['foo' => new Reference('baz')], 'bar');
9292

9393
(new AnalyzeServiceReferencesPass())->process($container);
9494
(new InlineServiceDefinitionsPass())->process($container);
95+
96+
$this->expectException(ServiceNotFoundException::class);
97+
$this->expectExceptionMessage('The service "foo" in the container provided to "bar" has a dependency on a non-existent service "baz".');
98+
9599
$this->process($container);
96100
}
97101

98102
public function testWithErroredHiddenService()
99103
{
100-
$this->expectException(ServiceNotFoundException::class);
101-
$this->expectExceptionMessage('The service "bar" has a dependency on a non-existent service "foo".');
102104
$container = new ContainerBuilder();
103105

104106
ServiceLocatorTagPass::register($container, ['foo' => new Reference('foo')], 'bar');
105107

106108
(new AnalyzeServiceReferencesPass())->process($container);
107109
(new InlineServiceDefinitionsPass())->process($container);
110+
111+
$this->expectException(ServiceNotFoundException::class);
112+
$this->expectExceptionMessage('The service "bar" has a dependency on a non-existent service "foo".');
113+
108114
$this->process($container);
109115
}
110116

111117
public function testProcessThrowsExceptionOnInvalidReferenceWithAlternatives()
112118
{
113-
$this->expectException(ServiceNotFoundException::class);
114-
$this->expectExceptionMessage('The service "a" has a dependency on a non-existent service "@ccc". Did you mean this: "ccc"?');
115119
$container = new ContainerBuilder();
116120

117121
$container
@@ -121,19 +125,22 @@ public function testProcessThrowsExceptionOnInvalidReferenceWithAlternatives()
121125
$container
122126
->register('ccc', '\stdClass');
123127

128+
$this->expectException(ServiceNotFoundException::class);
129+
$this->expectExceptionMessage('The service "a" has a dependency on a non-existent service "@ccc". Did you mean this: "ccc"?');
130+
124131
$this->process($container);
125132
}
126133

127134
public function testCurrentIdIsExcludedFromAlternatives()
128135
{
129-
$this->expectException(ServiceNotFoundException::class);
130-
$this->expectExceptionMessage('The service "app.my_service" has a dependency on a non-existent service "app.my_service2".');
131-
132136
$container = new ContainerBuilder();
133137
$container
134138
->register('app.my_service', \stdClass::class)
135139
->addArgument(new Reference('app.my_service2'));
136140

141+
$this->expectException(ServiceNotFoundException::class);
142+
$this->expectExceptionMessage('The service "app.my_service" has a dependency on a non-existent service "app.my_service2".');
143+
137144
$this->process($container);
138145
}
139146

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ class CheckReferenceValidityPassTest extends TestCase
2020
{
2121
public function testProcessDetectsReferenceToAbstractDefinition()
2222
{
23-
$this->expectException(\RuntimeException::class);
2423
$container = new ContainerBuilder();
2524

2625
$container->register('a')->setAbstract(true);
2726
$container->register('b')->addArgument(new Reference('a'));
2827

28+
$this->expectException(\RuntimeException::class);
29+
2930
$this->process($container);
3031
}
3132

0 commit comments

Comments
 (0)