Skip to content

Commit 749b13e

Browse files
committed
minor #1810 [TwigComponent]: Fix silently failing tests (alucas-campings)
This PR was merged into the 2.x branch. Discussion ---------- [TwigComponent]: Fix silently failing tests | Q | A | ------------- | --- | Bug fix? no | New feature? no | Issues | Fix silently failing tests | License | MIT This tries to fix two little mistakes : - the `expectException` should never be used twice in a test (because it does not actually try/catch, the first exception will stop the execution of the test and will be catched outside). - the piece of code that is expected to throw an exception should always come last in the test (because again, no try/catch, so any line after the throwing line will not be executed). Commits ------- d397e1e [TwigComponent]: Fix silently failing tests
2 parents 324e976 + d397e1e commit 749b13e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/TwigComponent/tests/Integration/ComponentFactoryTest.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,28 +139,34 @@ public function testLegacyAnonymous(): void
139139
{
140140
self::bootKernel(['environment' => 'legacy_anonymous']);
141141

142-
$this->expectException(\InvalidArgumentException::class);
143-
$this->factory()->metadataFor('anonymous:AButton');
142+
// Named templates should be found
143+
$metadata = $this->factory()->metadataFor('foo:bar:baz');
144+
$this->assertSame('components/foo/bar/baz.html.twig', $metadata->getTemplate());
144145

146+
// Prefixed nonymous templates should be found
147+
$metadata = $this->factory()->metadataFor('anonymous:AButton');
148+
$this->assertSame('anonymous/AButton.html.twig', $metadata->getTemplate());
149+
150+
// Unprefixed anonymous templates should not be found
145151
$this->expectException(\InvalidArgumentException::class);
146152
$this->factory()->metadataFor('AButton');
147-
148-
$metadata = $this->factory()->metadataFor('foo:bar:baz');
149-
$this->assertSame('components/components/foo:bar:baz.html.twig', $metadata->getTemplate());
150153
}
151154

152155
public function testAnonymous(): void
153156
{
154157
self::bootKernel(['environment' => 'anonymous_directory']);
155158

156-
$this->expectException(\InvalidArgumentException::class);
157-
$this->factory()->metadataFor('anonymous:AButton');
159+
// Named templates should be found
160+
$metadata = $this->factory()->metadataFor('foo:bar:baz');
161+
$this->assertSame('components/foo/bar/baz.html.twig', $metadata->getTemplate());
158162

163+
// Unprefix anonymous templates should be found
159164
$metadata = $this->factory()->metadataFor('AButton');
160-
$this->assertSame('components/anonymous/AButton.html.twig', $metadata->getTemplate());
165+
$this->assertSame('anonymous/AButton.html.twig', $metadata->getTemplate());
161166

167+
// Prefixed anonymous templates should not be found
162168
$this->expectException(\InvalidArgumentException::class);
163-
$this->factory()->metadataFor('foo:bar:baz');
169+
$this->factory()->metadataFor('anonymous:AButton');
164170
}
165171

166172
public function testAutoNamingInSubDirectory(): void

0 commit comments

Comments
 (0)