Skip to content

Commit 09fc38c

Browse files
committed
bug #499 Fixing tests for Symfony5 (weaverryan)
This PR was merged into the 1.0-dev branch. Discussion ---------- Fixing tests for Symfony5 This also removes the dev-stable. That was a build to detect possible BC breaks on patch versions made in Symfony... which is rare and probably not the job of Maker :). Commits ------- 56df019 Various test fixes & matrix improvements:
2 parents 7102b79 + 56df019 commit 09fc38c

File tree

8 files changed

+62
-29
lines changed

8 files changed

+62
-29
lines changed

.travis.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ env:
1717
matrix:
1818
fast_finish: true
1919
include:
20+
- php: 7.1.33
21+
- php: 7.3
22+
- php: 7.3
23+
env: MAKER_TEST_VERSION=dev
24+
allow_failures:
2025
- php: 7.3
21-
- php: 7.2
22-
env: MAKER_TEST_VERSION=stable-dev
23-
- php: 7.2
2426
env: MAKER_TEST_VERSION=dev
2527

2628
before_install:

src/EventRegistry.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ public function getEventClassName(string $event)
149149
return Event::class;
150150
}
151151

152+
// ignore an "object" type-hint
153+
if ('object' === $type) {
154+
continue;
155+
}
156+
152157
return $type;
153158
}
154159
}

src/Test/MakerTestEnvironment.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ private function postMake()
289289
$yaml = file_get_contents($this->path.'/config/packages/security.yaml');
290290
$manipulator = new YamlSourceManipulator($yaml);
291291
$data = $manipulator->getData();
292+
292293
foreach ($guardAuthenticators as $firewallName => $id) {
293294
if (!isset($data['security']['firewalls'][$firewallName])) {
294295
throw new \Exception(sprintf('Could not find firewall "%s"', $firewallName));
@@ -320,9 +321,9 @@ private function buildFlexSkeleton()
320321

321322
$rootPath = str_replace('\\', '\\\\', realpath(__DIR__.'/../..'));
322323

323-
// allow dev dependencies
324+
// dev deps already will allow dev deps, but we should prefer stable
324325
if (false !== strpos($targetVersion, 'dev')) {
325-
MakerTestProcess::create('composer config minimum-stability dev', $this->flexPath)
326+
MakerTestProcess::create('composer config prefer-stable true', $this->flexPath)
326327
->run();
327328
}
328329

@@ -449,10 +450,7 @@ private function getTargetFlexVersion(): string
449450

450451
break;
451452
case 'dev':
452-
$version = $data['dev'];
453-
$parts = explode('.', $version);
454-
455-
$this->targetFlexVersion = sprintf('%s.%s.x-dev', $parts[0], $parts[1]);
453+
$this->targetFlexVersion = 'dev-master';
456454

457455
break;
458456
default:

src/Util/YamlSourceManipulator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private function updateData(array $newData)
217217
}
218218

219219
// 3b) value DID change
220-
$this->log(sprintf('updating value to {%s}', is_array($newVal) ? '<array>' : $newVal));
220+
$this->log(sprintf('updating value to {%s}', \is_array($newVal) ? '<array>' : $newVal));
221221
$this->changeValueInYaml($newVal);
222222
}
223223

@@ -465,7 +465,7 @@ private function changeValueInYaml($value)
465465
$newPosition = $this->currentPosition + \strlen($newYamlValue);
466466
$isNextContentComment = $this->isPreviousLineComment($newPosition);
467467
if ($isNextContentComment) {
468-
$newPosition++;
468+
++$newPosition;
469469
}
470470

471471
$newContents = substr($this->contents, 0, $this->currentPosition)
@@ -785,7 +785,7 @@ private function findEndPositionOfValue($value, $offset = null)
785785

786786
// a value like "foo:" can simply end a file
787787
// this means the value is null
788-
if ($offset === strlen($this->contents)) {
788+
if ($offset === \strlen($this->contents)) {
789789
return $offset;
790790
}
791791

tests/EventRegistryTest.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,25 @@ public function testGetEventClassNameReturnsType()
2323
{
2424
$eventObj = new DummyEvent();
2525
$dispatcher = $this->createMock(EventDispatcherInterface::class);
26+
27+
$listenersMap = [
28+
'someFunctionToSkip',
29+
[$eventObj, 'methodNoArg'],
30+
[$eventObj, 'methodNoType'],
31+
[$eventObj, 'methodObjectType'],
32+
[$eventObj, 'methodWithType'],
33+
];
34+
35+
// less than PHP 7.2, unset object type-hint example
36+
// otherwise, it looks like a class in this namespace
37+
if (PHP_VERSION_ID < 70200) {
38+
unset($listenersMap[3]);
39+
}
40+
2641
$dispatcher->expects($this->once())
2742
->method('getListeners')
2843
->with('foo.bar')
29-
->willReturn([
30-
'someFunctionToSkip',
31-
[$eventObj, 'methodNoArg'],
32-
[$eventObj, 'methodNoType'],
33-
[$eventObj, 'methodWithType'],
34-
]);
44+
->willReturn($listenersMap);
3545

3646
$registry = new EventRegistry($dispatcher);
3747
$this->assertSame(GetResponseForExceptionEvent::class, $registry->getEventClassName('foo.bar'));
@@ -85,6 +95,10 @@ public function methodNoType($event)
8595
{
8696
}
8797

98+
public function methodObjectType(object $event)
99+
{
100+
}
101+
88102
public function methodWithType(GetResponseForExceptionEvent $event)
89103
{
90104
}

tests/Maker/FunctionalTest.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,9 @@ function (string $output, string $directory) {
665665
->assert(function (string $output, string $directory) {
666666
$this->assertStringContainsString('created: src/Controller/SweetFoodController.php', $output);
667667
$this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output);
668-
}),
668+
})
669+
// workaround for segfault in PHP 7.1 CI :/
670+
->setRequiredPhpVersion(70200)
669671
];
670672

671673
yield 'crud_basic_in_custom_root_namespace' => [MakerTestDetails::createTest(
@@ -681,7 +683,9 @@ function (string $output, string $directory) {
681683
->assert(function (string $output, string $directory) {
682684
$this->assertStringContainsString('created: src/Controller/SweetFoodController.php', $output);
683685
$this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output);
684-
}),
686+
})
687+
// workaround for segfault in PHP 7.1 CI :/
688+
->setRequiredPhpVersion(70200)
685689
];
686690

687691
yield 'crud_repository' => [MakerTestDetails::createTest(
@@ -713,7 +717,9 @@ function (string $output, string $directory) {
713717
->assert(function (string $output, string $directory) {
714718
$this->assertStringContainsString('created: src/Controller/SweetFoodController.php', $output);
715719
$this->assertStringContainsString('created: src/Form/SweetFoodType.php', $output);
716-
}),
720+
})
721+
// workaround for segfault in PHP 7.1 CI :/
722+
->setRequiredPhpVersion(70200)
717723
];
718724

719725
yield 'registration_form_entity_guard_authenticate' => [MakerTestDetails::createTest(
@@ -729,7 +735,12 @@ function (string $output, string $directory) {
729735
])
730736
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeRegistrationFormEntity')
731737
->configureDatabase()
732-
->updateSchemaAfterCommand(),
738+
->updateSchemaAfterCommand()
739+
// workaround for a strange behavior where, every other
740+
// test run, the UniqueEntity would not be seen, because
741+
// the the validation cache was out of date. The cause
742+
// is currently unknown, so this workaround was added
743+
->addPostMakeCommand('php bin/console cache:clear --env=test')
733744
];
734745

735746
// sanity check on all the interactive questions
@@ -757,7 +768,10 @@ function (string $output, string $directory) {
757768
])
758769
->setFixtureFilesPath(__DIR__.'/../fixtures/MakeRegistrationFormEntity')
759770
->configureDatabase()
760-
->updateSchemaAfterCommand(),
771+
->updateSchemaAfterCommand()
772+
// workaround for strange failure - see test case
773+
// registration_form_entity_guard_authenticate for details
774+
->addPostMakeCommand('php bin/console cache:clear --env=test')
761775
];
762776

763777
yield 'auth_login_form_user_entity_with_encoder_logout' => [

tests/fixtures/MakeRegistrationFormEntity/tests/RegistrationFormTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ class RegistrationFormTest extends WebTestCase
1010
{
1111
public function testRegistrationSuccessful()
1212
{
13-
self::bootKernel();
13+
$client = static::createClient();
14+
1415
/** @var EntityManager $em */
1516
$em = self::$kernel->getContainer()
1617
->get('doctrine')
1718
->getManager();
1819
$em->createQuery('DELETE FROM App\\Entity\\User u')
1920
->execute();
2021

21-
$client = static::createClient();
2222
$crawler = $client->request('GET', '/register');
2323
$form = $crawler->selectButton('Register')->form();
2424
$form['registration_form[email]'] = 'ryan@symfonycasts.com';
@@ -34,7 +34,8 @@ public function testRegistrationSuccessful()
3434

3535
public function testRegistrationValidationError()
3636
{
37-
self::bootKernel();
37+
$client = static::createClient();
38+
3839
/** @var EntityManager $em */
3940
$em = self::$kernel->getContainer()
4041
->get('doctrine')
@@ -47,7 +48,6 @@ public function testRegistrationValidationError()
4748
$em->persist($user);
4849
$em->flush();
4950

50-
$client = static::createClient();
5151
$crawler = $client->request('GET', '/register');
5252
$form = $crawler->selectButton('Register')->form();
5353
$form['registration_form[email]'] = 'ryan@symfonycasts.com';

tests/fixtures/MakeUserEntityPassword/tests/GeneratedEntityTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class GeneratedEntityTest extends WebTestCase
1111
{
1212
public function testGeneratedEntity()
1313
{
14-
self::bootKernel();
14+
$client = static::createClient();
15+
1516
/** @var EntityManager $em */
1617
$em = self::$kernel->getContainer()
1718
->get('doctrine')
@@ -31,7 +32,6 @@ public function testGeneratedEntity()
3132
$em->flush();
3233

3334
// login then access a protected page
34-
$client = static::createClient();
3535
$client->request('GET', '/login?email=foo@example.com');
3636

3737
$this->assertSame(302, $client->getResponse()->getStatusCode());

0 commit comments

Comments
 (0)