Installing Symfony 3, Behat, and more

This video is available to view for members only.

Click here to Join!

Already a member?

Login


Before we get started, a word of caution: Symfony 3 is new. Many of the packages you will have absolutely no problems with in Symfony 2 may very well not work immediately in Symfony 3. The process of updating these packages is a work in progress (at the time of writing), so please - use Symfony 2.7 if you need long term support / don't need to be cutting edge.

Installing Symfony 3 is no different to installing Symfony 2. In this video, and in the real world, I strongly advise you to make use of the Symfony installer.

As mentioned in this video, the way I work tends to be without Vagrant / shared folders. This has the unfortunate side affect of not keeping your local code and the code on your server directly in sync. If you use an IDE like PHPStorm then one of these directions will be resolved for you - that is, local code changes can be automatically uploaded to your development server.

However, changes on the server side will not be pulled down by default. This is great in some respects - it means you won't end up with all the cached folder contents polluting your hard drive. But it will mean you need to manually pull down your composer.lock file, or log files, during development.

You may wish to work differently, that is your choice. I have used this way for a long time and have come to accept the limitations as acceptable when compared to the benefits I find this method provides.

Generally I find the easiest way is to install the Symfony installer on to the server, then run symfony new {project-name-here}, run a composer update, then use rsync to pull down the contents from the server to my local development machine.

If working in this way, be sure to update your local hosts file (/etc/hosts on mac / linux) to include an entry for your server, so you can access your site via hostname.

The rsync command would be :

cd /your/local/dev/directory
rsync -avzh your_user@your-server.dev:/var/www/your-project.dev .
mv your-project.dev/* .
rm -rf your-project.dev

Looks a bit weird. There's probably a better way of doing this (feel free to leave a comment).

To walk through it:

cd /your/local/dev/directory Change directory to a folder on your local machine where you want to store your code.

rsync -avzh your_user@your-server.dev:/var/www/your-project.dev . Copy the new symfony site data from the server to your current folder - BUT this will create a folder inside your current folder called your-project.dev. So...

mv your-project.dev/* . Move everything out of this nested subfolder, into your current directory, leaving this second directory empty, and then...

rm -rf your-project.dev Remove that left over folder.

Lastly, you will need to update your composer.json file with all the necessary dependencies.

Now, at this point we hit on a major issue with Symfony 3 - at the time of writing at least. There are a number of incompatible libraries / packages for Behat and Symfony 3.

So, here's the composer.json file for Symfony 2:

{
    "name": "your-name/your-project.dev",
    "license": "proprietary",
    "type": "project",
    "autoload": {
        "psr-4": {
            "": "src/"
        }
    },
    "require": {
        "php": ">=5.3.9",
        "symfony/symfony": "2.8.*",
        "doctrine/orm": "^2.4.8",
        "doctrine/doctrine-bundle": "~1.4",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~4.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "incenteev/composer-parameter-handler": "~2.0",

        "nelmio/cors-bundle": "~1.4",
        "nelmio/api-doc-bundle": "~2.9@dev",
        "friendsofsymfony/user-bundle": "2.*@dev",
        "lexik/jwt-authentication-bundle": "^1.3",
        "csa/guzzle-bundle": "^1.3",
        "friendsofsymfony/rest-bundle": "^1.7",
        "jms/serializer-bundle": "^1.0",
        "oneup/flysystem-bundle": "^1.2"
    },
    "require-dev": {
        "sensio/generator-bundle": "~2.3",
        "behat/behat": "~3.0",
        "behat/symfony2-extension": "~2.0",
        "behat/mink": "~1.5",
        "behat/mink-extension": "~2.0",
        "behat/mink-browserkit-driver": "~1.1",
        "behat/web-api-extension": "~1.0@dev",
        "behatch/contexts": "dev-master",
        "phpspec/phpspec": "~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",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "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",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        }
    }
}

And a similar one for Symfony 3:

{
    "name": "your-name/your-project.dev",
    "license": "proprietary",
    "type": "project",
    "autoload": {
        "psr-4": {
            "": "src/"
        },
        "classmap": [
            "app/AppKernel.php",
            "app/AppCache.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "require": {
        "php": ">=5.5.9",
        "symfony/symfony": "3.0.*",
        "doctrine/orm": "^2.5",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/doctrine-cache-bundle": "^1.2",
        "symfony/swiftmailer-bundle": "^2.3",
        "symfony/monolog-bundle": "^2.8",
        "sensio/distribution-bundle": "^5.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "incenteev/composer-parameter-handler": "^2.0",

        "nelmio/cors-bundle": "^1.4",
        "nelmio/api-doc-bundle": "^2.11",
        "friendsofsymfony/rest-bundle": "^1.7",
        "csa/guzzle-bundle": "^2.0",
        "jms/serializer-bundle": "^1.1",
        "oneup/flysystem-bundle": "^1.2",
        "friendsofsymfony/user-bundle": "dev-master",
        "lexik/jwt-authentication-bundle": "dev-master"
    },
    "require-dev": {
        "sensio/generator-bundle": "^3.0",
        "symfony/phpunit-bridge": "^2.7",

        "phpspec/phpspec": "^2.4",
        "behat/behat": "dev-master"
    },
    "minimum-stability": "dev",
    "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",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ],
        "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",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
        ]
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-bin-dir": "bin",
        "symfony-var-dir": "var",
        "symfony-web-dir": "web",
        "symfony-tests-dir": "tests",
        "symfony-assets-install": "relative",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        }
    }
}

It's largely the same, except for the require-dev section and the inclusion of the "minimum-stability": "dev", option inside the Symfony 3 composer.json file.

I needed to lower the minimum stability to get access to the Symfony 3 compatible branches.

And lacking the Behat libraries is a big issue, which will hopefully be resolved asap. It's not going to stop us writing our features though, which is exactly what we are going to do next.


Code For This Course

Get the code for this course.

Share This Episode

If you have found this video helpful, please consider sharing. I really appreciate it.


Episodes in this series

# Title Duration
1 Project Introduction 17:13
2 Setting Up Our Development Environment 05:08
3 Installing Symfony 3, Behat, and more 13:53
4 User Feature - Part 1 17:47
5 User Feature - Part 2 07:51
6 Talking English To Your Computer 11:05
7 Teaching Your Database To Forget 07:42
8 Creating User Data From Behat Background - Part 1 14:44
9 Creating User Data From Behat Background - Part 2 11:33
10 Creating A Custom RestApiContext 17:44
11 Our First Passing Behat User Scenario 12:01
12 Our Next Passing Step 13:10
13 Securing Our User Endpoint - Part 1 17:17
14 Securing Our User Endpoint - Part 2 24:27
15 Securing Our User Endpoint - Part 3 24:47
16 Log In To A Symfony API With JWTs (LexikJWTAuthenticationBundle) 11:02
17 Implementing PATCH for Users 18:17
18 Improving our API User Experience 13:59
19 GET a Collection of Accounts 12:15
20 POSTing in New Accounts 14:34
21 PUT and PATCH for Accounts 12:14
22 How To DELETE Existing Accounts 05:11
23 File Feature Overview 11:40
24 File - Using Existing Resources as Boilerplate 15:17
25 File POST 14:53
26 Fixing A Bug In POST Guided By Behat 12:50
27 Wrapping Up With File DELETE 07:47