Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine
This tutorial has a new version, check it out!

PHPUnit: Secure the Park

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

Let me paint you a scary picture:

It's Friday night. It's stormy. The office is empty and you're deploying fresh code straight to production. Suddenly, an alarm! What? The fences are down!? The dinosaurs are escaping!? Somehow, your beautiful code contained a bug. And as the raptors surround you, one thought keeps coming back: if only you had written tests.

I hate bugs, I hate fixing emergencies on production, and I especially hate being eaten by raptors.

It's time to go pro with coding... and that means, learning to test! And not just because we hate running from dinosaurs. We want to write code that is thoughtfully-designed and have the ability to add new features with confidence.

Hello Dinosaur Park

To make this dream come alive, you should totally code along with me. Download the course code from this page. After unzipping the file and turning the fences back on, you should find a start/ directory that has the same code you see here. Open up the README.md file for setup instructions and directions on how to catch the last boat off the island before the storm.

The last step is to find a terminal, move into your project, and run:

./bin/console server:run

to start the built-in PHP web server. In your browser, go to http://localhost:8000 to find... well... nothing! Just, "Welcome to Dinosaur Park". Instead of creating a park full of dinosaurs and then worrying about security... ahem... we don't have any code yet. We're going to build this dino factory and write tests all at the same time.

Installing PHPUnit

The de facto standard tool for testing in PHP is PHPUnit. Open a new terminal tab. Install it with:

composer require --dev "phpunit/phpunit:^6.5"

This will obviously download the PHPUnit library into your vendor/ directory. But mostly, you will interact with PHPUnit as an executable. When this finishes, you can now run:

./vendor/bin/phpunit

Hi PHPUnit! And hello Sebastian Bergmann and other contributors! There are no tests yet but I already feel like we're making friends.

Write some Tests

Let's write our first test. But, uh, don't worry about what we're testing yet - let's just experiment a little.

Create a tests/ directory and inside, another AppBundle/Entity directory. We'll talk about this structure soon, but first we have dinosaurs to contain!

Add a new PHP class: DinosaurTest, and give it a namespace: Tests\AppBundle\Entity. Make sure you extend a class: TestCase from PHPUnit.

... lines 1 - 2
namespace Tests\AppBundle\Entity;
... line 4
use PHPUnit\Framework\TestCase;
... line 6
class DinosaurTest extends TestCase
{
... lines 9 - 12
}

To actually make a test, create a public function called testThatYourComputerWorks. We're giving it that name because, inside, we're going to say $this->assertTrue(false).

... lines 1 - 6
class DinosaurTest extends TestCase
{
public function testThatYourComputerWorks()
{
$this->assertTrue(false);
}
}

If this test passes, you'll know to throw your computer out of the window and buy a new one. Let's find out. To run the tests, find your terminal, and re-run PHPUnit:

./vendor/bin/phpunit

Yes! It fails! My computer gets to live! It failed asserting that false is true on DinosaurTest line 11.

Test Rules & Best Practices

Ok, let's talk about the basic rules of writing a PHPUnit test. First, you can technically put your test classes anywhere... but.. you've gotta admit that tests/ is a pretty good place. Actually, in a Symfony project, you automatically start with a phpunit.xml.dist file. Well, in Symfony 4, this is added when you install phpunit. We'll talk more about this file later... but PHPUnit reads this automatically. And... check it out! It says that our tests all live in... tests/. That's how PHPUnit is able to find our DinosaurTest.

Second, our test has a namespace... but that's not really important. In a Symfony project, your composer.json file has an autoload-dev section that basically says that anything in tests/ should start with the namespace Tests. No big deal.

Let's get to the really important stuff, because PHPUnit does have a few crucial rules. First, your test class must extend TestCase and end in the word Test. Second, all of your test methods must be public and start with the word test. When you run PHPUnit, it basically looks for all classes ending in Test and all public functions inside starting with test.

Got it? Good... because the storm is coming, and we've got work to do. Delete the fake test. Let's start coding.

Leave a comment!

66
Login or Register to join the conversation

Loved the "Jurassic Park" reference!
- It's a Unix system!

3 Reply
Carlos Avatar

Hey!! What's the magic with "use PHPUnit\Framework\TestCase;" ?? Because I can find it anywhere, and even PHPStorm doesnt. But the tests work with vendor/bin/simple-phpunit.

1 Reply

Just adding this, if someone else is having same issues :-) Try running the recommended command as the FIRST thing after composer require: php bin/phpunit -> Installs the required phpunit as mentioned and phpStorm is happy again ;-)

Reply

Hey Mark,

Thanks for pointing this one more time! :) Yes, first run of "bin/phpunit" will install PHPUnit into "bin/.phpunit/" hidden directory. All the next runs will just use that source code. That's done by design, Symfony's PHPUnit Bridge installs PHPUnit into a "bin/.phpunit/", NOT into vendor/, that's why you don't see those classes after Composer commands.

Cheers!

Reply

Hey Carlos

It's not magic, you should find that file inside vendor/phpunit/phpunit/src/Framework/TestCase.php

Probably the file location depends on your PHPUnit version but if you are on version 7 (or maybe even version 6) you should find it right there.

Cheers!

Reply
Carlos Avatar

But Diego, it isnt there. The only required package is the "symfony/phpunit-bridge": "^4.2". And in the composer.json of phpunit-bridge we see:

"conflict": {
"phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0"
},

My vendor folder only contains this:

autoload.php
/bin
/composer
/guzzlehttp
/psr
/ralouphie
/symfony

I think that the "magic" is done with the phpunit inside the bin folder: ./bin/.phpunit/phpunit-6.5. But I can't figure it out how the autoload finds the classes inside this folder.

Thanks

Reply

Hey Carlos!

You're using symfony/phpunit-bridge, which indeed does things a bit differently :). Instead of downloading phpunit into your vendor directory (and all its dependencies), it creates a separate composer.json file and downloads phpunit and all its dependencies into its own isolated directory. The short explanation for why this is, is that it avoids dependency issues between the version of libraries that your app requires and the version that PHPUnit requires. And you were already looking in the right place, there's a script that literally downloads PHPUnit and its dependencies into, in your example, bin/.phpunit/phpunit-6.5. That vendor/ directory is autoloaded, as well as your normal vendor dir. It's definitely some magic, but the point is to work around a few version dependency issues.

Cheers!

1 Reply
Maki V. Avatar
Maki V. Avatar Maki V. | posted 4 years ago

Another good example why creating tests during your development process (quite a different one than getting eaten by a Dino :)) is when you are developing a new technology you are not familiar with, and instead of writing a testing environemt (a class or function that does everything you need), you can write the UnitTests or the FunctionalTests which would test each and every aspect of your new logic.

What is so good about this approach?
- Well, it helps you think on the most elementary level - what your logic REALLY needs and not getting tangled inside a labyrinth.

All of this approach expects that you write tests before you write your logic. Now, I myself consider more comfortable to image and think about every aspect of my application before I start coding it and consider it good practise - It's up to you (YOU THE READER) which approach is more comfortable for you.
You hold the reins of your universe in your own hands, mate :)

1 Reply

<3 this so much! What a great example of a way that tests help you that you don't realize until you really dive into them.

1 Reply
Marko Avatar

Hi!

When I do : composer require --dev "phpunit/phpunit:^6.5" (or : composer require --dev phpunit/phpunit), I get the following error :

In Process.php line 143:
[TypeError]
Argument 1 passed to Symfony\Component\Process\Process::__construct() must be of the type array, string given, called in D:\code-phpunit\start\vendor\sensio\distribution-bundle\Composer\ScriptHandler.php on line 310

Did someone have the same exception ? How to solve it ?

Thanks.

Reply
Marko Avatar
Marko Avatar Marko | Marko | posted 2 months ago | edited

P.S.

Same error when I do composer install.

I am using php 7.3.9

Reply

Hey Marko,

Hm, did you download the course code and started from the start/ directory? Or do you follow this course on your personal project?

It seems like "composer update" might help with this error, but it may require more work from you to get the project working after this upgrade. But probably worth to try first.

Cheers!

Cheers!

Reply
Marko Avatar
Marko Avatar Marko | victor | posted 2 months ago | edited

Hi Victor! Thanks for your answer! Yes, I downloaded the course code and started from the start directory. I have tried "composer update", but I am getting the same error...I have also tried to find a solution on google but no success for the moment...

Reply

Hey @Marko!

Sorry about the troubles - that's not the experience we want! The problem is simply that this tutorial is old. Most of the concepts still apply fine, but the code itself is pretty ancient. But, I can tell you two things:

A) We're currently recording and update for this tutorial. That won't help you right this second - but it's coming!
B) The error you're getting us coming from an old bundle that, for some reason, isn't playing nice with your dependencies. I don't know what that's happening - but it's somehow related to... just the code being old. The library is https://packagist.org/packages/sensio/distribution-bundle which is now abandoned. And you shouldn't even need it. Try running composer remove sensio/distribution-bundle and see if that fixes things.

Cheers!

Reply
Marko Avatar
Marko Avatar Marko | weaverryan | posted 2 months ago | edited

Hi Ryan! Thanks a lot for your answer! I have run : composer remove sensio/distribution-bundle . After that, when I do composer install I am getting the following error : PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "SensioDistributionBundle" from namespace "Sensio\Bundle\DistributionBundle". Did you forget a "use" statement for another namespace? in D:\code-phpunit\start\app\AppKernel.php:24 . So I have commented out the line : $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); in AppKernel.php file. composer install runs fine now but after running php bin/console doctrine:database:create, I am now getting : [Symfony\Component\Console\Exception\LogicException] An option named "connection" already exists. If I add : --force at the end, the same error appears.

Reply

Hey Marko, I believe if you upgrade the DoctrineBundle library, the error will go away. I'd also suggest removing your vendor directory entirely and clearing the cache manually rm -rf var/cache

Reply
Marko Avatar
Marko Avatar Marko | MolloKhan | posted 2 months ago | edited

Hi MolloKhan. Thanks a lot for your answer. I have done all that you suggest but I am still getting the same error after I do php bin/console doctrine:database:create. So the error is : [Symfony\Component\Console\Exception\LogicException] An option named "connection" already exists.

Reply

Hey @Marko!

Apparently this is due to some bug between doctrine/doctrine-bundle and doctrine/dbal. I'm reading that upgrading to doctrine/doctrine-bundle 1.12 would fix it.

To do that (I just did it locally), you should:

A) In composer.json, update the symfony/symfony requirement to 3.4.*
B) Run composer update

That will, among other libraries, update doctrine-bundle to a version without the bug. I can't promise things will work - the code is still very old - but that at least gets beyond this error. Though, I'm not hitting another error using PHP 8.1.

Error: During inheritance of ArrayAccess: Uncaught Error: Class "Symfony\Component\VarDumper
\Cloner\Data

But, this error doesn't happen if I use php 7.4 :).

Cheers!

1 Reply
Marko Avatar
Marko Avatar Marko | weaverryan | posted 2 months ago | edited

Hi Ryan! Thanks again for your help, and with these changes it works! And after using php 7.4.13 to avoid the error you have mentioned, I had to revert to php 7.3.9 to continue the tutorial. So it is necessary to 'juggle' with php versions to avoid bugs :)

Reply

Yay! Thanks for the update that you got it working and how. We'll have an update soon - these old tutorials are a pain for old PHP versions :).

Cheers!

Reply
Default user avatar
Default user avatar Pascal Breitrück | posted 1 year ago

Hey Symfonycasts team is a dinosaur testing update planned here at some point ??? 😁✌️

Reply

Hi Pascal Breitrück!

That is a good question. Yeah we do have some plans about it, but sorry can't say any exact information. =)

Stay tuned!

Reply
Sven W. Avatar
Sven W. Avatar Sven W. | posted 1 year ago

Hi,

I've installed PHP unit bridge with `composer require symfony/phpunit-bridge --dev` but when I run `./vendor/bin/simple-phpunit` it results in "No tests executed". I didn't change phpunit.xml.dist and I've made sure my class ends with Test and the method is public and starts with test:


// tests/AppBundle/Entity/DinosaurTest.php
namespace Tests\AppBundle\Entity;

use PHPUnit\Framework\TestCase;

class DinosaurTest extends TestCase
{
public function testThatYourComputerWorks()
{
$this->assertTrue(false);
}
}

What am I doing wrong?

Edit: when I add tests/ as the first (and only) argument to `./vendor/bin/simple-phpunit` it does find my tests. But I'm confused as to why.

Reply
CloudCreators Avatar
CloudCreators Avatar CloudCreators | Sven W. | posted 1 year ago | edited

I ran into the same problem and was stuck yeah it works when you add tests/ as first argument idk why? Sven W. can you tell why?

Reply

Hey CloudCreators

There may be many reasons. I recommend you to execute your tests via php bin/phpunit, that file comes with the recipe when you install the Symfony PHPUnit Bridge component. Can you give it a try and check if the problem goes away?

Cheers!

Reply

Hey Sven W.

What Symfony version are you using. On Symfony 5 you run your tests by running bin/phpunit
Can you double-check that your phpunit.xml file has this config? (It just define the test directory path)


<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

Cheers!

Reply
Sven W. Avatar

Hi Diego, I’m using Symfony 3 and I can confirm the definition of the test suite, though it’s in phpunit.xml.dist. (I’ve downloaded the project code from this series.). I’ll double check tomorrow evening to see if creating a copy and renaming it to phpunit.xml (without .dist) makes any difference

Reply

Oh, you're on Symfony 3, things may work a bit different on that version. What PHPUnit version are you using? Please give it a try with a non dist phpunit.xml file, it may fix the problem

Reply
Sven W. Avatar

I'm not on a real project, just using Symfony 3 because that's the code shared for this (a bit older tutorial). Using a non-dist phpunit.xml didn't solve the issue. And I have symfony/phpunit-bridge:5.3.3 installed. It's not that much of an issue to use tests with the command. Just trying to understand what I'm doing wrong :)

Reply

Yea... this tutorial it's using an old version of Symfony (Although, the concepts taught here are still relevant) we're planning in upgrading it. I think the problem is you're using phpunit-bridge 5.3 version. You should be using version 3 instead

Cheers!

Reply
Kajetan Avatar
Kajetan Avatar Kajetan | posted 1 year ago

Hi!
I'm very exited for this tutorial series but I'm having
some problems with initial setup (and from what I can see many people do
too).
I'm not super proficient in creating contained local development environments or with using docker.
I was wondering if maybe you could add docker-compose file to the course code zip file
so that anyone interested in coding along could just spin up a container for this course without worrying about PHP versions,

setting up DB and any other problems that can come up from just the differences in their local env.
From
what i gather you wouldn't have to change any files or the file
structure so it would still be the same as in the videos, you'd just
extend the readme ;)
At the same time somebody learning docker
could learn about it by looking at docker-compose file, how it
structured, what containers need to be created, how they are connected,
etc...

Reply

Hi @Kajetan!

Sorry for my slow reply - but thanks for the message!

> but I'm having some problems with initial setup (and from what I can see many people do too).

That's no fun :/ - sorry about that! If you have some specific errors, we could totally help debug. But, I think your next point is valid ;)

> I was wondering if maybe you could add docker-compose file to the course code zip file
> so that anyone interested in coding along could just spin up a container for this course without worrying about PHP versions,

We've been getting this feedback more and more, and I totally agree. We're building some systems in internally to test the course code itself. When we have that, one of the things we'd like to do is generate docker-compose files for the code download and also generate the README. We could create the docker-compose right now - but we want it to be validated by a testing system so that we know it works... and works for all the tutorials we provide it on.

So, yes! This is something we're actively pushing towards. It's especially challenging, I realize, when we might have one tutorial that requires PHP 7.4, then an older tutorial that only works on PHP 7.1-7.3. Docker would fix that.

Cheers!

Reply
Pradeep R. Avatar
Pradeep R. Avatar Pradeep R. | posted 1 year ago

Hello I have similar issue which was faced by Boris Rieunier

when i run the command: composer update

I get the problem on this file

Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:
[Symfony\Component\Console\Exception\LogicException]
An option named "connection" already exists.

I am trying to set up on PHP 7.2.34

Please guide me on the same.

How do I complete my setup.

PS: I have downloaded the course code and I run composer update on the same.

Reply

Hey Pradeep,

I see this course project should work on your PHP version that is 7.2 and that's a good sing. Also, I see that after you downloaded the course code, you ran "composer update" command, but if you would open the README file - you will see that you have to run "composer install" command instead. Please, download the course code again, unzip it, go to start/ directory and follow the steps from the README file there. It means, that instead of "composer update" you will need to run "composer install" that will install the deps locked in composer.lock file.

Let us know if you still see that error even when you run "composer install"

Cheers!

Reply
Boris R. Avatar
Boris R. Avatar Boris R. | posted 1 year ago

Hello,

Trying to setup the project I have this error on composer install :

[Symfony\Component\Console\Exception\LogicException]
An option named "connection" already exists.

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event termi
nated with an exception

[RuntimeException]
An error occurred when executing the ""cache:clear --no-warmup"" command:

[Symfony\Component\Console\Exception\LogicException]
An option named "connection" already exists.

Php version is 7.3.21
My Symfony Version is Symfony CLI version v4.23.5 (2021-04-07T05:30:32+0000 - stable)

I ran a composer update, same issue in the end.

I changed the composer.json so that it could be compatible with my current php version. I am to downgrade my php version for it to work ? If so to wich version ? Thanks !

Reply

Hey Boris R.!

Ah, sorry about the troubles! This tutorial (while the contents are still great) is getting a bit old: it's compatible with PHP 7.0-7.3 only (we show that when you hover over the course download link). If a tutorial doesn't support newer versions of PHP it's because, unfortunately, we've determined that we can't upgrade the dependencies to support the newer PHP version without altering the code in some drastic way (where the code in the download would stop looking like the code in the video).

If you want to code along, the easiest path is to use an old version of PHP - v7.3. This tutorial is on our radar to update :).

Cheers!

Reply
Paul Avatar

Hi there, love your tutorials. Ubuntu 20.04 comes bundled with PHP v7.4, which is not compatible with this project's dependencies. What is the best way to get the project going in that environment ?

I realize I could use Docker, or better Docker Compose, but I am not sufficiently proficient to set up that solution quickly.

Reply
MolloKhan Avatar MolloKhan | SFCASTS | Paul | posted 1 year ago | edited

Hey Paul

Unfortunately, the only way right now it's to downgrade to PHP 7.3 or lower. But, if you're on Ubuntu it should be easy to do so by using update-alternatives. You can see here how to do it https://stackoverflow.com/a...

Cheers!

1 Reply
Angela F. Avatar
Angela F. Avatar Angela F. | posted 2 years ago

Hi, I am trying to set up this project on a PC running windows 10. I am getting an error when trying to install the phpunit package or when trying to run php bin/console cache:clear

See the exact error below:

Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache


[Symfony\Component\Console\Exception\LogicException]
An option named "connection" already exists.


Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception


[RuntimeException]
An error occurred when executing the ""cache:clear --no-warmup"" command:





[Symfony\Component\Console\Exception\LogicException]
An option named "connection" already exists.

This is the parameters.yml file
# This file is auto-generated during the composer install
parameters:
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password: password
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: ThisTokenIsNotSoSecretChangeIt

and the config.yml file
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en

framework:
#esi: ~
#translator: { fallbacks: ['%locale%'] }
secret: '%secret%'
router:
resource: '%kernel.project_dir%/app/config/routing.yml'
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: '%locale%'
trusted_hosts: ~
session:
# https://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true

# Twig Configuration
twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'

# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite'
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: '%database_path%'

orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }

Reply

Hey there,

That's and odd error to me. Can you tell me which Symfony version are you using and what database engine?

BTW, try upgrading your composer dependencies, it may help composer upgrade

Cheers!

Reply
Angela F. Avatar

That issue was resolved with upgrading the memory limit size and using an older version of phpunit but now that I ran composer upgrade phpunit version that is installed is 7.5.

"require-dev": {
"phpunit/phpunit": "^7.5",

The error I get when I try running phpunit commands and I've tried a few different ones is

C:\Users\username\Documents\phpunit>phpunit --version
Could not open input file: C:\Users\username\Documents\phpunit\phpunit.phar

If I try to run the ./vendor/bin/phpunit command I get

'.' is not recognized as an internal or external command,
operable program or batch file.

I have a phpunit.cmd file that contains

echo @php "%~dp0phpunit.phar" %* > phpunit.cmd

A bit at a loss here...again this is a Windows 10 pc. If anyone was able to get this to work on their machine I would appreciate the help!

Reply

Hey, are you using Symfony's PHPUnit brigde? Check inside your directory bin/ for the executable phpunit. If that's the case you can run PHPUnit through it php bin/phpunit
Give it a try and let me know what happened

You can read more about the bridge here https://symfony.com/doc/cur...

Reply
Liviu M. Avatar
Liviu M. Avatar Liviu M. | posted 2 years ago

I'm having some issues with composer install. the composer lock file from the downloaded code sais i need ocramius 1.7 which requires php ^7.4... what gives?

Reply

Hey Liviu M.!

That is 100% our bad! We recently upgraded dependencies on some tutorial to make sure that they *could* work on php 7.4. For a small number of tutorials, we were missing some config, and we accidentally upgraded the dependencies so that they *required* PHP 7.4. We're going to fix that :p. At the moment, you should be able run composer update to fix this - but we're going to fix the code download ASAP.

Thanks for the comment!

Reply

Would be very nice to include what PHP version (and when applicable what node version) you are using on a project for all the courses. I don't have PHP installed on my pc so I'm using Docker, I had to rebuild my entire container 4 times before getting a PHP version that match all packages requirements.

Reply

Hey julien_bonnier

We are very sorry that you got stuck with configurations and spent a lot of time to get all working. We are now developing a feature that will show package versions for each course and some requirements but it will be great to hear what issues have you faced? You mentioned that problem was in PHP version and package requirements can you describe some of them? Because our courses doesn't have strict requirements about PHP and it's packages.

Cheers!

Reply
Amit Avatar

Hi - I just started watching the tutorial and was trying to setup the project. I was getting error saying that annotation were not enabled and null is being passed from routing.yml. This project is based on Symfony 3.4... but I had php 7.4 on my machine. Once I downgraded to php 7.2 it started working and now I can follow the tutorial. In case anyone is trying to follow the tutorial and get weird error on annotation like I did, try down grading to php 7.2.

Reply

Hey Amit!

Thanks for the note! I know this error - it IS indeed a problem with an older version of doctrine/annotations. We'll see if we can upgrade it in the course code :).

Cheers!

Reply
Oleksii V. Avatar
Oleksii V. Avatar Oleksii V. | posted 2 years ago

Hello,
I'm using code from "Download" button of this tutorial. When I try to execute command "composer require --dev phpunit/phpunit" I get "Updating dependencies (including require-dev)
PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///usr/local/Cellar/composer/1.9.2/bin/composer/src/Composer/DependencyResolver/Solver.php on line 223

So I can't install phpunit. I have only 16Gb RAM. Explain please, how can I install phpunit in your code. My php version 7.2 Thanx in advance.

Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

While the fundamentals of PHPUnit haven't changed, this tutorial *is* built on an older version of Symfony and PHPUnit.

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": "^7.0, <7.4",
        "composer/package-versions-deprecated": "^1.11", // 1.11.99
        "doctrine/doctrine-bundle": "^1.6", // 1.10.3
        "doctrine/orm": "^2.5", // v2.7.2
        "incenteev/composer-parameter-handler": "^2.0", // v2.1.2
        "sensio/distribution-bundle": "^5.0.19", // v5.0.21
        "sensio/framework-extra-bundle": "^3.0.2", // v3.0.28
        "symfony/monolog-bundle": "^3.1.0", // v3.1.2
        "symfony/polyfill-apcu": "^1.0", // v1.6.0
        "symfony/swiftmailer-bundle": "^2.3.10", // v2.6.7
        "symfony/symfony": "3.3.*", // v3.3.13
        "twig/twig": "^1.0||^2.0" // v2.4.4
    },
    "require-dev": {
        "doctrine/data-fixtures": "^1.3", // 1.3.3
        "doctrine/doctrine-fixtures-bundle": "^2.3", // v2.4.1
        "liip/functional-test-bundle": "^1.8", // 1.8.0
        "phpunit/phpunit": "^6.3", // 6.5.2
        "sensio/generator-bundle": "^3.0", // v3.1.6
        "symfony/phpunit-bridge": "^3.0" // v3.4.30
    }
}