Upgrading Symfony 3.4 to 4.x with Flex - Composer Problems - symfony

I have a Symfony 3.4 project I'm trying to upgrade to 4.x with Flex but I'm falling at the first hurdle.
With the output of Composer this verbose I assume the answer is staring me straight in the face, but I'm not seeing it. What do I need to do? I've deleted everything in vendor, deleted my composer.lock file, cleared composer cache, etc.
composer.json
{
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"sensio/framework-extra-bundle": "^5.5",
"symfony/console": "4.4.*",
"symfony/dotenv": "4.4.*",
"symfony/flex": "^1.3.1",
"symfony/framework-bundle": "4.4.*",
"symfony/monolog-bundle": "^3.5",
"symfony/orm-pack": "^1.0",
"symfony/profiler-pack": "^1.0",
"symfony/twig-pack": "^1.0",
"symfony/yaml": "4.4.*",
"friendsofsymfony/jsrouting-bundle": "^2.5",
"friendsofsymfony/user-bundle": "~2.0",
"stof/doctrine-extensions-bundle": "^1.3",
"symfony/swiftmailer-bundle": "^2.6.4",
"ext-json": "*"
},
"require-dev": {
"symfony/debug-pack": "^1.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.19",
"phpstan/phpstan-doctrine": "^0.12.10",
"phpunit/phpunit": "^7.5",
"symfony/phpunit-bridge": "^3.0"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
]
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.4.*"
}
}
}
Tried to composer install with:
php -d memory_limit=-1 /usr/local/bin/composer install
And it spews all this out (too big to paste here): https://pastebin.com/KLVRkYdF
Saw something elsewhere about needing to install Flex on its own first, so I tried this:
php -d memory_limit=-1 /usr/local/bin/composer update symfony/flex --no-plugins --no-scripts
But got the following error (too big to paste here): https://pastebin.com/KxG2siZi

The problem is that you haven't updated symfony/swiftmailer-bundle - as given in the composer.json, you tried to install at most v2.6.7 which requires symfony/http-kernelin v2.7 or v3.x. This is not compatible with symfony/framework-bundle in v4.4, as this requires symfony/http-kernel to be of that same v4.4 branch.
Conclusion: also update symfony/swiftmailer-bundle to at least v3.1 which is the first one to be compatible with Symfony v4.

I also had a lot of issues with composer, packageversions and memory limits in the past.
Package vesions:
Set all symfony packages to the version "*" if yout dont require a specific Version at this point. Thisway composer will select the one suitable to your configured symfony version.
Memory limit:
Which IDE are you using? Which PHP Version? 32 or 64 bit? Try running the commany outside of the IDE and see what happens. Alternatively try the symfony command.

Related

Symfony maker bundle doesn't meet the requirements

I'm trying to start a new symfony --version=5.2 project, and before everything else I'm installing the symfony maker bundle, but I get this error which I can't find no solution for it.
Info from https://repo.packagist.org: #StandWithUkraine
Using version ^1.43 for symfony/maker-bundle
./composer.json has been updated
Running composer update symfony/maker-bundle
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires symfony/maker-bundle ^1.43 -> satisfiable by symfony/maker-bundle[v1.43.0].
- symfony/maker-bundle v1.43.0 requires symfony/config ^5.4.7|^6.0 -> found symfony/config[v5.4.7, v5.4.8, v5.4.9, v6.0.0, ..., v6.1.0] but the package is fixed to v5.2.12 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
You can also try re-running composer require with an explicit version constraint, e.g. "composer require symfony/maker-bundle:*" to figure out if any version is installable, or "composer require symfony/maker-bundle:^2.1" if you know which you need.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
I tried changing the maker-bundle version myself but still got the same error.
I tried to search for similar problems but no luck finding this error.
{
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=7.2.5",
"ext-ctype": "*",
"ext-iconv": "*",
"doctrine/doctrine-bundle": "^2.6",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^2.12",
"symfony/console": "5.2.*",
"symfony/dotenv": "5.2.*",
"symfony/flex": "^1.3.1",
"symfony/framework-bundle": "5.2.*",
"symfony/http-client": "5.2.*",
"symfony/proxy-manager-bridge": "5.2.*",
"symfony/yaml": "5.2.*"
},
"config": {
"allow-plugins": {
"composer/package-versions-deprecated": true,
"symfony/flex": true
},
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"docker": false,
"require": "5.2.*"
}
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "5.2.*",
"symfony/css-selector": "5.2.*",
"symfony/phpunit-bridge": "^6.1"
}
}

sh: symfony-cmd: command not found

I have downgraded a Symfony 5.2 app template to use Symfony 4.4 in order to allow the use of some libraries that require an older version of Symfony. The problem is that when I do composer install, I get this error near the end of the installation:
sh: symfony-cmd: command not found
It seems that the installations are mostly successful, as my vendor folder is created and populated. But I'm worried about the error.
What does this error mean? How do I fix it?
====
Edit: Here's my composer.json file:
{
"type": "project",
"license": "proprietary",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.4.0",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"composer/package-versions-deprecated": "1.11.99.1",
"cweagans/composer-patches": "^1.7",
"doctrine/doctrine-bundle": "^2.4",
"doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/orm": "^2.9",
"phpdocumentor/reflection-docblock": "*",
"sensio/framework-extra-bundle": "*",
"symfony/framework-bundle": "4.4.*",
"symfony/http-client": "*",
"symfony/intl": "*",
"symfony/mailer": "*",
"symfony/mime": "*",
"symfony/monolog-bundle": "^3.1",
"symfony/notifier": "*",
"symfony/process": "*",
"symfony/property-access": "*",
"symfony/property-info": "*",
"symfony/proxy-manager-bridge": "*",
"symfony/security-bundle": "*",
"symfony/serializer": "*",
"symfony/string": "*",
"symfony/translation": "*",
"symfony/twig-bundle": "*",
"symfony/validator": "*",
"symfony/web-link": "*",
"symfony/yaml": "*",
"twig/extra-bundle": "*",
"twig/twig": "*"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4",
"roave/security-advisories": "dev-master",
"symfony/browser-kit": "*",
"symfony/css-selector": "*",
"symfony/debug-bundle": "*",
"symfony/maker-bundle": "*",
"symfony/phpunit-bridge": "*",
"symfony/stopwatch": "*",
"symfony/var-dumper": "*",
"symfony/web-profiler-bundle": "*",
"vimeo/psalm": "^4.9"
},
"config": {
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.2.*"
},
"patches": {
"symfony/maker-bundle": {
"Provide flag to force annotation in make entity command": "https://raw.githubusercontent.com/vklux/maker-bundle-force-annotation/master/maker-force-annotation-flag.patch"
}
}
}
}
For those who have the symfony/flex package installed and are still getting the error, make sure the symfony/flex package is allowed to execute code when running composer.
This is because since Composer 2.2.0 the allow-plugins option adds a layer of security that allows you to restrict which Composer plugins can execute code at startup time.
So make sure you have the appropriate line in the allow-plugins config in your composer.json file
"config": {
// other config...
"allow-plugins": {
"symfony/flex": true
}
},
symfony-cmd is a part of Symfony Flex. Your composer.json does not contain any requirement for Flex, so running composer require symfony/flex might resolve that problem.
While adding symfony/flex to the project is one solution, keep in mind that Flex is optional. If you want to get rid of the error without installing Flex, simply remove the symfony-cmd command references from your composer.json.
Before:
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
]
},
After:
"scripts": {
"auto-scripts": {},
"post-install-cmd": [],
"post-update-cmd": []
},
I ran into a special case were an old deploy script added --no-plugins to my composer command. Removing that solved my issue with using deployer v6.
set('composer_options', '{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader');
Apparently you need plugins for flex to work, and I'm assuming since the scripts block has some commands you need that too. So having no script/plugins will break your installation.

Error while upgrading symfony 4.3 to 4.4 (Call to a member function generate() on null)

I'm trying to update my symfony project from 4.3 to 4.4.
In my composer.json file, I changed all "symfony/" dependencies to point from 4.3. to 4.4.*. I updated all dependencies by executing form terminal:
composer.phar update --with-all-dependencies
After the update, everything looks fine. There are a couple of warnings but I don't think that's the problem. Here is the result in the terminal:
Loading composer repositories with package information
Restricting packages listed in "symfony/symfony" to "4.4.*"
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Package doctrine/reflection is abandoned, you should avoid using it. Use roave/better-reflection instead.
Package paypal/paypalhttp is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
103 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Synchronizing package.json with PHP packages
Don't forget to run npm install --force or yarn install --force to refresh your JavaScript dependencies!
Run composer recipes at any time to see the status of your Symfony recipes.
Executing script cache:clear [OK]
Executing script assets:install public [OK]
The problem comes when I load any page in the browser, it shows this error for all the pages
Call to a member function generate() on null
in vendor/symfony/twig-bridge/Extension/RoutingExtension.php (line 71)
The error looks like this
I found that the error gets executed when the application access any controller and tries to show the view by calling the twig file with this line:
return $this->render('mytemplate',[]);
I thought the problem was created by a twig conflict and tried to return a random html directly from the controller to avoid calling the twig file, however the error persists:
public function testController(): Response
{
//the error happens when it executes the return
return new Response(
'<html><body>TEST</body></html>'
);
}
My composer.json file looks like this:
{
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"beelab/paypal-bundle": "v1.5.0",
"paypal/paypal-checkout-sdk": "1.0.1",
"curl/curl": "2.2.0",
"doctrine/doctrine-bundle": "2.3",
"doctrine/doctrine-migrations-bundle": "3.0.2",
"doctrine/orm": "^2.5.11",
"friendsofsymfony/rest-bundle": "2.6.0",
"php-http/guzzle6-adapter": "^2.0",
"phpoffice/phpspreadsheet": "^1.11",
"sensio/framework-extra-bundle": "v5.5.1",
"sonata-project/admin-bundle": "3.93",
"sonata-project/doctrine-orm-admin-bundle": "3.31",
"stof/doctrine-extensions-bundle": "v1.3.0",
"stripe/stripe-php": "v7.14.2",
"symfony/apache-pack": "^1.0",
"symfony/asset": "4.4.*",
"symfony/console": "4.4.*",
"symfony/dotenv": "4.4.*",
"symfony/expression-language": "4.4.*",
"symfony/flex": "v1.12",
"symfony/form": "4.4.*",
"symfony/framework-bundle": "4.4.*",
"symfony/http-client": "4.4.*",
"symfony/intl": "4.4.*",
"symfony/monolog-bundle": "v3.5.0",
"symfony/process": "4.4.*",
"symfony/security-bundle": "4.4.*",
"symfony/serializer-pack": "v1.0.2",
"symfony/swiftmailer-bundle": "v3.4.0",
"symfony/templating": "4.4.*",
"symfony/translation": "4.4.*",
"symfony/twig-bundle": "4.4.*",
"symfony/twig-bridge": "4.4.*",
"symfony/validator": "4.4.*",
"symfony/web-link": "4.4.*",
"symfony/webpack-encore-bundle": "v1.7.2",
"symfony/yaml": "4.4.*",
"symfony/doctrine-bridge": "4.4.*",
"symfony/profiler-pack": "v1.0.5",
"symfony/web-profiler-bundle": "4.4.*"
},
"require-dev": {
"symfony/debug-pack": "*",
"symfony/maker-bundle": "^1.11",
"symfony/profiler-pack": "*",
"symfony/test-pack": "*",
"symfony/web-server-bundle": "4.4.*"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/",
"Sim\\": "lib/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"paragonie/random_compat": "2.*",
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.4.*"
}
}
}

Deploying Symfony on Heroku

I'm trying to deploy a Symfony 5.2 on Heroku, I've already configured the Procfile and the required Config Vars such APP_ENV (prod), APP_SECRET and others related to the project.
Procfile:
web: vendor/bin/heroku-php-apache2 public/
composer.json:
{
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.2.5",
"ext-ctype": "*",
"ext-iconv": "*",
"knplabs/knp-paginator-bundle": "^5.2",
"lexik/jwt-authentication-bundle": "^2.8",
"nelmio/cors-bundle": "^2.0",
"sensio/framework-extra-bundle": "^5.5",
"symfony/asset": "5.1.*",
"symfony/console": "5.1.*",
"symfony/dotenv": "5.1.*",
"symfony/flex": "^1.3.1",
"symfony/framework-bundle": "5.1.*",
"symfony/mailer": "5.1.*",
"symfony/orm-pack": "^1.0",
"symfony/security-bundle": "5.1.*",
"symfony/serializer": "5.1.*",
"symfony/yaml": "5.1.*",
"twig/twig": "^3.0"
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3",
"symfony/maker-bundle": "^1.19",
"symfony/profiler-pack": "^1.0"
},
"config": {
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
},
"replace": {
"paragonie/random_compat": "2.*",
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"#auto-scripts"
],
"post-update-cmd": [
"#auto-scripts"
],
"compile": [
"php bin/console doctrine:migrations:migrate"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.1.*"
}
}
}
No matter what I do I always end up with an error related to something missing such as:
PHP Fatal error: Uncaught Error: Class 'Symfony\Bundle\TwigBundle\TwigBundle' not found in /tmp/build_271a300c_/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php:74
My guess is the problem is related with everything ending up in this /tmp/build_271a300c_ folder and when the project is deployed it lost the refereed folder. But I have no idea what to do with this information I appreciate any help.
Solved the problem with, what I think, is nothing more than a workaround.
The deploy process was complaining always about the require-dev dependencies, so I did:
Moved all require-dev to require;
Run composer update to refresh the composer.lock file;
Pushed and tried the deploy again with success.
This solution was take for many people in other issues I read, I'm just describing step-by-step what was done to fix it. Still, I don't think it's the correct fix for this, after all the dev-dependencies shouldn't being installed on prod environment.

Behat+Mink+Selenium installation

I'm getting error below when trying to install Behat+Mink+Selenium. What could be the solution?
php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for symfony/framework-standard-edition 2.4.x-dev -> satisfiable by symfony/framework-standard-edition[2.4.x-dev].
- symfony/framework-standard-edition 2.4.x-dev requires behat/behat 2.4.*#stable -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Composer.json:
{
"name": "symfony/framework-standard-edition",
"license": "MIT",
"type": "project",
"description": "The \"Symfony Standard Edition\" distribution",
"minimum-stability": "dev",
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.4",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~2.3",
"sensio/framework-extra-bundle": "~3.0",
"sensio/generator-bundle": "~2.3",
"incenteev/composer-parameter-handler": "~2.0",
"behat/behat": "2.4.*#stable",
"behat/mink": "1.4.*#stable",
"behat/mink-extension": "*",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium2-driver": "*",
"behat/symfony2-extension": "*",
"behat/mink-browserkit-driver": "*",
"behat/mink-sahi-driver": "*",
"phpunit/phpunit": "3.7.*"
},
"scripts": {
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
},
"config": {
"bin-dir": "bin/"
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.4-dev"
}
}
}
I'm following these two blogs to install it:
Installing, configuring and running Behat on Symfony2 with Mink and
Selenium
Installing Behat, Mink and Selenium2 for Symfony2
IMO, you have registered too many packages. For example, behat is a dependency of the symfony2-extension. So, just need to require the symfony2-extension and behat will be required :) The problem when you require everything explicitly is you need to check if every packages constraints can work together on packagist (which can becomes a pain)...
For a Symfony 2.4 project, I would use the following packages:
"require-dev": {
"behat/symfony2-extension": "~1.1",
"behat/mink-extension": "~1.3",
"behat/mink-selenium2-driver": "~1.1",
"behat/mink-goutte-driver": "~1.0",
}
I would suggest run composer require, and before you installing do a composer update so that all dependencies are at updated version. So the below dependencie were usesful for my symfony2.8 project:
composer update
composer require behat/behat
composer require behat/symfony2-extension
composer require behat/mink
composer require behat/mink-browserkit-driver
composer require behat/mink-extension
composer require behat/mink-goutte-driver
composer require behat/mink-selenium2-driver
composer require emuse/behat-html-formatter
composer require coduo/php-matcher

Resources