Simulate another environment by using the 'composer update' command

5

I have a Symfony2 project with dependencies managed by composer , with their composer.json and composer.lock files synchronized between my local machine and the production server through git .

It is known that when running the command composer update , some checks of machine settings are made before the dependency versions are chosen, since in some cases different versions of the same package are compatible with different environments.

An example of a multi-version package is symfony/icu , which is responsible for internalizing Symfony2 . The version chosen by composer for this package differs between 1.0.0 and 1.2.0 depending on the existence or absence of the lib-icu library on the machine.

Case 1 - Run composer update on local machine

When I run composer update on my local machine , which has the lib-icu internationalization library, a composer.lock file is created that references version v.1.2.0 of symfony/icu package %.

Problem: The production server does not have the lib-icu library, so when I run composer install from the previously generated composer.lock , an error is returned that is missing from that library.

Case 2 - Run composer update on the production server

If, on the other hand, I run composer update on my production server , the automatically chosen dependency of symfony/icu is version v1.0.0 (which works without lib-icu ). In this situation, running composer install everything works fine, both on the production server and on my local machine.

How to simulate the production server environment?

My question is: is there any way I can run composer update on my local machine by forcing the composer to use version v1.0.0 of the symfony/icu package instead of using v1.2.0 based on the my machine? That is, I want to run composer update on my local machine, and get the same result I would get if I ran it on the remote server, as if my local machine did not have the lib-icu library.

My composer.json

{
    "name": "symfony/framework-standard-edition",
    "license": "MIT",
    "type": "project",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": {
            "": "src/",
            "Application": "app/"
        }
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.3.*",
        "doctrine/orm": ">=2.2.3,<2.4-dev",
        "doctrine/doctrine-bundle": "1.2.*",
        "twig/extensions": "1.0.*",
        "symfony/assetic-bundle": "2.3.*",
        "symfony/swiftmailer-bundle": "2.3.*",
        "symfony/monolog-bundle": "2.3.*",
        "sensio/distribution-bundle": "2.3.*",
        "sensio/framework-extra-bundle": "2.3.*",
        "sensio/generator-bundle": "2.3.*",
        "incenteev/composer-parameter-handler": "~2.0",
        "sonata-project/admin-bundle": "2.2.7",
        "sonata-project/doctrine-orm-admin-bundle": "2.2.4",
        "sonata-project/easy-extends-bundle": "2.1.3",
        "sonata-project/user-bundle": "2.2.0"
    },
    "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"
    },
    "minimum-stability": "stable",
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "2.3-dev"
        }
    }
}
    
asked by anonymous 15.12.2013 / 01:18

1 answer

2

I would try to include this package explicitly, passing the desired version. This may well have priority over the chain of dependencies that the composer is using. I believe that anyone who asks for symfony/icu should be asking for a minimum version, using a wildcard ( * ) in the version number, or specifying >= X .

So include in your key require :

"symfony/icu": "1.0.0" // ou 1.0.*
    
15.12.2013 / 02:11