Skip to content

Instantly share code, notes, and snippets.

@wouterj
Created November 20, 2015 23:01
Show Gist options
  • Save wouterj/dcb43f67701639f8cd4c to your computer and use it in GitHub Desktop.
Save wouterj/dcb43f67701639f8cd4c to your computer and use it in GitHub Desktop.

How to Prepare Your Bundle for Symfony 3

Symfony 3 is a major version update of Symfony. This means that code working on Symfony 2 applications might not work on Symfony 3. In order to update your bundles for Symfony 3, you need to make sure that your bundle doesn't use any of the removed features without also using the replacement. This guide will teach you how to add Symfony 3 support to your bundle and it'll also give you some practical tips to support both Symfony 2 and 3.

1) Update the Composer Dependencies

As bundles are created for the Symfony framework, they almost always have some sort of dependency on a Symfony package (symfony/framework-bundle being the most commonly used dependency). The version constraints used for these packages should be updated to allow installing the bundle with Symfony 3. For instance, if your composer.json file contains something like this:

{
    "require": {
        "symfony/framework-bundle": "~2.3",
        "...": "..."
    }
}

Update it to something like this:

{
    "require": {
        "symfony/framework-bundle": "~2.3|~3.0",
        "...": "..."
    }
}

The new version constraint means that the bundle requires the symfony/framework-bundle package with a version that's either ~2.3 or ~3.0.

2) Test your Bundle against Symfony 3

Using Automated Tests

  1. composer require symfony/symfony "3.0.*@beta"
  2. (optionally) Use branch aliases composer require symfony/symfony "3.0.*@beta as 2.8.x-dev"
  3. Run tests

Tip

Use symfony/phpunit-bridge on Symfony 2.8 tests to find many deprecated features.

Travis

Testing inside a Symfony App

  1. symfony new sf3-testing 3.0
  2. Requiring the bundle
  3. (optionally) Use branch aliases 3.0.*@beta as 2.8.x-dev

3) Reading the Upgrade Guides

Tips and Tricks

Form Name Refactoring

OptionsResolver API Refactoring

Service Factory Refactoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment