Skip to content

Commit 31a7597

Browse files
committed
bug #480 Allow Symfony 5 + many cleanups (nicolas-grekas)
This PR was merged into the 1.0-dev branch. Discussion ---------- Allow Symfony 5 + many cleanups Note that having php-cs-fixer in the deps blocks installing Symfony 5 (did I already mention it's a bad practice to add tools as deps? ;) ) But locally when I remove php-cs-fixer (and patch the code to use my local version), all is green, with SF5 deps. Commits ------- 2cf9460 Allow Symfony 5 + many cleanups
2 parents 3e3651e + 2cf9460 commit 31a7597

File tree

87 files changed

+629
-463
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+629
-463
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/vendor/
44
/tests/tmp/*
55
/.php_cs.cache
6+
/.phpunit.result.cache

.php_cs.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ return PhpCsFixer\Config::create()
1919
->setRules(array(
2020
'@Symfony' => true,
2121
'@Symfony:risky' => true,
22+
'@PHPUnit75Migration:risky' => true,
2223
'array_syntax' => ['syntax' => 'short'],
2324
'protected_to_private' => false,
2425
'semicolon_after_instruction' => false,

composer.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,29 @@
1111
"homepage": "https://symfony.com/contributors"
1212
}
1313
],
14+
"minimum-stability": "dev",
1415
"require": {
1516
"php": "^7.0.8",
1617
"doctrine/inflector": "^1.2",
1718
"nikic/php-parser": "^4.0",
18-
"symfony/config": "^3.4|^4.0",
19-
"symfony/console": "^3.4|^4.0",
20-
"symfony/dependency-injection": "^3.4|^4.0",
21-
"symfony/filesystem": "^3.4|^4.0",
22-
"symfony/finder": "^3.4|^4.0",
23-
"symfony/framework-bundle": "^3.4|^4.0",
24-
"symfony/http-kernel": "^3.4|^4.0"
19+
"symfony/config": "^3.4|^4.0|^5.0",
20+
"symfony/console": "^3.4|^4.0|^5.0",
21+
"symfony/dependency-injection": "^3.4|^4.0|^5.0",
22+
"symfony/filesystem": "^3.4|^4.0|^5.0",
23+
"symfony/finder": "^3.4|^4.0|^5.0",
24+
"symfony/framework-bundle": "^3.4|^4.0|^5.0",
25+
"symfony/http-kernel": "^3.4|^4.0|^5.0"
2526
},
2627
"require-dev": {
27-
"doctrine/doctrine-bundle": "^1.8",
28+
"doctrine/doctrine-bundle": "^1.8|^2.0",
2829
"doctrine/orm": "^2.3",
2930
"friendsofphp/php-cs-fixer": "^2.8",
3031
"friendsoftwig/twigcs": "^3.1.2",
31-
"symfony/http-client": "^4.3",
32-
"symfony/phpunit-bridge": "^3.4.19|^4.0",
33-
"symfony/process": "^3.4|^4.0",
34-
"symfony/security-core": "^3.4|^4.0",
35-
"symfony/yaml": "^3.4|^4.0"
32+
"symfony/http-client": "^4.3|^5.0",
33+
"symfony/phpunit-bridge": "^4.3|^5.0",
34+
"symfony/process": "^3.4|^4.0|^5.0",
35+
"symfony/security-core": "^3.4|^4.0|^5.0",
36+
"symfony/yaml": "^3.4|^4.0|^5.0"
3637
},
3738
"config": {
3839
"preferred-install": "dist",

phpunit.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
backupGlobals="false"
77
colors="true"
88
bootstrap="vendor/autoload.php"
9+
failOnRisky="true"
10+
failOnWarning="true"
911
>
1012
<php>
1113
<ini name="error_reporting" value="-1" />

src/Command/MakerCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,16 @@ protected function interact(InputInterface $input, OutputInterface $output)
9999
$this->maker->interact($input, $this->io, $this);
100100
}
101101

102-
protected function execute(InputInterface $input, OutputInterface $output)
102+
protected function execute(InputInterface $input, OutputInterface $output): int
103103
{
104104
$this->maker->generate($input, $this->io, $this->generator);
105105

106106
// sanity check for custom makers
107107
if ($this->generator->hasPendingOperations()) {
108108
throw new \LogicException('Make sure to call the writeChanges() method on the generator.');
109109
}
110+
111+
return 0;
110112
}
111113

112114
public function setApplication(Application $application = null)

src/Doctrine/DoctrineHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
namespace Symfony\Bundle\MakerBundle\Doctrine;
1313

1414
use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
15+
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
1516
use Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver;
1617
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
1718
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
19+
use Doctrine\Common\Persistence\Mapping\MappingException as PersistenceMappingException;
1820
use Doctrine\ORM\EntityManagerInterface;
19-
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
2021
use Doctrine\ORM\Mapping\MappingException as ORMMappingException;
21-
use Doctrine\Common\Persistence\Mapping\MappingException as PersistenceMappingException;
2222
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
2323
use Symfony\Bridge\Doctrine\ManagerRegistry;
2424
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails;

src/EventRegistry.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
use Symfony\Component\Console\Event\ConsoleCommandEvent;
1515
use Symfony\Component\Console\Event\ConsoleErrorEvent;
1616
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
17+
use Symfony\Component\EventDispatcher\Event as LegacyEvent;
1718
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
19+
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
20+
use Symfony\Component\HttpKernel\Event\ControllerEvent;
21+
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
1822
use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent;
1923
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
2024
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
@@ -23,17 +27,15 @@
2327
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
2428
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
2529
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
26-
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
27-
use Symfony\Component\HttpKernel\Event\ControllerEvent;
28-
use Symfony\Component\HttpKernel\Event\ResponseEvent;
2930
use Symfony\Component\HttpKernel\Event\RequestEvent;
30-
use Symfony\Component\HttpKernel\Event\ViewEvent;
31-
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
31+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
3232
use Symfony\Component\HttpKernel\Event\TerminateEvent;
33+
use Symfony\Component\HttpKernel\Event\ViewEvent;
3334
use Symfony\Component\Security\Core\Event\AuthenticationEvent;
3435
use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent;
3536
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
3637
use Symfony\Component\Security\Http\Event\SwitchUserEvent;
38+
use Symfony\Contracts\EventDispatcher\Event;
3739

3840
/**
3941
* @internal
@@ -76,10 +78,10 @@ public function __construct(EventDispatcherInterface $eventDispatcher)
7678
$this->eventDispatcher = $eventDispatcher;
7779

7880
// Loop through the new event classes
79-
foreach (self::$newEventsMap as $oldEventName => $newEventClass) {
81+
foreach (self::$newEventsMap as $eventName => $newEventClass) {
8082
//Check if the new event classes exist, if so replace the old one with the new.
81-
if (isset(self::$eventsMap[$oldEventName]) && class_exists($newEventClass)) {
82-
unset(self::$eventsMap[$oldEventName]);
83+
if (isset(self::$eventsMap[$eventName]) && class_exists($newEventClass)) {
84+
unset(self::$eventsMap[$eventName]);
8385
self::$eventsMap[$newEventClass] = $newEventClass;
8486
}
8587
}
@@ -141,7 +143,13 @@ public function getEventClassName(string $event)
141143
}
142144

143145
if (null !== $type = $args[0]->getType()) {
144-
return (string) $type;
146+
$type = $type instanceof \ReflectionNamedType ? $type->getName() : $type->__toString();
147+
148+
if (LegacyEvent::class === $type && class_exists(Event::class)) {
149+
return Event::class;
150+
}
151+
152+
return $type;
145153
}
146154
}
147155

src/Maker/MakeAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
use Symfony\Component\Console\Input\InputInterface;
3434
use Symfony\Component\Console\Input\InputOption;
3535
use Symfony\Component\Console\Question\Question;
36+
use Symfony\Component\Form\Form;
3637
use Symfony\Component\HttpKernel\Kernel;
3738
use Symfony\Component\Yaml\Yaml;
38-
use Symfony\Component\Form\Form;
3939

4040
/**
4141
* @author Ryan Weaver <[email protected]>

src/Maker/MakeEntity.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
use Symfony\Bundle\MakerBundle\DependencyBuilder;
1919
use Symfony\Bundle\MakerBundle\Doctrine\DoctrineHelper;
2020
use Symfony\Bundle\MakerBundle\Doctrine\EntityClassGenerator;
21+
use Symfony\Bundle\MakerBundle\Doctrine\EntityRegenerator;
22+
use Symfony\Bundle\MakerBundle\Doctrine\EntityRelation;
2123
use Symfony\Bundle\MakerBundle\Doctrine\ORMDependencyBuilder;
2224
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
25+
use Symfony\Bundle\MakerBundle\FileManager;
2326
use Symfony\Bundle\MakerBundle\Generator;
2427
use Symfony\Bundle\MakerBundle\InputAwareMakerInterface;
2528
use Symfony\Bundle\MakerBundle\InputConfiguration;
2629
use Symfony\Bundle\MakerBundle\Str;
27-
use Symfony\Bundle\MakerBundle\Doctrine\EntityRegenerator;
28-
use Symfony\Bundle\MakerBundle\FileManager;
2930
use Symfony\Bundle\MakerBundle\Util\ClassDetails;
3031
use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator;
31-
use Symfony\Bundle\MakerBundle\Doctrine\EntityRelation;
3232
use Symfony\Bundle\MakerBundle\Validator;
3333
use Symfony\Component\Console\Command\Command;
3434
use Symfony\Component\Console\Input\InputArgument;

src/Maker/MakeFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\Maker;
1313

14+
use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait;
1415
use Symfony\Bundle\MakerBundle\ConsoleStyle;
1516
use Symfony\Bundle\MakerBundle\DependencyBuilder;
1617
use Symfony\Bundle\MakerBundle\Generator;
@@ -20,7 +21,6 @@
2021
use Symfony\Component\Console\Input\InputArgument;
2122
use Symfony\Component\Console\Input\InputInterface;
2223
use Symfony\Component\CssSelector\CssSelectorConverter;
23-
use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait;
2424
use Symfony\Component\Panther\PantherTestCaseTrait;
2525

2626
/**

src/Maker/MakeRegistrationForm.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,17 @@ private function generateFormClass(ClassNameDetails $userClassDetails, Generator
293293

294294
$formFields = [
295295
$usernameField => null,
296+
'agreeTerms' => [
297+
'type' => CheckboxType::class,
298+
'options_code' => <<<EOF
299+
'mapped' => false,
300+
'constraints' => [
301+
new IsTrue([
302+
'message' => 'You should agree to our terms.',
303+
]),
304+
],
305+
EOF
306+
],
296307
'plainPassword' => [
297308
'type' => PasswordType::class,
298309
'options_code' => <<<EOF
@@ -310,17 +321,6 @@ private function generateFormClass(ClassNameDetails $userClassDetails, Generator
310321
'max' => 4096,
311322
]),
312323
],
313-
EOF
314-
],
315-
'agreeTerms' => [
316-
'type' => CheckboxType::class,
317-
'options_code' => <<<EOF
318-
'mapped' => false,
319-
'constraints' => [
320-
new IsTrue([
321-
'message' => 'You should agree to our terms.',
322-
]),
323-
],
324324
EOF
325325
],
326326
];
@@ -330,9 +330,9 @@ private function generateFormClass(ClassNameDetails $userClassDetails, Generator
330330
$formFields,
331331
$userClassDetails,
332332
[
333-
'Symfony\Component\Validator\Constraints\NotBlank',
334-
'Symfony\Component\Validator\Constraints\Length',
335333
'Symfony\Component\Validator\Constraints\IsTrue',
334+
'Symfony\Component\Validator\Constraints\Length',
335+
'Symfony\Component\Validator\Constraints\NotBlank',
336336
]
337337
);
338338

src/Resources/skeleton/authenticator/LoginFormAuthenticator.tpl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use Symfony\Component\HttpFoundation\Request;
99
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1010
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
11-
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
1211
<?= $user_needs_encoder ? "use Symfony\\Component\\Security\\Core\\Encoder\\UserPasswordEncoderInterface;\n" : null ?>
12+
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
1313
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
1414
use Symfony\Component\Security\Core\Security;
1515
use Symfony\Component\Security\Core\User\UserInterface;

src/Resources/skeleton/command/Command.tpl.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function configure()
2222
;
2323
}
2424

25-
protected function execute(InputInterface $input, OutputInterface $output)
25+
protected function execute(InputInterface $input, OutputInterface $output): int
2626
{
2727
$io = new SymfonyStyle($input, $output);
2828
$arg1 = $input->getArgument('arg1');
@@ -36,5 +36,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3636
}
3737

3838
$io->success('You have a new command! Now make it your own! Pass --help to see your options.');
39+
40+
return 0;
3941
}
4042
}

src/Resources/skeleton/serializer/Normalizer.tpl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
<?= ($cacheable_interface = interface_exists('Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface')) ? "use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;\n": '' ?>
5+
<?= ($cacheable_interface = interface_exists('Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface')) ? "use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;\n" : '' ?>
66
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
77
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
88

@@ -28,7 +28,7 @@ public function supportsNormalization($data, $format = null): bool
2828
{
2929
return $data instanceof \App\Entity\BlogPost;
3030
}
31-
<?php if($cacheable_interface): ?>
31+
<?php if ($cacheable_interface): ?>
3232

3333
public function hasCacheableSupportsMethod(): bool
3434
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
<?php if($panther_is_available): ?>
5+
<?php if ($panther_is_available): ?>
66
use Symfony\Component\Panther\PantherTestCase;
77
<?php else: ?>
88
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@@ -15,12 +15,12 @@ public function testSomething()
1515
$client = static::createClient();
1616
$crawler = $client->request('GET', '/');
1717

18-
<?php if($web_assertions_are_available): ?>
18+
<?php if ($web_assertions_are_available): ?>
1919
$this->assertResponseIsSuccessful();
2020
$this->assertSelectorTextContains('h1', 'Hello World');
2121
<?php else: ?>
2222
$this->assertSame(200, $client->getResponse()->getStatusCode());
23-
$this->assertContains('Hello World', $crawler->filter('h1')->text());
23+
$this->assertStringContainsString('Hello World', $crawler->filter('h1')->text());
2424
<?php endif ?>
2525
}
2626
}

src/Test/MakerTestCase.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,28 @@ protected function executeMakerCommand(MakerTestDetails $testDetails)
3737
$csProcess = $testEnv->runPhpCSFixer($file);
3838

3939
$this->assertTrue($csProcess->isSuccessful(), sprintf(
40-
"File '%s' has a php-cs problem: %s\n\n%s",
40+
"File '%s' has a php-cs problem: %s\n",
4141
$file,
42-
$csProcess->getErrorOutput(),
43-
file_get_contents($testEnv->getPath().'/'.$file)
42+
$csProcess->getErrorOutput()."\n".$csProcess->getOutput()
4443
));
4544
}
4645

4746
if ('.twig' === substr($file, -5)) {
4847
$csProcess = $testEnv->runTwigCSLint($file);
4948

50-
$this->assertTrue($csProcess->isSuccessful(), sprintf('File "%s" has a twig-cs problem: %s', $file, $csProcess->getOutput()));
49+
$this->assertTrue($csProcess->isSuccessful(), sprintf('File "%s" has a twig-cs problem: %s', $file, $csProcess->getErrorOutput()."\n".$csProcess->getOutput()));
5150
}
5251
}
5352

5453
// run internal tests
5554
$internalTestProcess = $testEnv->runInternalTests();
5655
if (null !== $internalTestProcess) {
57-
$this->assertTrue($internalTestProcess->isSuccessful(), sprintf("Error while running the PHPUnit tests *in* the project: \n\n %s \n\n Command Output: %s", $internalTestProcess->getOutput(), $makerTestProcess->getOutput()));
56+
$this->assertTrue($internalTestProcess->isSuccessful(), sprintf("Error while running the PHPUnit tests *in* the project: \n\n %s \n\n Command Output: %s", $internalTestProcess->getErrorOutput()."\n".$internalTestProcess->getOutput(), $makerTestProcess->getErrorOutput()."\n".$makerTestProcess->getOutput()));
5857
}
5958

6059
// checkout user asserts
6160
if (null === $testDetails->getAssert()) {
62-
$this->assertContains('Success', $makerTestProcess->getOutput(), $makerTestProcess->getErrorOutput());
61+
$this->assertStringContainsString('Success', $makerTestProcess->getOutput(), $makerTestProcess->getErrorOutput());
6362
} else {
6463
($testDetails->getAssert())($makerTestProcess->getOutput(), $testEnv->getPath());
6564
}

src/Test/MakerTestEnvironment.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,20 @@ private function buildFlexSkeleton()
350350
// fetch a few packages needed for testing
351351
MakerTestProcess::create('composer require phpunit browser-kit symfony/css-selector --prefer-dist --no-progress --no-suggest', $this->flexPath)
352352
->run();
353+
$this->fs->remove($this->flexPath.'/vendor/symfony/phpunit-bridge');
354+
355+
if ('\\' !== \DIRECTORY_SEPARATOR) {
356+
$this->fs->symlink('../../../../../../vendor/symfony/phpunit-bridge', './vendor/symfony/phpunit-bridge');
357+
} else {
358+
$this->fs->mirror(\dirname(__DIR__, 2).'/vendor/symfony/phpunit-bridge', $this->flexPath.'/vendor/symfony/phpunit-bridge');
359+
}
353360

354361
// temporarily ignoring indirect deprecations - see #237
355362
$replacements = [
356363
[
357364
'filename' => '.env.test',
358365
'find' => 'SYMFONY_DEPRECATIONS_HELPER=999999',
359-
'replace' => 'SYMFONY_DEPRECATIONS_HELPER=weak_vendors',
366+
'replace' => 'SYMFONY_DEPRECATIONS_HELPER=max[self]=0',
360367
],
361368
];
362369
$this->processReplacements($replacements, $this->flexPath);

0 commit comments

Comments
 (0)