Symfony 5 Phpunit undefined method - symfony

I'm working with Symfony 5 and I installed phpunit-bridge with the command included in the documentation : composer require --dev symfony/phpunit-bridge.
When I run phpunit with this command, php bin/phpunit, I have this error :
PHP Fatal error : Uncaught Error: Call to undefined method
PHPUnit\TextUI\TestRunner::doRun()

I'll try to guess.
You also have a bundle like liip/functional-test-bundle or other, which require PHPUnit in requirements (or even you require PHPUnit directly in your composer.json together with phpunit-bridge).
As a result you have two different version of PHPUnit installed in project, with two different api.
If installed liip/functional-test-bundle is your case and you do not want to remove it, you need to install by bridge same PHPUnit version as installed by Liip bundle dependency. You can set version through SYMFONY_PHPUNIT_VERSION env variable or directly in bin/phpunit file. Or you can redefine path to already installed PHPUnit version (in vendors/) through SYMFONY_PHPUNIT_DIR env or directly in bin/phpunit.
Note: you can not set SYMFONY_PHPUNIT_VERSION or SYMFONY_PHPUNIT_DIR through .env.* files, since bin/phpunit not read this files. So it should be real env vars.

I had a similar issue with symfony 5.1. I tried upgrading all dev packages related to testing but it didn't work.
Once I completely remove all dev (testing related) packages and reinstalling the symfony phpunit bridge package it worked.
You have to remove the phpunit file inside the root/bin directory
Steps to follow
Remove all dev test packages (Eg: composer remove symfony/browser-kit)
Remove if there are following packages : phpunit/phpunit, symfony/phpunit-bridge, symfony/css-selector, symfony/browser-kit
Install the brdge package again by running composer require --dev symfony/phpunit-bridge

Related

How to run symfony cli command with --webapp using local composer.phar?

I run different versions of Symfony and PHP on my Mac for various apps I have to work on (sorry that our clients are so slow to get to upgrade), and I'm trying to install the LTS version of Symfony through the CLI documentation recommendations, but I'm trying to get it to use a composer.phar in the folder I run the command in... it keeps defaulting to the globally-installed one.
Sure I could just go change composer's execution path or upgrade/downgrade it temporarily whenever I want to run the cli for x version of PHP, but that's gonna drive me crazy and I'd rather see how to tell it to run a certain composer.phar file. I'm not seeing in the documentation how to do this to get the benefits of the --webapp option.
The documentation is weird on it anyway; I can't tell if running composer directly (as composer.phar) will give me the benefits of the --webapp option using the symfony command (because the composer commands are identical for 'traditional web application' and 'console application or API'):
https://symfony.com/doc/5.4/setup.html#creating-symfony-applications
# run this if you are building a traditional web application
$ symfony new my_project_directory --version=5.4 --webapp
# run this if you are building a microservice, console application or API
$ symfony new my_project_directory --version=5.4
# run this if you are building a traditional web application
$ composer create-project symfony/skeleton:"^5.4" my_project_directory
$ cd my_project_directory
$ composer require webapp
# run this if you are building a microservice, console application or API
$ composer create-project symfony/skeleton:"^5.4" my_project_directory
When I run the install through composer directly, I can't tell if I'm getting the benefits of the symfony command --webapp option... and I'm not seeing an option for the symfony command to specify to use the folder's composer.phar.
I had to cheat a little bit: I installed the latest composer using the instructions here to a composer.phar file:
https://getcomposer.org/download/
I then created a console alias like php composer.phar, ran the Symfony create composer command with that alias, which created the symfony-5 folder no problem, then I copied the composer.phar file to the new folder and run the alias for any other composer commands, like with require webapp, which is working! Kind of nice to freeze a version of composer for any similar repos.
Maybe not the best answer, but it's working.
Also I discovered that I could just run composer self-update to get the latest version, which worked, then composer self-update [whatever version number] to get back to one I need that works with other repos (since certain version ranges just do not work with certain version ranges of PHP). Annoying, but functional.
Ultimately I think moving forward, it's best to make a copy of composer.phar at a compatible version range for your older PHP apps, depending on their versions, and use those in an alias, rather than totally rely on a global composer version, which has proven not completely workable for my work.

error when installing php unit

I'm working on an existing symfony project and need to use php unit.
When I tried to install it through composer with this command:
composer require --dev phpunit/phpunit ^5
But I got this error:
proc_open (): CreateProcess failed, error code -267
See screenshot here
If you refer to MS's error code reference, you'll see that error code 267 means that the directory name is invalid. So you've probably got an invalid directory reference in your configuration file.
Symfony has its own PHPunit bridge component that adds features on top of the library.
Install it by running this command at the root of your project:
composer require --dev symfony/phpunit-bridge
You should then be able to run your test scripts with:
./vendor/bin/simple-phpunit

PhpStorm with PHPUnit: PHP_CodeCoverage_Filter not found

I am trying to use PHPUnit in PhpStorm (on a Mac). Therefore I tried adding the pear path and phpunit path to the include path of PhpStorm (the ones I found through which pear on the command line) - it tells me that phpunit was not found.
I also tried to use PHPUnit with the custom autoloader generated by composer (the phpunit package is installed), I then receive another error:
Fatal error: Class 'PHP_CodeCoverage_Filter' not found
If I run phpunit on the console normally everything works:
phpunit --bootstrap vendor/autoload.php tests/*Test.php
What am I doing wrong?
The problem was that I used the default php interpreter which phpStorm suggested to me. This was version PHP 5.5 though and not the 5.6 version in my terminal.
After changing the interpreter to an up-to-date php version (5.6 or 7.0) it worked with the PHAR Option.

Installing phpunit - are the sebastian & symfony directories necessary?

When installing phpunit 4.0 using composer (in PHPStorm) I get ....
/phpunit
/sebastian
/symfony
Does anyone know why I get the 2nd two and if there are necessary in any way.
Thanks
these dependencies are necessary as you can see at the composer file of PHPUnit. Before Composer was around and they shipped the software only via PEAR, you need to install all the dependencies by your own. At the end nothing changed.
In case you are concerned about installing all these dependencies over and over again for every PHP project you need PHPUnit, you can install it globally on you system.
Add composer global require 'phpunit/phpunit=3.7.*' to your composer.json.
Yes, those two directories are necessary for PHPUnit to work.
The dependencies in the vendor folder are managed by composer for you, you don't need to worry here. The reason you have them is because you installed PHPUnit.
When you remove PHPUnit and those dependencies aren't required by any other package, they will be removed again.

Symfony 2.0 bundle installation

So I am a new to doctrine, but I am not able to install a bundle at all. I am following the guide, but the "error" which I am getting is very unusual.
Anyhow, I add this lines into deps file:
[FOSRestBundle]
git=http://github.com/FriendsOfSymfony/FOSRestBundle.git
target=bundles/FOS/RestBundle
Then I do:
./bin/vendors install
And I get:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/sqlite.so' - /usr/lib/php5/20090626+lfs/sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0
Your project seems to be based on a Standard Edition that includes vendors.
Try to run ./bin/vendors install --reinstall
So on this standard way I am not able to install it at all. Can somebody explain me what is the problem, because to me it looks like, the symfony vendors script doesnt recognize changes in deps file at all.
This happens when you've downloaded the Symfony2 Standard Edition from the website. The vendor install script checks to see if the vendor directories are git repositories, and if not, will throw this error. You can fix the situation in one of two ways:
you can either run the command that it suggests: php bin/vendors install --reinstall
or, you can remove the vendors directory, then run php bin/vendors install, which amounts to about the same thing
No need to install that. Just follow the steps in the url : http://mmoreramerino.github.com/GearmanBundle/installation.html

Resources