PHP / Composer cannot redeclare - php

I was happily working away in my development environment and suddenly I started getting the following error:
PHP Fatal error: Cannot redeclare composerRequire7a368ac394ae1d2e857becf2a235ebaa() (previously declared in [APP_ROOT]/vendor/composer/autoload_real.php:56) in [APP_ROOT]/vendor/composer/autoload_real.php on line 59
I haven't made any changes to speak of in composer dependencies (although I think I did do a composer update somewhere in that timeframe but no changes to the dependencies/packages used so nothing big should have changed.
Notably, when I checkout the repo on my laptop I do NOT get this error but if I git clone a clean repo and then composer install on my main development machine I DO get this error. So I'm assuming it must have some machine-specific origin but I'm running out of ideas on what that might be.
Any help would be greatly appreciated.
Note: I'm running PHP 5.3.28 on OSX; my app uses namespacing and is PSR0 compliant
Also of note is that I'm running PHPUnit 4.0.17 and the error is triggered at the very first stages of trying to run a unit test (it doesn't matter WHICH unit test). Here's the stack trace:
0.0009 636648 1. {main}() [APP_BASE]/vendor/phpunit/phpunit/phpunit:0
0.0465 1423664 2. PHPUnit_TextUI_Command::main() [APP_BASE]/vendor/phpunit/phpunit/phpunit:54
0.0465 1424280 3. PHPUnit_TextUI_Command->run() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:132
0.0465 1424280 4. PHPUnit_TextUI_Command->handleArguments() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:141
0.0674 2123344 5. PHPUnit_TextUI_Command->handleBootstrap() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:638
0.0681 2139872 6. PHPUnit_Util_Fileloader::checkAndLoad() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:808
0.0681 2140008 7. PHPUnit_Util_Fileloader::load() [APP_BASE]/vendor/phpunit/phpunit/src/Util/Fileloader.php:77
0.0774 2144176 8. include_once('[APP_BASE]/tests/test-loader.php') [APP_BASE]/vendor/phpunit/phpunit/src/Util/Fileloader.php:93
0.0775 2146736 9. include('[APP_BASE]/vendor/autoload.php') [APP_BASE]/tests/test-loader.php:2

Delete composer.lock and vendor/ and run composer update again.

I had this problem when I made a copy of an existing project directory and tried to run phpunit on the new directory. Finally figured out that when I executed phpunit, it was running out of the old directory. I ran this:
which phpunit
And saw that it was running from my composer vendor directory:
/home/vagrant/Code/MYOLDPROJECT/api/vendor/bin/phpunit
I ran phpunit from the new directory and the problem disappeared:
/home/vagrant/Code/mynewproject/api/vendor/bin/phpunit

Related

Updated composer.json, now PHP autoload does not work. PHPUnit cannot find my classes

I am a user of the EWZSearchBundle and want to update it to work with Symfony 3.x
Updating the composer.json file should be easy, but I don't manage to get the unit tests running.
Here is the link to my fork of the bundle with some "improvements": link to commit
When I run the phpunit tests, I get the following error:
$ vendor/bin/phpunit Tests/Lucene/FieldTest.php
PHPUnit 5.7.26 by Sebastian Bergmann and contributors.
PHP Fatal error: Call to undefined method Zend\Search\Lucene\Document\Field::getType() in /tmp/azine/EWZSearchBundle/Tests/Lucene/FieldTest.php on line 18
PHP Stack trace:
PHP 1. {main}() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/phpunit:52
PHP 3. PHPUnit_TextUI_Command->run() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/TextUI/Command.php:116
PHP 4. PHPUnit_TextUI_TestRunner->doRun() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/TextUI/Command.php:186
PHP 5. PHPUnit_Framework_TestSuite->run() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:517
PHP 6. PHPUnit_Framework_TestCase->run() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/Framework/TestSuite.php:733
PHP 7. PHPUnit_Framework_TestResult->run() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/Framework/TestCase.php:868
PHP 8. PHPUnit_Framework_TestCase->runBare() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/Framework/TestResult.php:686
PHP 9. PHPUnit_Framework_TestCase->runTest() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/Framework/TestCase.php:913
PHP 10. ReflectionMethod->invokeArgs() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/Framework/TestCase.php:1062
PHP 11. EWZ\Bundle\SearchBundle\Tests\Lucene\FieldTest->testGetType() /tmp/azine/EWZSearchBundle/vendor/phpunit/phpunit/src/Framework/TestCase.php:1062
Steps to reproduce:
$ git clone git#github.com:azine/EWZSearchBundle.git
$ cd EWZSearchBundle
$ composer install
$ vendor/bin/phpunit Tests/Lucene/FieldTest.php
The cause of this error is, that the EWZ\Bundle\SearchBundle\Lucene\Field class is not (properly) autoloaded, but the Zend\Search\Lucene\Document\Field from the vendor directory is autoloaded but doesn't have that method.
Can anyone tell me why the autoloading of the classes in the namespace EWZ\Bundle\SearchBundle from the root directory does not work?
All help is highly appreciated.
The class is properly autoloaded. The problem is with the code itself.
When you're initiating a $binaryField by code
$binaryField = Field::Binary('Binary', 'value');
the result is of class \Zend\Search\Lucene\Document\Field, not of \EWZ\Bundle\SearchBundle\Lucene\Field.
Because it executes
return new self($name, $value, '', true, false, false, true);
inside of \Zend\Search\Lucene\Document\Field, and this runs a constructor of \Zend\Search\Lucene\Document\Field, not your extended class.

Deployer - Fatal error: Call to undefined function server()

Deployer version 4.1.0
When running dep deploy test the following error is reported:
PHP Fatal error: Call to undefined function server()
server ftn is defined as follows in config file:
// Configure servers
server('test', 'test.server.com')
->user('user')
->identityFile('~/.ssh/id.pub', '~/.ssh/user', 'password')
->stage("test")
->env('deploy_path', '/var/www/project.com');
This is pretty much the standard as per the Deployer site. Has anyone else experienced this issue? If so how did you resolve it?
SOLUTION
Fixed issue by running the following cmd (Suggested in comments above by Ken)
dep init
Compared the auto-generated deploy.php file to the original. Noted that the following was omitted:
namespace Deployer;
Also noted that ->env has been replaced with ->set
I had the same problem using deployer on a Laravel 5.4 project:
I had installed deployer using composer, when removed it and worked with deployer.pharfile , everything worked fine.

Symfony is suddenly failing with "The service "session.storage.metadata_bag" has a dependency on a non-existent parameter"

I upgraded from Symfony 3.1.5 to 3.2.0 yesterday morning and everything was fine up until an hour or so ago.
Now Symfony throws the following exception upon any type of access, including console commands:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
The service "session.storage.metadata_bag" has a dependency on a
non-existent parameter "session.metadata.storage_key".
I have tried the following:
Backed out my most recent changes
Deleted var/cache/*
Here is the exception trace:
Exception trace:
() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:100
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->get() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php:56
Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag->get() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:217
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveString() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:187
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveValue() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:177
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveValue() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php:39
Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass->process() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:120
Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:565
Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:484
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:116
Symfony\Component\HttpKernel\Kernel->boot() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:68
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:122
Symfony\Component\Console\Application->run() at /Volumes/Data01/Projects/Beck/WWUI/site/bin/console:29
As you can see, it's part of Symfony, and not my code.
I am at a loss.
Has anybody else seen this?
Suggestions?
Edit 1:
Based on Dagon's suggestion that I check session.xml, and seeing that it appears correct, I decided to replace the
<argument>%session.metadata.storage_key%</argument>
tag with
<argument>_sf2_meta</argument>
in session.xml. This resulted in a new, similar error:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
The service
"64e3c91c625381e3c2c0184cf9ea0c6d5353986d77aa111949ca6fb8b17a8f07_2"
has a dependency on a non-existent parameter "validator.mapping.
cache.prefix".
This isn't really an answer per-se, but is is a fix.
I renamed vendor to vendor-HOLD and then ran composer install. Problem gone.
I did a diff on the old and new session.xml files and found that the definition of the parameter was different. The version causing the error contained:
<parameter string="session.metadata.storage_key">_sf2_meta</parameter>
The newly installed version contained:
<parameter key="session.metadata.storage_key">_sf2_meta</parameter>
instead. Obviously other files were incorrect, as well, based on the experimental edit I did to session.xml. No clue as to what happened, but it's nice that composer install fixed it. Oh, and yes, I deleted vendor-HOLD afterwards.

phpStorm : wrong path returned by realpath function

I am using symfony and phpunit for my tests.
I had a project in foodmeup.dev directory which I copied into foodmeupnew.dev
Now, when making a call to phpunit from phpStorm command line, I've got something strange with the autoload file being looked for in the previous folder.
See the following, at line 8 it's changing dir from foodmeupnew.dev to foodmeup.dev, how can I correct this ?
> D:\Divers\Programmation\Web\foodmeupnew.dev\bin\phpunit.bat -c app
Fatal error: Cannot redeclare getLadybug() (previously declared in D:\Divers\Programmation\Web\foodmeupnew.dev\vendor\raulfraile\ladybug-themes\Ladybug\Plugin\Extra\Resources\php\helpers.php:12) in D:\Divers\Programmation\Web\foodmeup.dev\vendor\raulfraile\ladybug-themes\Ladybug\Plugin\Extra\Resources\php\helpers.php on line 21
Call Stack:
0.0002 234304 1. {main}() D:\Divers\Programmation\Web\foodmeupnew.dev\vendor\phpunit\phpunit\phpunit:0
0.0088 1457264 2. PHPUnit_TextUI_Command::main() D:\Divers\Programmation\Web\foodmeupnew.dev\vendor\phpunit\phpunit\phpunit:36
0.0088 1463816 3. PHPUnit_TextUI_Command->run() D:\Divers\Programmation\Web\foodmeupnew.dev\vendor\phpunit\phpunit\src\TextUI\Command.php:99
0.0088 1466536 4. PHPUnit_TextUI_Command->handleArguments() D:\Divers\Programmation\Web\foodmeupnew.dev\vendor\phpunit\phpunit\src\TextUI\Command.php:109
0.0132 2056112 5. PHPUnit_TextUI_Command->handleBootstrap() D:\Divers\Programmation\Web\foodmeupnew.dev\vendor\phpunit\phpunit\src\TextUI\Command.php:575
0.0134 2065160 6. PHPUnit_Util_Fileloader::checkAndLoad() D:\Divers\Programmation\Web\foodmeupnew.dev\vendor\phpunit\phpunit\src\TextUI\Command.php:750
0.0136 2065352 7. PHPUnit_Util_Fileloader::load() D:\Divers\Programmation\Web\foodmeupnew.dev\vendor\phpunit\phpunit\src\Util\Fileloader.php:36
0.0183 3407040 8. include_once('D:\Divers\Programmation\Web\foodmeup.dev\app\bootstrap.php.cache') D:\Divers\Programmation\Web\foodmeupnew.dev\vendor\phpunit\phpunit\src\Util\Fileloader.php:52
0.0185 3409304 9. require_once('D:\Divers\Programmation\Web\foodmeup.dev\app\autoload.php') D:\Divers\Programmation\Web\foodmeup.dev\app\bootstrap.php.cache:5
0.0187 3411320 10. require('D:\Divers\Programmation\Web\foodmeup.dev\vendor\autoload.php') D:\Divers\Programmation\Web\foodmeup.dev\app\autoload.php:9
0.0191 3424808 11. ComposerAutoloaderInit751ca4f7e73ded3907cdc8698c543ac6::getLoader() D:\Divers\Programmation\Web\foodmeup.dev\vendor\autoload.php:7
0.0214 3630760 12. composerRequire751ca4f7e73ded3907cdc8698c543ac6() D:\Divers\Programmation\Web\foodmeup.dev\vendor\composer\autoload_real.php:45
EDIT:
I've taken the following measure to make sure foodmeup.dev was not hardcoded :
- find and replace in content of every file including hidden and system files the string 'foodmeup.dev' by 'foodmeupnew.dev'
- delete entire directory, create new one, pull git branch, run composer install, reset bootstrap.cache
same error happens again. I'm sure there might be some misconfiguration but I can find out where it's coming from. any clue ?
EDIT2
OK, I figured out that line 5 is loading phpunit configuration that contains the hardcoded 'foodmeup.dev' value.
Where does this configuration come from... that is to find out
> $phpunit - D:\Divers\Programmation\Web\foodmeupnew.dev\vendor\phpunit\phpunit\src\TextUI\Command.php:566
============================================================================================================
array(
[colors] => string(4) "auto"
[backupGlobals] => bool(false)
[bootstrap] => string(64) "D:\Divers\Programmation\Web\foodmeup.dev\app\bootstrap.php.cache"
)
EDIT 3
Digging into it, I figured out that in file D:\Divers\Programmation\Web\foodmeupnew.dev\vendor\phpunit\phpunit\src\TextUI\Command.php:566 the realpath function applied to a relative path would render a different path.
var_dump($this->arguments['configuration'] . '/phpunit.xml');
string(15) "app/phpunit.xml"
var_dump(realpath($this->arguments['configuration'] . '/phpunit.xml'));
realpath($this->arguments['configuration'] . '/phpunit.xml') - D:\Divers\Programmation\Web\foodmeupnew.dev\vendor\phpunit\phpunit\src\TextUI\Command.php:529
================================================================================================================================================================ string(56) "D:\Divers\Programmation\Web\foodmeup.dev\app\phpunit.xml"
How can that be that the realpath function renders a path with foodmeup.dev when the call is made from a file located in the foodmeupnew.dev directory ?
EDIT 4:
I figured out this is a phpStorm issue. there must be a global variable which sets the dir for php function. If I run the command from an external command line, the error does not arise

PHPUNIT error when running tests with PHPSTORM

Running phpunit tests using PhpStorm.
Receiving this error:
/usr/local/php5/bin/php
/private/var/folders/m8/k61mmmmj7g732j3pd0_91s0c0000gn/T/ide-phpunit.php
--configuration /Users/psteinheuser/unity/test/phpunit.xml DatabaseDumperTest
/Users/psteinheuser/unity/test/DatabaseDumperTest.inc Testing started
at 11:36 AM ...
Fatal error: Class IDE_PHPUnit_Framework_TestListener contains 1
abstract method and must therefore be declared abstract or implement
the remaining methods (PHPUnit_Framework_TestListener::addRiskyTest)
in
/private/var/folders/m8/k61mmmmj7g732j3pd0_91s0c0000gn/T/ide-phpunit.php
on line 504
Call Stack:
0.0013 340096 1. {main}() /private/var/folders/m8/k61mmmmj7g732j3pd0_91s0c0000gn/T/ide-phpunit.php:0
PHP Fatal error: Class IDE_PHPUnit_Framework_TestListener contains 1
abstract method and must therefore be declared abstract or implement
the remaining methods (PHPUnit_Framework_TestListener::addRiskyTest)
in
/private/var/folders/m8/k61mmmmj7g732j3pd0_91s0c0000gn/T/ide-phpunit.php
on line 504
Have found previous posts which have said this is fixed, though I seem to have the correct versions where it should work.
PHPStorm 7.1.3
phpunit 3.7.28
php 5.4.24
The OS is Mac 10.9.2
Have removed and re-installed PHPStorm, upgraded php, re-installed phpunit, restarted apache, rebooted, scratched my head, etc.
Running the phpunit tests manually from the terminal, works fine.
Looking at Preferences within PHpStorm, it seems to be pointing to phpunit correctly.
I'm thinking it's a permission or path issue, but I don't know where to look next.
Appreciate any input or direction.
In PHPStorm, the only way I was able to solve this was by manually updating the contents of the jar file where this error exists.
We're both on Mac OSX 10.9, so these instructions should work for you.
Begin by making a copy of the existing jar file:
cp /Applications/PhpStorm.app/plugins/php/lib/php.jar /Applications/PhpStorm.app/plugins/php/lib/php.jar.orig
Now, create a temporary directory to hold your jar file's contents and extract
mkdir ~/jarfiles
cd ~/jarfiles
jar xf /Applications/PhpStorm.app/plugins/php/lib/php.jar
Once extracted, you'll need to edit the phpunit.php file to add the missing method stub
vi scripts/phpunit.php
Around line 310 in my file is a class 'IDE_PHPUnit_Framework_TestListener'. Insert the following method stub:
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time){}
Now just re-pack your jar and replace it into your PhpStorm:
jar cf0 php.jar ./*
mv php.jar /Applications/PhpStorm.app/plugins/php/lib/php.jar
That fixed it for me. Hope it fixes it for you too. Good luck!

Categories