When a PHPUnit test fails normally on my dev box (Linux Mint), it causes a "Segmentation Fault" on my Continous Integration box (Centos). Both machines are running the same version of PHPUnit. My dev box is running PHP 5.3.2-1ubuntu4.9, and the CI is PHP 5.2.17. I'd rather leave upgrading the PHP as a last resort though.
As per this thread: PHPUnit gets segmentation fault
I have tried deactivating / reinstalling Xdebug. I don't have inclue.so installed.
On the CI box I currently only have two extensions active: dom from php-xml (required for phpunit) and memcache (required by my framework), all the others have been turned off.
Next to what cweiske suggests, if upgrading PHP is not an option for you and you have problems to locate the source of the segfault, you can use a debugger to find out more.
You can launch gdb this way to debug a PHPUnit session:
gdb --args php /usr/bin/phpunit quiz_service_Test.php
Then type in r to run the program and/or set environment variables first.
set env MALLOC_CHECK_=3
r
You might also consider to install the debugging symbols for PHP on the system to get better results for debugging. gdb checks this on startup for you and leaves a notice how you can do so.
I've had an issue with PHPUnit segfaulting and had trouble finding an answer, so hopefully this helps someone with the same issue later.
PHPUnit was segfaulting, but only:
If there was an error (or more than one)
After all tests had run but before the errors were printed
After a while I realized that it was due to failures on tests that used data providers, and specifically for data providers that passed objects with lots of recursive references. A bell finally went off and I did some digging: the problem is that when you're using data providers and a test fails, PHPUnit tries to create a string representation of the provided arguments for the failure description to tell you what failed, but this is problematic when one of the arguments has some infinite recursion. In fact, what PHPUnit does in PHPUnit_Framework_TestCase::dataToString() (around line 1612) is print out all the arguments provided by the data provider using print_r, which causes the segfault when PHP tries to create a string representation of the infinitely recursive object.
The solution I came to was:
Use a single base class for all my test classes (which fortunately I was already doing)
Override dataToString() in my test base class, to check for these kinds of objects in the data array (which is possible in my case because I know what these objects look like). If the object is present, I return some special value, if not I just pass it along to the parent method.
I had similar problem and by disabling the garbge collactor in
PHPStorm => Edit configuration => Interpreter option : -d
zend.enable_gc=0
Or if you are running your tests from the command line you may try adding :
-d zend.enable_gc=0
When you get a segfault, upgrade your PHP to the latest version. Not only the latest in your package manager, but the latest available on php.net. If it still segfaults, you are sure that the problem has not been fixed yet in PHP itself. Don't bother trying to get rid of a segfault in old version of PHP because it might have been fixed already in a newer one.
Next step is to locating the problem: Make your test smaller and smaller until you can't remove anything (but it still segfaults). If you have that, move the test into a standalone php script that segfaults. Now you have a test script for your bug in the PHP bug tracker.
In addition to https://stackoverflow.com/a/38789046/246790 which helped me a lot:
You can use PHP function gc_disable();
I have placed it in my PHPUnit bootstrap code as well with ini_set('memory_limit', -1);
I had the same problem and could nail it down, that I tried to write a class variable which was not definied:
My class (it's a cakePHP-class) which caused segmentation fault:
class MyClass extends AppModel {
protected $classVariableOne;
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->classVariableOne =& ClassRegistry::init('ClassVariableOne');
// This line caused the segmentation fault as the variable doesn't exists
$this->classVariableTwo =& ClassRegistry::init('ClassVariableTwo');
}
}
I fixed it by adding the second variable:
class MyClass extends AppModel {
protected $classVariableOne;
protected $classVariableTwo; // Added this line
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->classVariableOne =& ClassRegistry::init('ClassVariableOne');
$this->classVariableTwo =& ClassRegistry::init('ClassVariableTwo');
}
}
Infinite recursion is normally what causes this issue for us. The symptoms of infinite recursion seem to be different when running code under phpunit, than they are when running it in other environments.
If anyone comes across this in relation to PHPunit within Laravel
It took a while to figure out what the issue was. I was going over the differences between my current code and the previous revision and through some trial and error finally got there.
I had two different models that were both including each other with the protected $with override.
This must have been causing some kind of loop that phpunit could not deal with.
Hopefully someone finds this useful.
Please update to the newest XDEBUG. Got the same error while using v3.1.5, and after upgrading to 3.1.6 eveything works.
I got into the same problem. I upgraded the PHPUnit to the 4.1 version (to run the tests) and it was able to show me the object, as pointed by Isaac.
So, if you get to this very same problem, upgrade to PHPUnit >= 4.1 and you'll be able to see the error instead of getting "Segmentation fault" message.
I kept getting a Segmentation fault: 11 when running PHPUnit with Code coverage. After doing a stack trace of the segmentation fault, I found the following was causing the Segmentation fault error:
Program received signal SIGSEGV, Segmentation fault.
0x0000000100b8421a in xdebug_path_info_get_path_for_level () from /usr/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so
I replaced my current xdebug.so in the path above with the latest version from the Komodo Remote Debugging Package the sub-folder of the corresponding downloaded package with the PHP version I have (which is 5.5 for me) and everything worked.
The following fixed a similar issue for me (when the output of the gdb backtrace included libcurl.so and libcrypto.so):
disable /etc/php.d/pgsql.ini:
; Enable pgsql extension module
; extension=pgsql.so
edit /etc/php.d/curl.ini to ensure that pgsql.so is included before curl:
; Enable curl extension module
extension=pgsql.so
extension=curl.so
curl.cainfo=/home/statcounter/include/config/cacert.pem
if you have an object with property pointing to the same object, or other sort of pointer loops, you will have this message while running
serialize($object);
And if you are a Laravel user, and you are dealing with models. And if you think, you will never have this problem, because you avoiding pointer loops by using $hidden property on your models, please be advised, the $hidden property does not affect serialize, it only affects casting to JSON and array.
I had this problem, when I had a model saved into a property of a Mailable object.
fixed with
$this->model->refresh();
in a __construct method , just before the whole object is serialized.
This related to code not extension. In my case i had these two files
Test Case
Example Test
In Test Case there is method called createApplication. Just leave it empty.
In Example Test you can create the method and fill with
$this->assertTrue(true)
Above is basic setup hope you can extend the requirement as you need.
Related
After the latest update of PHP Intelephense that I get today, the intelephense keep showing an error for an undefined symbol for my route (and other class too), there is no error like this before and it's bothering me.
Here is the error screenshot :
And this is my code :
Route::group(['prefix' => 'user', 'namespace' => 'Membership', 'name' => 'user.'], function () {
Route::get('profile', 'ProfileController#show')->name('profile.show');
Route::patch('profile', 'ProfileController#update')->name('profile.update');
Route::patch('change-password', 'ChangePasswordController#change')->name('change-password');
Route::get('role', 'ProfileController#getRole')->name('profile.role');
Route::get('summary', 'SummaryController#show')->name('summary');
Route::get('reserved', 'AuctionController#reservedAuction')->name('reserved');
});
Actually there's no error in this code but the intelephense keeps showing an error so is there a way to fix this?
Intelephense 1.3 added undefined type, function, constant, class constant, method, and property diagnostics, where previously in 1.2 there was only undefined variable diagnostics.
Some frameworks are written in a way that provide convenient shortcuts for the user but make it difficult for static analysis engines to discover symbols that are available at runtime.
Stub generators like https://github.com/barryvdh/laravel-ide-helper help fill the gap here and using this with Laravel will take care of many of the false diagnostics by providing concrete definitions of symbols that can be easily discovered.
Still, PHP is a very flexible language and there may be other instances of false undefined symbols depending on how code is written. For this reason, since 1.3.3, intelephense has config options to enable/disable each category of undefined symbol to suit the workspace and coding style.
These options are:
intelephense.diagnostics.undefinedTypes
intelephense.diagnostics.undefinedFunctions
intelephense.diagnostics.undefinedConstants
intelephense.diagnostics.undefinedClassConstants
intelephense.diagnostics.undefinedMethods
intelephense.diagnostics.undefinedProperties
intelephense.diagnostics.undefinedVariables
Setting all of these to false except intelephense.diagnostics.undefinedVariables will give version 1.2 behaviour. See the VSCode settings UI and search for intelephense.
Version 1.3.0 has flaw IMO.
Downgrade to version 1.2.3 fixes my problem.
I'm on
Laravel 5.1
PHP 5.6.40
use Illuminate\Support\Facades\Route;
Warning Disappeared after importing the corresponding namespace.
Version's
Larvel 6+
vscode version 1.40.2
php intelephense 1.3.1
If you see this immediately after adding a new Vendor class, be sure to run the VScode command (control-shift-P) Index Workspace
In my case, for some reason, vendor folder was disabled on VS Code settings:
"intelephense.files.exclude": [
"**/.git/**",
"**/.svn/**",
"**/.hg/**",
"**/CVS/**",
"**/.DS_Store/**",
"**/node_modules/**",
"**/bower_components/**",
"**/vendor/**", <-- remove this line!
"**/resources/views/**"
],
By removing the line containing vendor folder it works ok on version Intelephense 1.5.4
This solution may help you if you know your problem is limited to Facades and you are running Laravel 5.5 or above.
Install laravel-ide-helper
composer require --dev barryvdh/laravel-ide-helper
Add this conditional statement in your AppServiceProvider to register the helper class.
public function register()
{
if ($this->app->environment() !== 'production') {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
// ...
}
Then run php artisan ide-helper:generate to generate a file to help the IDE understand Facades. You will need to restart Visual Studio Code.
References
https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/16
https://github.com/barryvdh/laravel-ide-helper
You don't need to downgrade you can:
Either disable undefined symbol diagnostics in the settings -- "intelephense.diagnostics.undefinedSymbols": false .
Or use an ide helper that adds stubs for laravel facades. See https://github.com/barryvdh/laravel-ide-helper
1.3.1 fixed it.
Just update your extension and you should be good to go
There is an other solution since version 1.7.1 (2021-05-02)
You can now tell where intelephense should look for a dependency, for example vendor which is the most common.
"intelephense.environment.includePaths": [
"vendor"
],
Furthermore, it even bypass the VSCode rule
"files.exclude": {
"**/vendor": true
},
You can read more in the changelog here
To those would prefer to keep it simple, stupid; If you rather get rid of the notices instead of installing a helper or downgrading, simply disable the error in your settings.json by adding this:
"intelephense.diagnostics.undefinedTypes": false
Here is I solved:
Open the extension settings:
And search for the variable you want to change, and unchecked/checked it
The variables you should consider are:
intelephense.diagnostics.undefinedTypes
intelephense.diagnostics.undefinedFunctions
intelephense.diagnostics.undefinedConstants
intelephense.diagnostics.undefinedClassConstants
intelephense.diagnostics.undefinedMethods
intelephense.diagnostics.undefinedProperties
intelephense.diagnostics.undefinedVariables
This is really a set of configurations for your editor to understand Laravel.
If you want to configure it all manually, here is the repo. This is for both VS code and PhpStorm.
Or if you want you can download this package.(I created) recommended to install it globally.
And then just run andylaravel setupIDE. this will configure everything for you according to the fist repo.
No, the errors occurs only after the Intelephense extension is automatically updated.
To solve the problem, you can downgrade it to the previous version by click "Install another version" in the Intelephense extension. There are no errors on version 1.2.3.
Had same problem in v1.7.1. It was showing error on built-in functions. But just found the solution: go to extension setting #ext:bmewburn.vscode-intelephense-client and disable one by one Intelephense›Diagnostics: and you will see the error showing will stop.
For anyone going through these issues and uneasy about disabling a whole set of checks, there is a way to pass your own custom signatures to Intelephense.
Copied from Intelephese repo's comment (by #KapitanOczywisty):
https://github.com/bmewburn/vscode-intelephense/issues/892#issuecomment-565852100
For single workspace it is very simple, you have to create .php file
with all signatures and intelephense will index them.
If you want add stubs globally, you still can, but I'm not sure if
it's intended feature. Even if intelephense.stubs throws warning about
incorrect value you can in fact put there any folder name.
{
"intelephense.stubs": [
// ...
"/path/to/your/stub"
]
}
Note: stubs are refreshed with this setting change.
You can take a look at build-in stubs here:
https://github.com/JetBrains/phpstorm-stubs
In my case, I needed dspec's describe, beforeEach, it... to don't be highlighted as errors, so I just included the file with the signatures /directories_and_paths/app/vendor/bin/dspec in my VSCode's workspace settings, which had the function declarations I needed:
function describe($description = null, \Closure $closure = null) {
}
function it($description, \Closure $closure) {
}
// ... and so on
use Illuminate\Support\Facades\Route;
Add the above Namespace
In your web.php
Add this line of code
use Illuminate\Support\Facades\Route;
Then you are done, again if you got Auth error then add this line of code
use Illuminate\Support\Facades\Auth;
Thanks.
The only working solution I found is:
Set language mode to Blade (use extension: Laravel Blade formatter)
It will resolve the issue. Otherwise, follow this procedure.
These classes don't exist in the workspace. Laravel creates them at runtime. As such they are reported as undefined. The solution is to either provide stub definitions
https://github.com/barryvdh/laravel-ide-helper
or turn off the diagnostics (intelephense.diagnostics.undefinedTypes).
I had the same issue and the following seemed to have addressed the issue.
a) Updated to latest version 1.3.5 and re-enabled all the diagnosis settings.
I was still getting the messages
b) Added the vendor folder with the dependent libraries to the workspace
This seems to have solved the problem.
I recently fixed my own issue. by going file > preferences
and I search for intelliphense
The section that has file to exclude, I noticed vendor folder was added.
I removed it, now all my laravel files are indexed
After the latest update of PHP Intelephense that I get today, the intelephense keep showing an error for an undefined symbol for my route (and other class too), there is no error like this before and it's bothering me.
Here is the error screenshot :
And this is my code :
Route::group(['prefix' => 'user', 'namespace' => 'Membership', 'name' => 'user.'], function () {
Route::get('profile', 'ProfileController#show')->name('profile.show');
Route::patch('profile', 'ProfileController#update')->name('profile.update');
Route::patch('change-password', 'ChangePasswordController#change')->name('change-password');
Route::get('role', 'ProfileController#getRole')->name('profile.role');
Route::get('summary', 'SummaryController#show')->name('summary');
Route::get('reserved', 'AuctionController#reservedAuction')->name('reserved');
});
Actually there's no error in this code but the intelephense keeps showing an error so is there a way to fix this?
Intelephense 1.3 added undefined type, function, constant, class constant, method, and property diagnostics, where previously in 1.2 there was only undefined variable diagnostics.
Some frameworks are written in a way that provide convenient shortcuts for the user but make it difficult for static analysis engines to discover symbols that are available at runtime.
Stub generators like https://github.com/barryvdh/laravel-ide-helper help fill the gap here and using this with Laravel will take care of many of the false diagnostics by providing concrete definitions of symbols that can be easily discovered.
Still, PHP is a very flexible language and there may be other instances of false undefined symbols depending on how code is written. For this reason, since 1.3.3, intelephense has config options to enable/disable each category of undefined symbol to suit the workspace and coding style.
These options are:
intelephense.diagnostics.undefinedTypes
intelephense.diagnostics.undefinedFunctions
intelephense.diagnostics.undefinedConstants
intelephense.diagnostics.undefinedClassConstants
intelephense.diagnostics.undefinedMethods
intelephense.diagnostics.undefinedProperties
intelephense.diagnostics.undefinedVariables
Setting all of these to false except intelephense.diagnostics.undefinedVariables will give version 1.2 behaviour. See the VSCode settings UI and search for intelephense.
Version 1.3.0 has flaw IMO.
Downgrade to version 1.2.3 fixes my problem.
I'm on
Laravel 5.1
PHP 5.6.40
use Illuminate\Support\Facades\Route;
Warning Disappeared after importing the corresponding namespace.
Version's
Larvel 6+
vscode version 1.40.2
php intelephense 1.3.1
If you see this immediately after adding a new Vendor class, be sure to run the VScode command (control-shift-P) Index Workspace
In my case, for some reason, vendor folder was disabled on VS Code settings:
"intelephense.files.exclude": [
"**/.git/**",
"**/.svn/**",
"**/.hg/**",
"**/CVS/**",
"**/.DS_Store/**",
"**/node_modules/**",
"**/bower_components/**",
"**/vendor/**", <-- remove this line!
"**/resources/views/**"
],
By removing the line containing vendor folder it works ok on version Intelephense 1.5.4
This solution may help you if you know your problem is limited to Facades and you are running Laravel 5.5 or above.
Install laravel-ide-helper
composer require --dev barryvdh/laravel-ide-helper
Add this conditional statement in your AppServiceProvider to register the helper class.
public function register()
{
if ($this->app->environment() !== 'production') {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
// ...
}
Then run php artisan ide-helper:generate to generate a file to help the IDE understand Facades. You will need to restart Visual Studio Code.
References
https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/16
https://github.com/barryvdh/laravel-ide-helper
You don't need to downgrade you can:
Either disable undefined symbol diagnostics in the settings -- "intelephense.diagnostics.undefinedSymbols": false .
Or use an ide helper that adds stubs for laravel facades. See https://github.com/barryvdh/laravel-ide-helper
1.3.1 fixed it.
Just update your extension and you should be good to go
There is an other solution since version 1.7.1 (2021-05-02)
You can now tell where intelephense should look for a dependency, for example vendor which is the most common.
"intelephense.environment.includePaths": [
"vendor"
],
Furthermore, it even bypass the VSCode rule
"files.exclude": {
"**/vendor": true
},
You can read more in the changelog here
To those would prefer to keep it simple, stupid; If you rather get rid of the notices instead of installing a helper or downgrading, simply disable the error in your settings.json by adding this:
"intelephense.diagnostics.undefinedTypes": false
Here is I solved:
Open the extension settings:
And search for the variable you want to change, and unchecked/checked it
The variables you should consider are:
intelephense.diagnostics.undefinedTypes
intelephense.diagnostics.undefinedFunctions
intelephense.diagnostics.undefinedConstants
intelephense.diagnostics.undefinedClassConstants
intelephense.diagnostics.undefinedMethods
intelephense.diagnostics.undefinedProperties
intelephense.diagnostics.undefinedVariables
This is really a set of configurations for your editor to understand Laravel.
If you want to configure it all manually, here is the repo. This is for both VS code and PhpStorm.
Or if you want you can download this package.(I created) recommended to install it globally.
And then just run andylaravel setupIDE. this will configure everything for you according to the fist repo.
No, the errors occurs only after the Intelephense extension is automatically updated.
To solve the problem, you can downgrade it to the previous version by click "Install another version" in the Intelephense extension. There are no errors on version 1.2.3.
Had same problem in v1.7.1. It was showing error on built-in functions. But just found the solution: go to extension setting #ext:bmewburn.vscode-intelephense-client and disable one by one Intelephense›Diagnostics: and you will see the error showing will stop.
For anyone going through these issues and uneasy about disabling a whole set of checks, there is a way to pass your own custom signatures to Intelephense.
Copied from Intelephese repo's comment (by #KapitanOczywisty):
https://github.com/bmewburn/vscode-intelephense/issues/892#issuecomment-565852100
For single workspace it is very simple, you have to create .php file
with all signatures and intelephense will index them.
If you want add stubs globally, you still can, but I'm not sure if
it's intended feature. Even if intelephense.stubs throws warning about
incorrect value you can in fact put there any folder name.
{
"intelephense.stubs": [
// ...
"/path/to/your/stub"
]
}
Note: stubs are refreshed with this setting change.
You can take a look at build-in stubs here:
https://github.com/JetBrains/phpstorm-stubs
In my case, I needed dspec's describe, beforeEach, it... to don't be highlighted as errors, so I just included the file with the signatures /directories_and_paths/app/vendor/bin/dspec in my VSCode's workspace settings, which had the function declarations I needed:
function describe($description = null, \Closure $closure = null) {
}
function it($description, \Closure $closure) {
}
// ... and so on
use Illuminate\Support\Facades\Route;
Add the above Namespace
In your web.php
Add this line of code
use Illuminate\Support\Facades\Route;
Then you are done, again if you got Auth error then add this line of code
use Illuminate\Support\Facades\Auth;
Thanks.
The only working solution I found is:
Set language mode to Blade (use extension: Laravel Blade formatter)
It will resolve the issue. Otherwise, follow this procedure.
These classes don't exist in the workspace. Laravel creates them at runtime. As such they are reported as undefined. The solution is to either provide stub definitions
https://github.com/barryvdh/laravel-ide-helper
or turn off the diagnostics (intelephense.diagnostics.undefinedTypes).
I had the same issue and the following seemed to have addressed the issue.
a) Updated to latest version 1.3.5 and re-enabled all the diagnosis settings.
I was still getting the messages
b) Added the vendor folder with the dependent libraries to the workspace
This seems to have solved the problem.
I recently fixed my own issue. by going file > preferences
and I search for intelliphense
The section that has file to exclude, I noticed vendor folder was added.
I removed it, now all my laravel files are indexed
I'm trying to get a TYPO3 v8 system updated to TYPO3 v9, but when it comes to unit-testing, I got some errors. I was able to fix some of them on my own but this one here's a very difficult one for me, because unit-testing is somewhat new to me in general.
I already searched the web, the TYPO3 documentation (which seems like the important parts are missing?), asked some friends and tried some things on my own, but nothing helped.
$this->environmentMock = $this->createMock(Environment::class);
$this->environmentMock->expects($this->once())
->method("::isCli")
->will($this->returnValue(TRUE));
I'm expecting to manually override the static function ::isCli() that comes with the Environment class. If that's not possible, is there any other "workaround", like setting a protected variable or something like that?
Currently this is my error message:
Trying to configure method "::isCli" which cannot be configured because it does not exist, has not been specified, is final, or is static
Thanks in advance!
Update 1:
After using #susis tip, I get the following error when appending the code:
TypeError: Return value of TYPO3\CMS\Core\Core\Environment::getContext() must be an instance of TYPO3\CMS\Core\Core\ApplicationContext, null returned
Additional information: My project is just an extension folder with TYPO3 v9 sources required in its own composer.json. No web, no htdocs, just the extension folder.
Update 2:
Here's a full gist of my test file.
Update 3:
Even the debugger isn't helping me in this case, see attached screenshot:
xdebug phpstorm applicationcontext environment screenshot
Update 4:
I updated the gist, added the environment vars to the phpunit.xml file and added parent::setUp() to the top of the setUp() method but the error is still the same:
TypeError : Return value of TYPO3\CMS\Core\Core\Environment::getContext() must be an instance of TYPO3\CMS\Core\Core\ApplicationContext, null returned
/Users/xyz/my_redirect/public/typo3/sysext/core/Classes/Core/Environment.php:97
/Users/xyz/my_redirect/Tests/Unit/Hooks/RequestHandlerHookTest.php:41
Update 5:
I updated the gist and removed the environment settings from the phpunit.xml due to what I've seen that they didn't work either. At this moment, the test is working but I'm still not sure if it's done the right way. Thanks for your help!
You can initialize the Environment you want in your tests, for example with:
Environment::initialize(
Environment::getContext(),
true,
false,
Environment::getProjectPath(),
Environment::getPublicPath(),
Environment::getVarPath(),
Environment::getConfigPath(),
Environment::getBackendPath() . '/index.php',
Environment::isWindows() ? 'WINDOWS' : 'UNIX'
);
This is the same way as it is done in TYPO3 Core tests and allows you to customize the complete environment. If you are using the TYPO3 testing framework / UnitTestCase base classes, you can use the property protected $backupEnvironment = true; to make sure the environment is reset after your test.
For an example, you can have a look at the ResourceCompressorIntegrationTest
I am very new to NetBeans and I just wanted to run a Code Coverage teston my code developed earlier. I do not know what I am doing wrong.
I am using NetBeans 7.3.1 with Wamp Server 2.4, installed PHPUnit and Skeleton Generator through PEAR, and set those files in NetBeans settings.
I made the project using an existing sources. Running in my browser seems OK. I can even debug with XDebug.
But when I right click on the project name and "Test", it says "No tests executed.(0.0 s)" in the Test Result window, and this in the Output window:
PHPUnit 3.7.23 by Sebastian Bergmann.
Configuration read from C:\wamp\www\test\configuration.xml
Time: 141 ms, Memory: 2.00Mb
No tests executed!
Generating code coverage report in Clover XML format ... done
I tried running test on a PHP file, it returns an information dialog box "Test file for the selected source file was not found."
I right clicked on the PHP file, and selected "Tools->Create PHPUnit tests", it returns a warning dialog box "Tests were not generated for the following files: (file name) Review the log in Output Window." but nothing was changed in the Output window.
I generated PHPUnit Bootstrap and XML Configuration, but they did not help.
I wished I can provide screenshots, but I cannot. I am trying to be specific as possible.
I appreciate any help.
I got this error too.. I also got this in the Output tab
Fatal error: Class 'package\path\Tests\TestCase' not found in project\path\package\path\Tests\ClientTest.php on line 25
Here, TestCase is the subclass of PHPUnit_Framework_TestCase and that, along with the current test file is in a different directory structure than the source files. So, in my case, it was a path issue.
Something I noted is I need to add a bootstrap file to include files in the test path and the source path to the runtime.
This bootstrap could be generated by NetBeans. See instructions here: https://netbeans.org/kb/docs/php/phpunit.html#project-specific-configurations
I of course, had another bootstrap.php (added by another developer). I only had to link the bootstrap like follows,
Good luck!
PHPUnits message:
No tests executed!
just means that no tests were found. This can have multiple reasons:
First of all, if there are no tests, no tests are executed.
But it is also possible that there are tests, but the configuration says to skip those (for example some tests are grouped into a group named slow and the configuration XML says to exclude slow from being run).
For your case this most certainly is a configuration issue. I'm not fluent with Netbeans but as you can successfully execute PHPUnit already, that part of your setup looks working.
Next step is to find out when you invoke the test-runner where it looks for tests. It might just be that the tests directory is missing or not specified. E.g. check which configuration is in configuration.xml for example and compare that with the documentation to double-check all settings.
This is not a very concrete answer and somebody who is more fluent with Netbeans might help more, however as you'er not showing further screenshots, this is my honest best bet how to go on with trouble-shooting and why.
Seems I am getting closer to the solution. I found out the problem is not in the configurations, but in the code itself.
I do not know if this is a silly problem, but seems the test only accepts PHP codes written in OOP. I tried making another file with a class and I can make test file out of it with no problem. At least I can see the test result changes from "No test executed" to "No test passed, 1 test skipped"
My codes are written for months without OOP and I know nothing about it at all. Does this mean I have to rewrite all of them again?
It will happen when you put an assertion in a constructor of your test class and this assertion fails.
Then you will see only the warning 'No tests executed!' (not very helpful) but i suppose one should not put assertions in the constructors (this is in phpunit 4.1~).
for it was because my test names were not starting with 'test'
EDIT 3: Solved. See below.
EDIT 2: I think Chadwick's on the right track with his comment. Hudson/PHPUnit is taking the localhost (the Hudson workspace) AND my local file structure and using both to run the unit tests. So it's redeclaring everything that was already declared. Why is this happening and how can I change it?
I've since reported this issue on Hudson's JIRA Server. If I get a resolution there, I'll post here. Otherwise, any help would be appreciated since my builds are going nowhere now.
My build keeps failing and I can't for the life of me understand why. Here's what I get back.
phpunit:
[exec] PHP Fatal error: Cannot redeclare generate_options() (previously declared in
<http://localhost:8080/job/Goals/ws/Goals/includes/functions/registration_fns.php>:5) in /Users
/joshsmith/Sites/Goals/Goals/includes/functions/registration_fns.php on line 32
But this particular function starts at line 5 and ends at line 32! So what in the world is going on here?
And just so you know PHPUnit works on its own outside of Hudson. Here's my terminal output from a successful test run:
Macintosh:goals joshsmith$ phpunit alltests.class
PHPUnit 3.4.14 by Sebastian Bergmann.
.............................
Time: 14 seconds, Memory: 9.75Mb
OK (29 tests, 67 assertions)
Can anyone help me figure this craziness out?
EDIT: Under Chadwick's suggestion, I tried renaming the function in case it were trying to redeclare a function internal to Hudson. This didn't work, and is clearly some other obscure issue.
This has been solved. It was an issue where I had hardcoded the paths in a single initializer file. As a result, they were being redeclared by PHPUnit.
It sounds like generate_options() is declared both in your registration_fns.php file and in some file by Hudson. PHP function names are global, so this is an inherent risk of combining code from a third party.
One way around it is to rename one of the functions (and of course all calls to it) - you can modify the Hudson code where it is declared, or modify your own, but personally I recommend changing your own. Should you upgrade Hudson in the future, you'd likely have to modify it again.
Since PHP 5.3, you also have the option of using namespaces.