I am trying to move my development environment (symfony2 application) from my windows 7 localhost to a virtual machine using vagrant and the default ubuntu 10.04 64 bit machine. Everything is set up and it almost works, but there is one thing bothering me:
When I run ant and it executes phpunit, I get the following error while executing my selfmade bootstrap:
stty: standard input: Invalid argument
I could narrow the problem down to the following line of code, which executes the symfony cache:warmup command:
executeCommand($application, "cache:warmup");
This executes the following command:
php app/console -e test -q cache:warmup
Running phpunit without ant works fine, so does running ant without the executeCommand line.
I read a bit about this stty error and looked up ~/.bashrc, ~./profile, /etc/bash.bashrc, /etc/profile as well as /root/.bashrc and /root/.profile without finding anything like tty or stty. SO I don't know what I could delete to make it work.
I am a bit stuck as I need the cache warmup and cannot figure out what is going wrong.
This took a while to figure out, but I now got it.
For some reason, the options passed to the symfony2 application object causeing the issue only when run by ant.
I don't have any insight on what causes it, but changing the command to this fixes the issue:
php app/console --env=test --quiet cache:warmup
As this is only the long form and does not change anything, I'm very happy. My whole executeCommand function looks like this:
function executeCommand($application, $command, Array $options = array()) {
$options["--env"] = "test";
$options["--quiet"] = true;
$options = array_merge($options, array('command' => $command));
$application->run(new ArrayInput($options));
}
The only lines changes are 2 and 3 where the key for the array was changed from -eand -q. I hope this helps one or another who struggles with an issue like this!
Related
I am developing a Laravel (8.83.24) app and testing with Laravel's built in server "php artisan serve". I am using Process and am trying to debug a memory allocation error which has lead me to here:
$process = new Process(['node', '-v']);
$process->run();
print_r($process);
That leads me to a line in the output:
[command] => cmd /V:ON /E:ON /D /C (node -v) 1>"C:\Users\mat\AppData\Local\Temp\sf_proc_01.out" 2>"C:\Users\mat\AppData\Local\Temp\sf_proc_01.err"
and sf_proc_01.err contains:
'node' is not recognized as an internal or external command,
operable program or batch file.
Clearly node can't be found. I am on Windows 10. Node is set in my in System and User PATH. Running "node -v" from cmd.exe works and returns the version number. So Laravel's server doesn't seem to be able to find node. However, I can't check the path as running this:
$process = new Process(['echo', '%PATH%']);
$process->run();
print_r($process);
Just leads to an output of
"%PATH%"
How can I make Node findable by Laravel / Process?
Many thanks for your help.
I eventually solved this by setting the path for node in my Laravel .env file:
NODE_PATH='C:\PROGRA~1\nodejs\node.exe'
NPM_PATH='D:\Work\Project\node_modules'
I'm trying to use multiple consumers with the same Redis transport using the Symfony Messenger component.
As mentioned in the Symfony guide, we can have problems if we use the same values for stream/group/messenger, cause the same message can be handled by multiple consumers.
So I have updated my supervisor config as follow:
environment=MESSENGER_CONSUMER_NAME=%(program_name)s_%(process_num)02d
Then, I have updated my messenger.yaml file as follow:
redis:
dsn: '%env(MESSENGER_TRANSPORT_REDIS)%'
options:
consumer: '%env(MESSENGER_CONSUMER_NAME)%'
I have reloaded the supervisor:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start messenger-consume:*
but I still get the error:
[2021-12-25T18:33:08.954217+01:00] console.CRITICAL: Error thrown while running command "messenger-dispatcher --count=100". Message: "Environment variable not found: "MESSENGER_CONSUMER_NAME"." {"exception":"[object] (Symfony\\Component\\DependencyInjection\\Exception\\EnvNotFoundException(code: 0): Environment variable not found: \"MESSENGER_CONSUMER_NAME\". at /var/www/vendor/symfony/dependency-injection/EnvVarProcessor.php:172)","command":"messenger-dispatcher --count=100","message":"Environment variable not found: \"MESSENGER_CONSUMER_NAME\"."} []
I follow the guidelines but there is something missing somewhere ... but where?
Why does my app not read env var?
If I call my consumer:
MESSENGER_CONSUMER_NAME=myconsumer ./bin/console messenger:consume redis
it works as expected; it does not work only with supervisor vars.
Thanks in advance
UPDATE
This is the complete section config of my supervisor file:
[program:consumer-redis]
command=php /var/www/bin/console messenger:consume redis --limit=5 --time-limit=3600
user=root
numprocs=6
startsecs=0
autostart=true
autorestart=true
process_name=%(program_name)s_%(process_num)02d
environment=MESSENGER_CONSUMER_NAME=%(program_name)s_%(process_num)02d
Today I had a similar issue, but you need to explain a little more if my answer match with your problem if not please replay me to delete my answer.
So the problem is, when you run the command:
php /var/www/bin/console messenger:consume redis
Symfony asumes the APP_ENV from 2 parts, if you are using a web server, the variable is taken from the apache or nginx or php/apache.conf file configuration, but in command line if you server has no configured the variable APP_ENV, symfony is going to check the .env file and then .env.local or .env.local.php, so, if that variable doesn't exists, Symfony is not going to take any files like .env.prod.local or .env.prod because is missing that variable. If you are using
I found the answer thanks to this article.
Your configuration is all good. You simply need to add an environment variable with a default value, so that Symfony doesn't generate errors :
# .env.local
MESSENGER_CONSUMER_NAME=0
This env variable will be overwritten in processes ran by supervisor. To test it, I simply log $_ENV['MESSENGER_CONSUMER_NAME'] in a function. Here's what I get when I call it :
Not using Messenger (synchronously) : 0
Using Messenger : either messenger-consume_00 or messenger-consume_01. (In my config I have numprocs=2)
I fixed this problem by adding the following at the top of my config/packages/messenger.yaml file:
parameters:
env(MESSENGER_CONSUMER_NAME): '00'
I have configured PhpStorm to connect to a remote web server. I am running phpunit for unit tests. I have xdebug running and have created an ssh tunnel for debugging. I know xdebug is running as I am able to click and run a phpunit test (with breakpoint set) by just clicking the run button (after turning on listening for PHP debug connections). However if I instead choose the Debug option in PhpStorm I get connection errors.
Enabling debug messages to the PhpStorm log file I see that the command being sent is:
DEBUG - ellij.ssh.SshConnectionService - Executing SSH command:
cd /[path to project files];
exec env "IDE_PHPUNIT_CUSTOM_LOADER"="/[path to autoloader]/autoload.php" "JETBRAINS_REMOTE_RUN"="1" "XDEBUG_CONFIG"="idekey=17650" /usr/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9002 -dxdebug.remote_host=[ip address] /[path to phpunit]/phpunit/phpunit --configuration /[path to phpunit xml file]/phpunit.xml --filter '/(::myTestClassMethod)( .*)?$/' 'another method being tested' /[path to unit test file]/myUnitTest.php --teamcity within SshjSshConnection([blah]#[foo])#bar
My php.ini settings are expecting idekey=PHPSTORM but I'm seeing a numeric key in the command line that keeps changing for each attempt.
I'm assuming these two values for idekey need to match. If that's correct how do I do that?
Thanks
They don't need to match. In fact, PhpStorm is just overriding it here so that it can match against what it expects.
I don't understand why it does that, as IDE Keys are (currently) only used in combination with DBGp proxies.
As you don't describe what "connection errors" are, it's not really possible to provide an answer to that part of the question yet.
I'm trying to run the PHPUnit into the NetBeans 8.0.2.
If I run # phpunit inside my folder tests all tests run. So it's seems been set right.
But in the NetBeans output I always got:
"C:\nginx\php\5.6.12\php.exe" "C:\nginx\php\5.6.12\phpunit.phar" "--colors" "--log-junit" "C:\Users\...\AppData\Local\Temp\nb-phpunit-log.xml" "--bootstrap" "E:\var\www\...\tests\TestHelper.php" "--configuration" "E:\var\www\...\tests\phpunit.xml" "C:\Program Files\NetBeans 8.0.2\php\phpunit\NetBeansSuite.php" "--run=E:\var\www\...\tests\app\utils\FormatUtilTest.php"
PHPUnit 4.8.2 by Sebastian Bergmann and contributors.
unrecognized option --run
Done.
Maybe the "--run message" it's right, because this command doesn't exist in the PHPUnit manual. But if is that so, how to create another script for the NetBeans execute the tests?
I ran into the same issue yesterday after a PHPUnit update. So I reverted back to PHPUnit 4.7.7 for now, until this is fixed in NB.
I too have encountered this error causing the latest version of PHPUnit not to work with NetBeans v8.0.2.
Further investigating this issue has resulted in determining that there is an incompatibility between NetBeansSuite.php and the latest version of PHPUnit.
The error 'unrecognized option --run' is being thrown by the phpunit.phar and not being thrown by NetBeansSuite.php. I also do not believe the NetBeansSuite.php is even being executed.
phpunit.phar, line 63816 or 63894, is where the exception is being thrown.
Until this is fixed, PHPUnit will not work from NetBeans v8.0.2.
#Pablo: I thank you for opening an issue and have commented on your issue.
PHPUnit v4.7.7 works correctly.
Opened a bug report: https://netbeans.org/bugzilla/show_bug.cgi?id=254276
The answer is: This was indeed a bug in NB and is now fixed in nightly.
Possible solutions:
Upgrade to latest nightly from http://bits.netbeans.org/dev/nightly/
Use PHPUnit 4.7.7 as mentioned by Luuk
"--run" option is used in the NetBeansSuite.php for running tests. So, you should submit that to NetBeans bugzilla [1] if you want to avoid that.
[1] https://netbeans.org/community/issues.html (PHP/PHPUnit)
2019 and the problem still exists. Downgrading PHPUnit is no option anymore today. So I created, as a workaround, a wrapper script for phpunit which takes care of removing the bad parameters.
It also removes the NetBeansSuite.php file completely because it does the same a call directly to the phpunit script would.
My setup is Windows Netbeans 11, Windows PHP 7.3, and a cygwin wrapper (because it's bash code). If somebody feels like porting this to native windows, please leave a comment here.
#!/usr/bin/env sh
# modified phpunit script originally from vendors dir
# 1. cygwin default search path is bad in my installation...
PATH="$PATH:/bin:/usr/bin"
# original code, only adjust the ../../ to match your installation.
# the directory this is run in is where the wrapper script resides
dir=$(cd "${0%[/\\]*}" > /dev/null; cd "../../vendor/phpunit/phpunit" && pwd)
if [ -d /proc/cygdrive ] && [[ $(which php) == $(readlink -n /proc/cygdrive)/* ]]; then
# We are in Cgywin using Windows php, so the path must be translated
dir=$(cygpath -m "$dir");
fi
# fix netbeans parameters
while [ $# -gt 0 ]; do
case "$1" in
*NetBeansSuite.php) shift;;
--run=*) PARAMS="$PARAMS ${1#--run=}"; shift;;
--) shift ;;
*) PARAMS="$PARAMS $1"; shift;;
esac
done
"${dir}/phpunit" $PARAMS
You have to adjust both occurrences of "../"s to your folder structure.
This solution works with ALT-F6 (run all tests), right clicking a test folder "Run Tests" and also single test files right click "Run".
The setting for "Netbeans: Tools/Options/Frameworks & Tools/PHPUnit" is then:
C:\cygwin\bin\bash.exe /cygdrive/c/workspace/Project/src/cli/phpunit
Adjust these path names to your needs, again.
HTH,
M.
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!