Skip to content

Commit ade1f13

Browse files
committed
feature #417 [make:functional-test] Use Panther when available. (adrienlucas)
This PR was merged into the 1.0-dev branch. Discussion ---------- [make:functional-test] Use Panther when available. Hope this will be useful for others. Let me know if there are some mistakes to fix ! Commits ------- 3333d6e Generated functional test use Panther when available
2 parents e4031ef + 3333d6e commit ade1f13

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/Maker/MakeFunctionalTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Console\Input\InputInterface;
2222
use Symfony\Component\CssSelector\CssSelectorConverter;
2323
use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait;
24+
use Symfony\Component\Panther\PantherTestCaseTrait;
2425

2526
/**
2627
* @author Javier Eguiluz <[email protected]>
@@ -55,6 +56,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
5556
'test/Functional.tpl.php',
5657
[
5758
'web_assertions_are_available' => trait_exists(WebTestAssertionsTrait::class),
59+
'panther_is_available' => trait_exists(PantherTestCaseTrait::class),
5860
]
5961
);
6062

@@ -82,5 +84,11 @@ public function configureDependencies(DependencyBuilder $dependencies)
8284
true,
8385
true
8486
);
87+
$dependencies->addClassDependency(
88+
PantherTestCaseTrait::class,
89+
'panther',
90+
false,
91+
true
92+
);
8593
}
8694
}

src/Resources/skeleton/test/Functional.tpl.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22

33
namespace <?= $namespace; ?>;
44

5+
<?php if($panther_is_available): ?>
6+
use Symfony\Component\Panther\PantherTestCase;
7+
<?php else: ?>
58
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
9+
<?php endif ?>
610

7-
class <?= $class_name ?> extends WebTestCase
11+
class <?= $class_name ?> extends <?= $panther_is_available ? 'PantherTestCase' : 'WebTestCase' ?><?= "\n" ?>
812
{
913
public function testSomething()
1014
{
1115
$client = static::createClient();
1216
$crawler = $client->request('GET', '/');
1317

14-
<?php if($web_assertions_are_available) { ?>
18+
<?php if($web_assertions_are_available): ?>
1519
$this->assertResponseIsSuccessful();
1620
$this->assertSelectorTextContains('h1', 'Hello World');
17-
<?php } else { ?>
21+
<?php else: ?>
1822
$this->assertSame(200, $client->getResponse()->getStatusCode());
1923
$this->assertContains('Hello World', $crawler->filter('h1')->text());
20-
<?php } ?>
24+
<?php endif ?>
2125
}
2226
}

tests/Maker/FunctionalTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,17 @@ public function getCommandTests()
248248
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeFunctional')
249249
];
250250

251+
yield 'functional_with_panther' => [MakerTestDetails::createTest(
252+
$this->getMakerInstance(MakeFunctionalTest::class),
253+
[
254+
// functional test class name
255+
'FooBar',
256+
])
257+
->addExtraDependencies('panther')
258+
->setRequiredPhpVersion(70100)
259+
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeFunctional')
260+
];
261+
251262
yield 'subscriber' => [MakerTestDetails::createTest(
252263
$this->getMakerInstance(MakeSubscriber::class),
253264
[

0 commit comments

Comments
 (0)