phpunit with composer not working - php

Background: i am on a windows host and sshing into a vagrant LAMP setup (ubuntu 13.04).
I have installed phpunit with composer using the following line in my composer.json:
"require-dev": {
"phpunit/phpunit": "3.7.*"
}
I have then run composer update which installed phpunit. I can now navigate to /vendor/bin and see phpunit binary.
However if i type phpunit from within that directory (or anywhere elese for that matter) I get the error "phpunit is not installed"
Any suggestions as to where I go next with this - there are so few steps involved in this setup I really cant see where I could have gone wrong

So I had this issue too, for me the fix was to change in my vagrant file:
config.vm.synced_folder "C:/dev/vm/share", "/var/www/", mount_options: ['dmode=777','fmode=666']
to
config.vm.synced_folder "C:/dev/vm/share", "/var/www/", mount_options: ['dmode=777','fmode=777']
There is a lot of advise saying 666 is permissive enough, but in my case it was not and as this is only a development machine the security implications are not too important.

./phpunit from the bin directory.
It's just not in your path.

I created the script above:
#!/bin/bash
binary=$1
shift
dir=$PWD
for i in $( seq 5 )
do
if [ -e "$dir/composer.json" ]
then
$dir/vendor/bin/$binary $#
else
echo "not found phpunit in $dir"
fi
dir="$dir/.."
done
If you name it 'composer.exec', and put it n your path, you can call it:
composer.exec phpunit [phpunit-options]
And there is it! Calling phpunit or any other bin contained in vendor/bin.

Related

AWS Elastic Beanstalk Deployment Order

I'm deploying code to a single-instance web server AWS EB environment that will provision/update my connected RDS database. I've got an .ebextensions file that calls deployment code:
---
container_commands:
01deploydb:
command: /var/www/html/php/cli/deploy-db.php
leader_only: true
On the same deployment, I dropped the deploy-db.php file back one directory into /cli/. On deployment, I get ERROR: [Instance: i-*****] Command failed on instance. Return code: 127 Output: /bin/sh: /var/www/html/php/cli/deploy-db.php: No such file or directory.
container_command 01deploydb in .ebextensions/01_db.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
If I deploy a version that does not include the command, then deploy a second update including the command, there is no error. However, adding the command and the file it calls at the same time produces the error. A similar sequence occurred earlier with a different command/file.
My question is: is there a documented order/sequence for how AWS updates the environment? I would have expected that my new version would have fully deployed (and the .php file installed) before container_commands are called.
The commands: section runs before the project files are put in place. This is where you can install server packages for example.
The container_commands: section runs in a staging directory before the files are put in its final destination. Here you can modify your files if you need to. Current path is this staging directory so you can run it like this (I might get the app directory wrong, maybe it should be php/cli/deploy-db.php)
container_commands:
01deploydb:
command: cli/deploy-db.php
leader_only: true
Reference for above: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
You can also run a post deploy scripts. This is not very well documented (at least it wasn't). You can do something like this (it won't be leader only though, but you could put a file in this directory through a container_commands:):
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_deploy.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
/var/www/html/php/cli/deploy-db.php

How to setup Codeception with remote code coverage?

I have two repo on my machine
API
Codeception repo that tests API
In API repo I have added codeception+c3
"require-dev": {
"codeception/codeception": "2.*",
"codeception/c3": "2.*",
I've also included c3.php inside index.php, but when trying to test it with --coverage I have this error
[PHPUnit_Framework_Exception]
file_get_contents(http://local.api.codeception.com/c3/report/clear): fai
led to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
Is there ANY online example of remote codecoverage with Codeception?
Here's my configuration for remote codecoverage with Codeception (Project on GitHub).
Steps for running up remote codecoverage collection
1. Make sure that xdebug installed and enabled.
2. Configure codeception.
File codeception.yml (GitHub):
coverage:
enabled: true
c3_url: 'http://%SERVICE_HOST%/index-test.php/'
include:
- web/*
- config/*
- src/*
3. Enable coverage for the suits you need.
File acceptance.suite.yml (GitHub):
coverage:
remote: true
In my example its enabled only for acceptance tests.
4. Include c3.php file in your application bootstrap.
Application bootstrap file index-test.php (GitHub):
// Start the remote code coverage collection.
require_once __DIR__.'/../c3.php';
// autoloader, application running and etc
// ...
5. Run coverage.
$ vendor/bin/codecept run --coverage --coverage-html
By default you can find your reports in tests/_output directory.
Possible issues
1. Output directory not writable (tests/_output).
$ chmod 777 tests/_output
2. Remote codecoverage not printed in console.
It should not be printed. From documentation:
coverage:
remote: true
In this case remote Code Coverage results won’t be merged with local ones, if this option is enabled. Merging is possible only in case a remote and local files have the same path. But in case of running tests on a remote server we are not sure of it.
3. Some other error.
Try to enable debug. If debug enabled, you can get your report or clear it.
curl -o codecoverage.tar "http://localhost:8080/index-test.php/c3/report/html"
End
Sometimes it's not a trivial task. So I hope this will help!
Ok, it was a configuration nightmare, but I've fixed it
Here is example

Trying to run heroku locally and get a error 'vendor' is not a command

I am trying to run heroku locally using the command
heroku local
However, it returns:
[OKAY] Loaded ENV .env File as KEY=VALUE Format
'vendor' is not recognized as an internal or external command, operable program or batch file.
[DONE] Killing all proccess with signal null
Exited with exit code 1
I am using Heroku PHP within Windows 7
In my PATH environmental variable, I have both:
./vendor/bin and C:\Users\user-name\AppData\Roaming\Composer\vendor\bin
(The last one is an empty folder)
I searched for anything similar but I couldn't find.
Any thoughts on it?
Thanks in advance
Update
The error was in my Procfile:
web: vendor/bin/heroku-php-apache2 public/
Then I change all slashes to backslashes ():
web: vendor\bin\heroku-php-apache2 public\
Now its working but I am getting this error:
../heroku/heroku-buildpack-php/bin/heroku-php-apache2: line 196: php-fpm: command not found
This program requires PHP 5.5.11 or newer; check your 'php-fpm' command.
I think there is something wrong related to my composer.
The source file for heroku-php-apache2 can be found here.
The line 196 is presented below.
196: { php-fpm -n -v | php -n -r 'exit((int)version_compare(preg_replace("#PHP (\S+) \(fpm-fcgi\).+$#sm", "\\1", file_get_contents("php://stdin")), "5.5.11", "<"));'; } || { echo "This program requires PHP 5.5.11 or newer; check your 'php-fpm' command." >&2; exit 1; }
My composer.json file is:
{
"require" : {
"ext-mcrypt": "*",
"facebook/php-sdk-v4" : "~5.0",
"google/apiclient": "2.0"
},
"require-dev": {
"mashape/unirest-php": "3.*",
"heroku/heroku-buildpack-php": "*"
}
}
I tried to specific require php in composer.json but it didn't changed. Any thoughts on that?
Thank you in advance.
Years later, I've faced this same issue.
Fixed by removing vendor/ and running composer install again.
Then I've faced the same php-fpm error and to fix that I created a symbolic link from /usr/sbin/php-fpm7.4 -> /usr/sbin/php-fpm.
Hope that becomes helpful to orthers in the future!

How to fix the "unrecognized option --run" on NetBeans running PHPUnit

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 PHP Phing in PHPStorm using Composer leads to missing Archive/Tar.php

I've installed both Composer and Phing via PHPStorm and its capability to run these tools via their .phar-file distribution. So both tools are running "within" their .phar-file.
I created a build.xml and tried to run it within PHPStorm which fails like:
/usr/bin/php /Users/.../dev/phing/phing-latest.phar -f /Users/.../branches/dev/build/build.xml -Dversion=...
Buildfile: /Users/.../branches/dev/build/build.xml
BUILD FAILED
Error reading project file [wrapped: You must have installed the PEAR Archive_Tar class in order to use TarTask.]
Total time: 0.0808 seconds
[PHP Error] include_once(Archive/Tar.php): failed to open stream: No such file or directory [line 75 of phar:///Users/.../dev/phing/phing-latest. phar/classes/phing/tasks/ext/TarTask.php]
[PHP Error] include_once(): Failed opening 'Archive/Tar.php' for inclusion (include_path='phar:///Users/.../dev/phing/phing-latest.phar/bin/.. /classes:.:') [line 75 of phar:///Users/.../dev/phing/phing-latest.phar/classes/phing/tasks/ext/TarTask.php]
I installed the required components via composer:
{
"repositories": [
{
"type": "pear",
"url": "http://pear.php.net"
}
],
"require": {
"phing/phing" : "2.*",
"pear-pear.php.net/pear": "*"
}
}
Basically it's pretty clear what's wrong here, but I'm curious what's the best way out of it. I'm looking for a way out of it, without running into too much further dependencies. The way described above has the charm of being easily adapted to other workstations and other deployment environments. So what I'm looking for is a way to make this work without further environment setup.
Is there a way to influence the include_path in this scenario? I already tried to put the appropriate directories in the PHPStorm PHP Settings but it doesn't seem to be interpreted while staring a build target in the "Phing Build"-Window.

Categories