Does anyone know the correct command line to generate a code coverage file on a PHP project? I've already installed the XDebug tool.
In the official documentation from PHPUnit, I found the following command line, but it is not working:
phpunit --coverage-text=<file>
where is the file where output is going to be stored.
I don't have any tests yet, but is there a way to generate a report file, even though there are no tests in the project?
You'll need to include the path to your tests, as well as the white list command with the path to the source code to be tested. E.g.
phpunit --coverage-text="coverage.txt" ./path/to/tests --whitelist="./path/to/code"
Where coverage.txt is the file that the output will be stored in. You can generate a report without any tests.
Related
I'm on a Mac using macOS Monterey.
I'm trying to install and use Composer so that I can use it in MAMP.
I've followed a few tutorials to do this, but I am still unable to get terminal to recognize the command 'composer'.
It fails with the error:
env: php: No such file or directory
The composer executable is available here:
/Applications/Mamp/bin/composer
My .zshrc has the following alias:
alias phpmamp='/Applications/MAMP/bin/php/php7.4.12/bin/php'
How can I make Composer available for my PHP projects?
Your question sounds like you have problems to actually read/parse the message:
> env: php: No such file or directory
env: - this is the name of the utility (env(1)) that gives the message. if you don't know what it does and what is for, continue consulting the manual now as otherwise you have problems to decipher the rest of the message:
php: No such file or directory
In your environment, php is not available as a file or directory. It could not be resolved.
Whatever the consequences on your own configured system are can not be said without further information.
But next to reading about the utility in use - env(1) - and given the name of the other utility - php(1) - you can normally gather more information by obtaining the absolute path of php on your system first. There are only two options:
there is no such file named php.
there is such a file named php and you know it's full and absolute path now.
The rest you find in the env(1) documentation.
Hope this gets you back starting and you learn a bit more how your operating system works you want to use for development.
I am new to phpunit and I am trying to get it working with PHP storm. I have added composer and I have added the phpunit dependency and the files are all there. But when I try call phpunit in the command line I get this error.
I can't figure this out because I have tried calling phpunit and I have tried going through the folders to the files phpunit and phpunit.bat. Here is a picture of the folders and files.
It displays an error since your php is not being recognized. In order to fix the problem, you need to add your php directory to your PATH Environment Variable.
Screenshot of My System Variable
To verify that your php is now being recognized by the system, run the command php --version in your command prompt. It should display the version of your PHP
I'm trying to create something similar to the laravel installer, it's a PHP Script that utilises Symfony's Console Component. It all works fine except I can't seem to get the damn thing to execute globally on my command line.
I've currently got the script(boiler) stored as /dir/dir/vendor/author/packagename/boiler.
Via Composer I also have a symlink that points to the script from /dir/dir/vendor/bin/. Automatically done via bin in composer.json.
I've updated my $PATH, which now shows /folder/folder/vendor/bin/ to point to the symlink;
My script starts:
#!/usr/bin/env php
Permissions are:
-rwxr-xr-x
I'm running Zshell on Mac OSX.
It will run if I go into the directory and type php boiler but boilerreturns command not found and if I'm in a different directory boiler also returns command not found. php boiler returns "Could not open input file: boiler"
The laravel installer runs exactly as I want mine to, using just laravel whilst anywhere on the command line.
At a complete loss. Google isn't turning up any similar issues, and neither is Stack (My searching ability may be lacking though, it's 4am.)
For those with similar issues:
Use which commandName to see if it's correctly added to your $PATH
Check the symlink is correct if it's via one
Check permissions on symlink and executable script
Post to stackoverflow so that it'll just.. fix itself.
So... which boiler returned the correct path so I tried boiler again from my home dir and it worked.
I genuinely haven't changed a single thing and been stuck for an hour. I don't understand...
Thanks all for help.
I have run into a truly strange issue for which i have no explanation whatsoever.
After setting up OS X Yosemite and my local dev environment using XAMPP, i installed ImageMagick through MacPorts. All is well, it runs perfectly fine on the commandline.
However, when executed through Apache and called through PHP, i get no output from it whatsoever.
I have done extensive research and found a variety of approaches:
Setting the path environment variable in Apache (which i tried)
Using an absolute path to the executable (which i do)
Checking if exec() is listed as a disabled function (which it is not)
Checking if convert is even callable, as in executable (which it is)
I even went as far as copying the convert executable to the local project root directory and trying to exec('./convert'); but to no avail. I always receive absolutely no output from that call. Not even an error message. Needless to say, when i run the same thing through the Terminal, it works fine.
I also tried:
Calling exec('ls'); to see if anything comes up at all (yes it does, that works fine)
Calling exec('which convert');, where i get no result at all - the call returns nothing
Calling exec('which ls'); to double-check if the problem was with which - but which ls works fine and gives me /bin/ls as a response.
Providing chmod 0777 to the executable - to no avail
Regardless from what i try or do, convert remains entirely untouchable to PHP/Apache.
Can anyone tell me why that is and how to remedy it?
Checking the Apache error logs, i found the following message:
dyld: Library not loaded: /opt/local/lib/libfreetype.6.dylib
Referenced from: /opt/local/bin/convert
Reason: Incompatible library version: convert requires version 18.0.0 or later, but libfreetype.6.dylib provides version 15.0.0
Research showed that there is a common approach changing some environment path variable that applies to Apache and its subsidiary processes while running. However, since i did not want to fiddle around like that, i went for a somewhat more raw approach:
I opened a terminal and went to the very root directory of my system. There i ran:
find . -name "libfreetype.6.dylib"
This gave me all the libfreetype.6.dylib files that were available on my system. One of them was in the XAMPP lib directory, another one was in /usr/local/lib.
I backup up the file in the XAMPP directory and then copied the one from /usr/local/lib there.
I then tested convert again through Apache and was given another, quite similar error message relating to libexpat.1.dylib. For that i repeated the copying process as above. Afterwards, convert was executable through Apache and the problem was solved.
When you run scripts and programs via your web server, they are being run by a different user. In Macs this is usually _www. The convert application can't be found because the path to its executable file (probably /usr/local/bin) isn't included in the $PATH environment setting for this user.
The simplest solution is just to prefix the command with the path to convert, i.e., exec('/usr/local/bin/convert ... ');
I'm trying to configure my local development environment to read .less files so that I can edit .less files during development and only convert to .css when it's time to go live. Make sense?
I'm running MAMP as my local testing server. I'm following the instructions I found here:
http://programming-perils.com/155/parse-less-files-on-the-fly-and-serve-them-as-css/#comment-920
In short, the plan is to use an htaccess file catch requests to .css files and direct them to a PHP script which compiles the .less file of same name and returns the css code.
Everything seems to be working from the command line. I can compile a .less file from the command line and it spits out the css. I know my rewrite rule is working because I can type the url into a browser and see the output of my php script. For example, if my PHP script calls echo shell_exec('pwd'); I will see a path printed in the browser.
THE PROBLEM is that I can't get the less script to run unless I SSH to the localhost as root. When I exit SSH and run the command I get "Permission denied". I suspect this is what happens when my PHP script tries to call this... so it's returning nothing.
I guess the question boils down to how can I get my PHP script to run the less compiler?
UPDATE! I solved the problem...
It turns out that the less command (path/path/lessc) needed to be sudo'ed. PHP wasn't doing this, so the shell_exec() command wasn't returning anything. That's why my echo statements DID work.
There are a lot of ways to sidestep this, but I determined that editing the list of sudoers with sudo visudo was the best for my purposes. There was a lot of helpful tips on this post. Through trial and error, I figured out that PHP uses the www-data account. Adding this line fixed my problem:
www-data ALL=(ALL) NOPASSWD: /var/root/node/npm/node_modules/less/bin/lessc
Something to remember is that you STILL have to add sudo to the command that gets fed to shell_exec(). Hope this is helpful to someone else.
Maybe it would be easier if you'd use the PHP implementation of lesscss: lessphp
It turns out that the less command (path/path/lessc) needed to be sudo'ed. PHP wasn't doing this, so the shell_exec() command wasn't returning anything. That's why my echo statements DID work...
See my edits to the question above.