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
Related
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
I am using the Symfony3 plugin in PhpStorm. My PHP Interpreter is 7.0.18. I have PHPUnit 6.3.0 configured in PhpStorm by having the .phar file in the root directory of my project.
Unit test work like a charm inside the IDE however performing any operation on the server (like bin/console server:start) triggers the following messages:
PHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found in
/1tb/programming/PhpstormProjects/binary_search/src/AppBundle/Search/BinarySearchTest.php on line 13
PHP Fatal error: Class 'PHPUnit\Framework\TestCase' not found in
/1tb/programming/PhpstormProjects/binary_search/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/TestCase.php
on line 17
BinarySearchTest.php:
<?php
namespace AppBundle\Search;
use PHPUnit\Framework\TestCase;
class BinarySearchTest extends TestCase
{
}
TestCase.php:
<?php
namespace Symfony\Bundle\FrameworkBundle\Tests;
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
class TestCase extends PHPUnitTestCase
{
}
I have read many posts with problems similar but none of them describe the problem the way I do. Then I tried running PHPUnit with phpunit . in the root directory of the folder with this error:
PHP Fatal error: Class 'Doctrine\Tests\Common\Cache\CacheTest' not
found in
/1tb/programming/PhpstormProjects/binary_search/vendor/doctrine/cache/tests/Doctrine/Tests/Common/Cache/ApcCacheTest.php
on line 10
It seems whatever I do I just run into more errors. I only just got started with Symfony and read a bit of the documentation but I can't get a grip on this thing, I have been at it for two days. Any suggestions for me?
I have PHPUnit 6.3.0 configured ... by having the .phar file in the root directory of my project
Such a bad idea. PHPUnit should not be installed on your (production?) server.
If this is a local staging server that you're trying to test on, then you need to install the phar in the path.
To globally install the PHAR:
$ wget https://phar.phpunit.de/phpunit-6.2.phar
$ chmod +x phpunit-6.2.phar
$ sudo mv phpunit-6.2.phar /usr/local/bin/phpunit
$ phpunit --version
Also, consider upgrading PHP to the newest version. There are several vulnerabilities in the one you're using. (See: change log for versions between yours and current).
EDIT:
Why are you running bin/console server:start on your server? Also not meant to be on a production server.
My guess here is that it is seeing the phar in your document root and trying to execute it, which is what is causing all the errors.
Installation of PHPUnit via composer worked. It turns out my composer installation went wrong in some way. After composer was successfully installed, I let it handle installing PHPUnit. After that it just worked. Tests work fine in the IDE and the server is responsive again. Thanks LazyOne.
After uploading my symfony2 project to the server, I try to reload :
http://my_website.com/web/app_dev.php and it show me this error :
Fatal error: Class 'Doctrine\Common\Annotations\AnnotationRegistry'
not found in /my_path/app/autoload.php on line 11
A missing class can indicate that the dependencies are missing. You have to install them with Composer:
composer install
And you can adjust options:
--prefer-dist: download zip files instead of using git repositories
-vvv --profile: display more verbose output
Which gives:
composer install --prefer-dist -vvv --profile
first of all I would like to say that I'm relatively new to symfony and I work with Netbeans.
My first problem occurs when I'm trying to install ccdn-forum-bundle like it's said here:
https://github.com/codeconsortium/CCDNForumForumBundle/blob/master/Resources/doc/install.md
When I try to update-dev with composer I get this error:
[RuntimeException]
Failed to execute git status --porcelain --untracked-files=no
"git" is not recognized as an internal or external command, operable program or batch file.
It occurs when composer is trying to update friendsofsymfony/user-bundle and when I try to run my project I get this error from symfony:
ClassNotFoundException: Attempted to load class "MonologBundle" from namespace "Symfony\Bundle\MonologBundle" in C:\xampp\htdocs\PortalInternoHUPR\app\AppKernel.php line 14. Do you need to "use" it from another namespace?
I tryed to fix it by running install dev in composer, but then I get this other one:
Fatal error: Class 'Knp\Bundle\PaginatorBundle\KnpPaginatorBundle' not found in C:\xampp\htdocs\MyProject\app\AppKernel.php on line 23
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception
[RuntimeException]
An error occurred when executing the ""cache:clear --no-warmup"" command.
Thanks.
Try not to use netbeans, and install the bundle directly from the prompt
First check if git is correctly installed
git –version
Then run
php composer.phar update
If that didn’t work for you, I suggest making a fresh install using --prefer-dist option
php composer.phar install --prefer-dist
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