Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Symfony 5 + many cleanups #480

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/vendor/
/tests/tmp/*
/.php_cs.cache
/.phpunit.result.cache
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ return PhpCsFixer\Config::create()
->setRules(array(
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit75Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'protected_to_private' => false,
'semicolon_after_instruction' => false,
Expand Down
27 changes: 14 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,29 @@
"homepage": "https://symfony.com/contributors"
}
],
"minimum-stability": "dev",
"require": {
"php": "^7.0.8",
"doctrine/inflector": "^1.2",
"nikic/php-parser": "^4.0",
"symfony/config": "^3.4|^4.0",
"symfony/console": "^3.4|^4.0",
"symfony/dependency-injection": "^3.4|^4.0",
"symfony/filesystem": "^3.4|^4.0",
"symfony/finder": "^3.4|^4.0",
"symfony/framework-bundle": "^3.4|^4.0",
"symfony/http-kernel": "^3.4|^4.0"
"symfony/config": "^3.4|^4.0|^5.0",
"symfony/console": "^3.4|^4.0|^5.0",
"symfony/dependency-injection": "^3.4|^4.0|^5.0",
"symfony/filesystem": "^3.4|^4.0|^5.0",
"symfony/finder": "^3.4|^4.0|^5.0",
"symfony/framework-bundle": "^3.4|^4.0|^5.0",
"symfony/http-kernel": "^3.4|^4.0|^5.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.8",
"doctrine/doctrine-bundle": "^1.8|^2.0",
"doctrine/orm": "^2.3",
"friendsofphp/php-cs-fixer": "^2.8",
"friendsoftwig/twigcs": "^3.1.2",
"symfony/http-client": "^4.3",
"symfony/phpunit-bridge": "^3.4.19|^4.0",
"symfony/process": "^3.4|^4.0",
"symfony/security-core": "^3.4|^4.0",
"symfony/yaml": "^3.4|^4.0"
"symfony/http-client": "^4.3|^5.0",
"symfony/phpunit-bridge": "^4.3|^5.0",
"symfony/process": "^3.4|^4.0|^5.0",
"symfony/security-core": "^3.4|^4.0|^5.0",
"symfony/yaml": "^3.4|^4.0|^5.0"
},
"config": {
"preferred-install": "dist",
Expand Down
2 changes: 2 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
failOnRisky="true"
failOnWarning="true"
>
<php>
<ini name="error_reporting" value="-1" />
Expand Down
4 changes: 3 additions & 1 deletion src/Command/MakerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ protected function interact(InputInterface $input, OutputInterface $output)
$this->maker->interact($input, $this->io, $this);
}

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

// sanity check for custom makers
if ($this->generator->hasPendingOperations()) {
throw new \LogicException('Make sure to call the writeChanges() method on the generator.');
}

return 0;
}

public function setApplication(Application $application = null)
Expand Down
4 changes: 2 additions & 2 deletions src/Doctrine/DoctrineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
namespace Symfony\Bundle\MakerBundle\Doctrine;

use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\Common\Persistence\Mapping\MappingException as PersistenceMappingException;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\MappingException as ORMMappingException;
use Doctrine\Common\Persistence\Mapping\MappingException as PersistenceMappingException;
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails;
Expand Down
26 changes: 17 additions & 9 deletions src/EventRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\EventDispatcher\Event as LegacyEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
Expand All @@ -23,17 +27,15 @@
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\Security\Core\Event\AuthenticationEvent;
use Symfony\Component\Security\Core\Event\AuthenticationFailureEvent;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\Event\SwitchUserEvent;
use Symfony\Contracts\EventDispatcher\Event;

/**
* @internal
Expand Down Expand Up @@ -76,10 +78,10 @@ public function __construct(EventDispatcherInterface $eventDispatcher)
$this->eventDispatcher = $eventDispatcher;

// Loop through the new event classes
foreach (self::$newEventsMap as $oldEventName => $newEventClass) {
foreach (self::$newEventsMap as $eventName => $newEventClass) {
//Check if the new event classes exist, if so replace the old one with the new.
if (isset(self::$eventsMap[$oldEventName]) && class_exists($newEventClass)) {
unset(self::$eventsMap[$oldEventName]);
if (isset(self::$eventsMap[$eventName]) && class_exists($newEventClass)) {
unset(self::$eventsMap[$eventName]);
self::$eventsMap[$newEventClass] = $newEventClass;
}
}
Expand Down Expand Up @@ -141,7 +143,13 @@ public function getEventClassName(string $event)
}

if (null !== $type = $args[0]->getType()) {
return (string) $type;
$type = $type instanceof \ReflectionNamedType ? $type->getName() : $type->__toString();

if (LegacyEvent::class === $type && class_exists(Event::class)) {
return Event::class;
}

return $type;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Maker/MakeAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Form\Form;

/**
* @author Ryan Weaver <ryan@knpuniversity.com>
Expand Down
6 changes: 3 additions & 3 deletions src/Maker/MakeEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\Doctrine\DoctrineHelper;
use Symfony\Bundle\MakerBundle\Doctrine\EntityClassGenerator;
use Symfony\Bundle\MakerBundle\Doctrine\EntityRegenerator;
use Symfony\Bundle\MakerBundle\Doctrine\EntityRelation;
use Symfony\Bundle\MakerBundle\Doctrine\ORMDependencyBuilder;
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
use Symfony\Bundle\MakerBundle\FileManager;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\InputAwareMakerInterface;
use Symfony\Bundle\MakerBundle\InputConfiguration;
use Symfony\Bundle\MakerBundle\Str;
use Symfony\Bundle\MakerBundle\Doctrine\EntityRegenerator;
use Symfony\Bundle\MakerBundle\FileManager;
use Symfony\Bundle\MakerBundle\Util\ClassDetails;
use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator;
use Symfony\Bundle\MakerBundle\Doctrine\EntityRelation;
use Symfony\Bundle\MakerBundle\Validator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down
2 changes: 1 addition & 1 deletion src/Maker/MakeFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\MakerBundle\Maker;

use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait;
use Symfony\Bundle\MakerBundle\ConsoleStyle;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\Generator;
Expand All @@ -20,7 +21,6 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\CssSelector\CssSelectorConverter;
use Symfony\Bundle\FrameworkBundle\Test\WebTestAssertionsTrait;
use Symfony\Component\Panther\PantherTestCaseTrait;

/**
Expand Down
26 changes: 13 additions & 13 deletions src/Maker/MakeRegistrationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ private function generateFormClass(ClassNameDetails $userClassDetails, Generator

$formFields = [
$usernameField => null,
'agreeTerms' => [
'type' => CheckboxType::class,
'options_code' => <<<EOF
'mapped' => false,
'constraints' => [
new IsTrue([
'message' => 'You should agree to our terms.',
]),
],
EOF
],
'plainPassword' => [
'type' => PasswordType::class,
'options_code' => <<<EOF
Expand All @@ -310,17 +321,6 @@ private function generateFormClass(ClassNameDetails $userClassDetails, Generator
'max' => 4096,
]),
],
EOF
],
'agreeTerms' => [
'type' => CheckboxType::class,
'options_code' => <<<EOF
'mapped' => false,
'constraints' => [
new IsTrue([
'message' => 'You should agree to our terms.',
]),
],
EOF
],
];
Expand All @@ -330,9 +330,9 @@ private function generateFormClass(ClassNameDetails $userClassDetails, Generator
$formFields,
$userClassDetails,
[
'Symfony\Component\Validator\Constraints\NotBlank',
'Symfony\Component\Validator\Constraints\Length',
'Symfony\Component\Validator\Constraints\IsTrue',
'Symfony\Component\Validator\Constraints\Length',
'Symfony\Component\Validator\Constraints\NotBlank',
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
<?= $user_needs_encoder ? "use Symfony\\Component\\Security\\Core\\Encoder\\UserPasswordEncoderInterface;\n" : null ?>
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
use Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\User\UserInterface;
Expand Down
4 changes: 3 additions & 1 deletion src/Resources/skeleton/command/Command.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function configure()
;
}

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$arg1 = $input->getArgument('arg1');
Expand All @@ -36,5 +36,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$io->success('You have a new command! Now make it your own! Pass --help to see your options.');

return 0;
}
}
4 changes: 2 additions & 2 deletions src/Resources/skeleton/serializer/Normalizer.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace <?= $namespace; ?>;

<?= ($cacheable_interface = interface_exists('Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface')) ? "use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;\n": '' ?>
<?= ($cacheable_interface = interface_exists('Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface')) ? "use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;\n" : '' ?>
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;

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

public function hasCacheableSupportsMethod(): bool
{
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/skeleton/test/Functional.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace <?= $namespace; ?>;

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

<?php if($web_assertions_are_available): ?>
<?php if ($web_assertions_are_available): ?>
$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('h1', 'Hello World');
<?php else: ?>
$this->assertSame(200, $client->getResponse()->getStatusCode());
$this->assertContains('Hello World', $crawler->filter('h1')->text());
$this->assertStringContainsString('Hello World', $crawler->filter('h1')->text());
<?php endif ?>
}
}
11 changes: 5 additions & 6 deletions src/Test/MakerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,28 @@ protected function executeMakerCommand(MakerTestDetails $testDetails)
$csProcess = $testEnv->runPhpCSFixer($file);

$this->assertTrue($csProcess->isSuccessful(), sprintf(
"File '%s' has a php-cs problem: %s\n\n%s",
"File '%s' has a php-cs problem: %s\n",
$file,
$csProcess->getErrorOutput(),
file_get_contents($testEnv->getPath().'/'.$file)
$csProcess->getErrorOutput()."\n".$csProcess->getOutput()
));
}

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

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

// run internal tests
$internalTestProcess = $testEnv->runInternalTests();
if (null !== $internalTestProcess) {
$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()));
$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()));
}

// checkout user asserts
if (null === $testDetails->getAssert()) {
$this->assertContains('Success', $makerTestProcess->getOutput(), $makerTestProcess->getErrorOutput());
$this->assertStringContainsString('Success', $makerTestProcess->getOutput(), $makerTestProcess->getErrorOutput());
} else {
($testDetails->getAssert())($makerTestProcess->getOutput(), $testEnv->getPath());
}
Expand Down
9 changes: 8 additions & 1 deletion src/Test/MakerTestEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,20 @@ private function buildFlexSkeleton()
// fetch a few packages needed for testing
MakerTestProcess::create('composer require phpunit browser-kit symfony/css-selector --prefer-dist --no-progress --no-suggest', $this->flexPath)
->run();
$this->fs->remove($this->flexPath.'/vendor/symfony/phpunit-bridge');

if ('\\' !== \DIRECTORY_SEPARATOR) {
$this->fs->symlink('../../../../../../vendor/symfony/phpunit-bridge', './vendor/symfony/phpunit-bridge');
} else {
$this->fs->mirror(\dirname(__DIR__, 2).'/vendor/symfony/phpunit-bridge', $this->flexPath.'/vendor/symfony/phpunit-bridge');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the required phpunit bridge was now a problem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bridge used for the main test suite and for functional tests must be at exactly the same version because they share the same runtime space. This leads to a fatal error right now when main is 4.4 or 5.0 but functionals stay at 4.3.


// temporarily ignoring indirect deprecations - see #237
$replacements = [
[
'filename' => '.env.test',
'find' => 'SYMFONY_DEPRECATIONS_HELPER=999999',
'replace' => 'SYMFONY_DEPRECATIONS_HELPER=weak_vendors',
'replace' => 'SYMFONY_DEPRECATIONS_HELPER=max[self]=0',
],
];
$this->processReplacements($replacements, $this->flexPath);
Expand Down