somewhere somehow i begun to get a dot with 4 spaces inside PHPUnit's progress bar and i don't understand how to set it back to normal. It's PHPUnit only, other shell scripts go ok.
It looks like this
. . . . . . . . . [...] 100 / 100 (100%)
Problem is not only with local machine because when i run the test on other machine, it also generates same progress bar with spaces between progress dots.
Maybe anybody has the clue where to fix it.
Some background information (but since i am getting same spaces on two different configurations, its something with files/phpunit and not dev env):
PHP Framework Laravel 4.0-dev
Test box 1: MacOSX 10.9, PHPUnit 3.7.28, PHP version 5.4.17
Test box 2: Ubuntu 13.04, PHPUnit 3.7.21, PHP 5.4.9-4ubuntu2.2
Both boxes env LANG: en_US.UTF-8
Both boxes env LC_CTYPE: UTF-8
Encoding for source file, test file and phpunit.xml - UTF-8
Command to launch tests:
~/> php ../bin/phpunit.phar -c phpunit.xml
phpunit.xml:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="bootstrap/autoload.php" processIsolation="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./app/tests/</directory>
</testsuite>
</testsuites>
</phpunit>
Freaking out. Its UTF-8 everywhere, PHPUnit doesn't have config for progress bar. what is happening.
EDIT/RESOLUTION:
Thanks to #Sven for the tip.
Debugging the test step by step helped - i had lame \t char in the beginning of the db mock config file which is included as part of ::setUp().
To justify myself I just hope that anybody else will get here via google and find this annoying, yet tricky question useful.
You probably echo out some spaces somewhere.
For me, i was autoloading a config file that had a single leading space before the opening <?php tag
Related
I'm playing for a week with phpUnit.
I'm slowly going forward with documentation at:
https://phpunit.readthedocs.io
At this point I'm at code Coverage. I've managed to generate small test --coverage-html (via console). I want everything to work via phpStorm.
I'm struggling with inclusion paths. I can see errors in console, but these aren't to helpful at all.
This is how my console output looks like:
This is the only place I use this file in
This is how folder structure for tested and displayed (in console) file looks like
|- dir:Boostrap
|- dir:Coverage
|- dir:Database
|- dir:Interfaces
|- dir:Methods
|---- file: BasicCalculations.php (line 3 inclusion)
|- dir:Tests
|---- file:DataDisplayingTest.php (file that I'm testing)
|---- dir:Data Providers
|-------- file:BasicCalculationDataProvider.php (line 4 inclusion)
What I've tried/What I've made so far
Cannot find PHPUnit in include path phpstorm (I'm not doing this via composer/vendor so this is not helping, my remote machine is for all the debugging, calculations etc).
PHPUnit test suite include path - this gave me idea to play around with bootstrap file, where I've included all the required files, but again this worked only via manually running tests in console - I want to make it work in phpStorm remotely.
PHPUnit's whitelist and blacklist seem to be ignored . At this point situation looks like this
without processUncoveredFilesFromWhitelist="true" I've got no inclusion error, but I got just more errors after that:
It looks like it's trying to work as console gets green for a moment and I've got the Coverage panel now, but I bet this errors shouldn't be there. I can't be sure If coverage report is being displayed correctly at all.
PHPUnit error "Failed to open stream: No such file or directory" - I've tried the DIR as You can see,
https://github.com/sebastianbergmann/phpunit/issues/1932 - this helped me a bit, now I know I can/have to import xml, and this way I don’t have to generate coverage report remotely via ssh
This is how my phpunit.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="phpunit.xsd"
cacheResult="true"
verbose="true">
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory>/var/www/html/phpUnit</directory>
</whitelist>
</filter>
<php>
<includePath>/var/www/html/phpUnit</includePath>
</php>
</phpunit>
I've played around with directory/incluedPath, tried variation like:
- /var/www/html/phpUnit
- /var/www/html/phpUnit/
- .
- ./
- <file>pointed/tested/file/here/</file>
I'm working with:
phpStorm
phpUnit 7.x Remotely
php 7.x Remotely
xdebug Remotely
To be more clear:
what am I doing wrong?
how can I deal with inclusions problems?
what is causing all this inclusion path problems?
I’ve manage to solve all the problems I had. I’ve used some of the informations provided in the links I’ve pointed above.
First of all
Include errors
PhpUnit xml uses directive includePath, which in my case looked like this:
<php>
<includePath>/var/www/html/phpUnit</includePath>
</php>
Generally at this point the problem is with… existence of includePath in xml file. This attribute changes the inclusion path.
So lets say that You got project structure like that:
- dir: Classes
–- dir: A
–-- file: A.php class: A (extends B)
–- dir: B
–-- file: B.pphp class: B
-file: index.php
So from the look of file A.php You would need to include B.php like that:
../B/B.php
Since the working directory is
/var/www/html/phpUnit/Classes/
But now since You’ve set up inclusion path to:
var/www/html/phpUnit
File A, tries to load file B from the perspective of phpUnit folder, and it’s kinda looking for file in:
var/www/html
Not having this directive is not solving the problem as phpUnit seems to use some other default path.
I’ve solved this problem by changing the way I include files in project:
Just instead using:
include_once '../Interfaces/BasicCalculationsInterface.php';
I’ve started doing it like this:
include_once __DIR__.'/../Interfaces/BasicCalculationsInterface.php';
This way:
Single files tests work fine
Project itself works fine
phpStorm detects methods, classes etc in included file
Group tests work well too
Writing file index.html permission denied
I’ve stumbled upon this problem as well. This actually is some kind of phpStorm issue, which I don’t know how to solve permanently but I’ve dealt with it for the xml file from which I can run all my tests.
Basically phpStorm added some default configurations for executed tests.
In menu go to
Run/Edit Configurations
Take a look at field Test Runner options.
In my case phpStorm added
--coverage-html /
Everything would be fine, but I use Ubuntu on laptop as remote host, and phpStorm tries this way to create files in / directory for which there is no writing permission. Changing this to some writeable folder or removing this line solved the problem.
And that’s all, this is how my xml file looks like at this point (just in case someone would like to have something to look at)
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="phpunit.xsd"
verbose="true">
<filter>
<whitelist addUncoveredFilesFromWhitelist="false">
<directory suffix=".php">/var/www/html/phpUnit</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="/var/www/html/phpunit/coverage.xml" lowUpperBound="35" highLowerBound="70"/>
<log type="coverage-html" target="/var/www/html/phpUnit/phpStormCoverageTest" lowUpperBound="35"
highLowerBound="70"/>
</logging>
<testsuites>
<testsuite name="allTests">
<directory suffix="Test.php">/var/www/html/phpUnit/Tests</directory>
</testsuite>
</testsuites>
</phpunit>
Preview of working html/phpStorm coverage
I'm trying to test all directories except from one in a specific folder. My current tree:
app/code/My/Module/Test/SomeTest.php
app/code/Magento/Admin/Test/SomeTest.php
app/code/Other/Module/Test/AnotherTest.php
I need to run all tests but those inside the app/code/Magento directory. What I've tried so far:
<testsuite name="Modules Tests">
<directory suffix=".php">app/code/*/*/Test</directory>
<exclude>app/code/Magento</exclude>
</testsuite>
Even using exclude with absolute path or a wildcard app/code/Magento/*, they keep being added to testsuite. Also tried with blacklist, but it seems to be ignored as well.
I'm using PHPUnit 4.6.4.
Any advice here?
Thanks!
See the working example here.
Also 'exclude are ignored if a path is added within the command line' according to the comment in the link.
Ok, i really don't understand what is happening with my PHPUnit's bootstrap file.
I have a folder structure like the following one:
[Root]
- joo_component
-- administrator
-- site
-- Tests
--- admin
--- site
--- bootstrap.php
--- phpunit.xml
- vendor
In the phpunit.xml file, i have the following code:
<phpunit bootstrap="./bootstrap.php" colors="true">
<testsuites>
<testsuite... [all the things that go here]</testsuite>
</testsuites>
</phpunit>
Now, if i call PHPUnit explicitly specifying the bootstrap file all works well: the testing starts and properly signals errors and all other things it has to signal.
This is the command that works:
vendor/bin/phpunit --bootstrap="joo_component/Tests/bootstrap.php" joo_component/Tests
But, if i try to launch the testing without explicitly specifying the bootstrap file but specifying it in the phpunit.xml file it seems like the bootstrap file isn't loaded.
vendor/bin/phpunit joo_component/Tests
Is there anyone who can help me underdtand why this happens? Is there a way to force PHPUnit to tell me which bootstrap file it is using to load the test suites?
I built an application to compile and run java files and it was running completely ok.
Since it is the user to choose the path of java files to be compiled and executed, i quote the path, so that it can contains white spaces and special characters. Like this:
javac "C:\test project\*.java"
Now, i tried out in another computer and now i am having this error:
javac: file not found: C:\test project\*.java
Usage: javac <options> <source files>
use -help for a list of possible options
If i remove quotes and there is no spaces or special characters in path it works, but for the example above, that contains a white space, i get this error:
javac: invalid flag: C:\test
Usage: javac <options> <source files>
use -help for a list of possible options
I've read some threads about this, but i couldn't figured out the solution. Anybody has a clue?
Thank you!
Try quoting only the path and add the *.java after the quote. For example:
javac "C:\test project"\*.java
I've had a script in my test env with the same pattern, which stopped working today. After some research I've seen that the only change is that I've updated from JDK7 update 7 to update 17, and when I go back to update 7 it's working again. Seems that there's a new bug which was introduced somewhere in between. After some trial and error I came up with this workaround, which works for both the old and new javac.
Hope that helps.
* is meaningful to the shell, not to the compiler. When you put the * in the quotes, you are passing it to the compiler, not allowing the shell to expand it. you need to quote the spaces without quoting the star.
However, you'd be far better off using a proper build tool such as ant or maven.
I'm having trouble correctly setting up unit testing in Kohana 3.2.
I installed PHPUnit. I changed the bootstrap to activate Kohana's unittest module. I also changed the index.php file to look like this:
if ( ! defined('SUPPRESS_REQUEST'))
{
echo Request::factory()
->execute()
->send_headers()
->body();
}
I created a folder tests in my application folder. In it, I inserted a phpunit.xml file that looks like this:
<phpunit colors="true" bootstrap="../../index.php">
<testsuites>
<testsuite name="Kohana Tests">
<directory>./</directory>
</testsuite>
</testsuites>
I am having two problems (the first one is the one I really need an answer to):
1- When I go into tests from the command line and try running phpunit, it seems that SUPPRESS_REQUEST never gets set to true. The Request is executed, and therefore no tests are run. The only way I am able to run the tests successfully is to momentarily comment out the entire Request::factory() line in index.php. Does anyone know how to get around this problem? If I should be adding a define('SUPPRESS_REQUEST', true) somewhere, where should I do it? I'm new to Kohana and PHPUnit.
2- PHPUnit complains that the variable REMOTE_ADDR is not set.
PHP Notice: Undefined index: REMOTE_ADDR in
/Users/**/Sites/root/application/bootstrap.php on line 76
This is actually not a huge problem for now as tests still seem to run in spite of this, but I'm wondering if anyone knows if I should be setting this variable somewhere in specific.
In modules/unittest there is a file called bootstrap.php which works perfectly well with phpunit.
My phpunit.xml which references that bootstrap is this:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" bootstrap="../../modules/unittest/bootstrap.php">
<testsuites>
<testsuite name="Kohana Tests">
<directory>./</directory>
</testsuite>
</testsuites>
</phpunit>
Also, for the REMOTE_ADDR problem, when phpunit is running the CLI version of PHP, which I don't think has access to a REMOTE_ADDR variable. If you look at the bootstrap from unittest, it does not use http related globals.
I'm not sure why you have to run Request::factory code in your bootstrap. On my vanilla 3.2 install, the Request::factory code lives in index.php and not bootstrap.php and does not have any reference to SUPRESS REQUEST. You may have some lingering files from a pre-3.2 installation which need cleaning.