Laravel says my public function is still undefined [duplicate] - php

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

Related

Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error

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

How to mock, use or override Environment::isCli() in TYPO3 v9 unit tests

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

Laravel Intellisense / autocomplete with PhpStorm

Trying to get a clean environment to work on Laravel 5.4 / PhpStorm.
Followed all the instructions from: https://github.com/barryvdh/laravel-ide-helper (including installing the PhpStorm Laravel plugin)
Got the file_ide_helper.php generated, added
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
to its proper location, cleared cache, restarted...
Please look at attached image, is the lack of intellisense I get supposed to be fixed by the ide helper ?
Ok here is the solution, assuming you have installed the helper already:
Example:
Replace in a controller:
use Illuminate\Support\Facades\Validator;
by
use Validator
In your config/app.php you must have this alias:
'Validator' => Illuminate\Support\Facades\Validator::class,
In my case it was already there.
After this, no more error message for the example shown in the image above and I can use full power of phpstorm that correctly understands the ::make method.
Source https://github.com/barryvdh/laravel-ide-helper/issues/431#issuecomment-275898789 thanks #lazyone.

"Member has private access error" after deleting plugin in CakePHP using PhpStorm

After deleting a plugin from my CakePHP Framework and all the lines of code associated with it I get an error in the getInitializer function of the autoload_static.php in my vendor->composer folder:
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit8835d383dd0f2dc92619594332e8ea7e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit8835d383dd0f2dc92619594332e8ea7e::$prefixDirsPsr4;
$loader->prefixesPsr0 = ComposerStaticInit8835d383dd0f2dc92619594332e8ea7e::$prefixesPsr0;
$loader->classMap = ComposerStaticInit8835d383dd0f2dc92619594332e8ea7e::$classMap;
}, null, ClassLoader::class);
}
All the prefixes and the classMap are underlined and the error message says:
"Member has private access"
I'm fairly new to PHP, so my question would be how to handle this error? I suppose it's not safe to just delete this 4 lines of code.
I already tried to update composer and invalidate caches/restart in PhpStorm.
EDIT 1
I surely shouldn't have deleted the lines of code related to the old plugin manually out of the composer files.
composer diagnose:
Checking composer.json: FAIL
require.cakephp/plugin-installer : unbound version constraints (*) should be avoided
Checking platform settings: FAIL
The OpenSSL library (0.9.8y) used by PHP does not support TLSv1.2 or TLSv1.1.
If possible you should upgrade OpenSSL to version 1.0.1 or above.
Checking git settings: OK
Checking http connectivity to packagist: Warning: Accessing packagist.org over http which is an insecure protocol.
As the project isn't too old, it might be the easiest way just to delete it completely and restart from scratch or is there an easy solution to that?
The lines are technically incorrectly highlighted as errors, and they were highlighted as errors even before you've modified the code.
The code will bind a specific object and scope to a closure, in this case it will bind the $loader object (an instance of ClassLoader) with the ClassLoader::class scope. This will cause the closure to be bound to the $loader object in a way that makes private methods visible to it, and hence things won't error out at runtime.
So the problem is just that the PhpStorm parser isn't smart enough (yet) to recognize this.
See also http://www.php.net/manual/en/closure.bind.php
As far as your other composer problems are concerned, vendor files should always be safe to delete, ie the vendor folder should normally only contain code installed through composer, which means that in case you screw things up big, you should be able to simply delete the vendor folder, fix up your composer.json file (and delete the composer.lock file) if necessary, and then just run the composer update or composer install command again.

PHPUnit Segmentation fault

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.

Categories