Hello,
I am having trouble running my PHPunit tests with xdebug on, and I think the problem might come from this package.
Until a recent change in my code, I had no problems running tests while my models were already using Eloquence. But today, I added 4 classes that inherit my Product model to provide different logics according to the type of product (Ex: AboProduct, StandardProduct...), which I think improves my code.
Here is how my Product model looks like:
namespace App;
use Illuminate\Database\Eloquent\Model;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Mappable;
class Product extends Model
{
use Eloquence, Mappable;
protected $maps = [
'name' => 'OLD_NAME',
'description' => 'OLD_DESCRIPTION',
'type' => 'OLD_TYPE',
];
/**
* Return an instance of a concrete product class
*
* @return ProductContract
*/
public function getConcrete()
{
$class = $this->resolveProductClass(); // Ex: 'App/AboProduct'
$model = new $class;
$model->exists = true;
$model->setRawAttributes((array) $this->getAttributes(), true);
return $model;
}
}
Here is how a concrete product class looks like:
namespace App;
class AboProduct extends Product implements ProductContract
{
public function performComplexCalculation()
{
// The ProductContract interface requires us to implement this
}
}
Here is how my controller looks like
namespace App\Http\Controllers;
use App\Product;
class ProductController extends Controller
{
public function getProductCalculation(Product $product)
{
return $product->getConcrete()->performComplexCalculation();
}
}
Now, as written above, I am having problems during my tests. Otherwise, everything works as intended. My tests are actually green and run without problem when I run them individually or filtered. It seems that the problem only happens when I run a large part of my test suite.
Here is the error that I get:
Fatal error: Maximum function nesting level of '256' reached, aborting! in /var/www/html/vendor/sofa/hookable/src/ArgumentBag.php on line 55
And here an extract of the stack trace (the last traces before it fails):
...
27.2507 75173272 200. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75173272 201. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2507 75173336 202. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75173336 203. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2507 75173400 204. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75173400 205. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2507 75173464 206. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75173464 207. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2507 75173528 208. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75173528 209. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2507 75173592 210. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75173592 211. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2507 75173656 212. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75173656 213. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2507 75173720 214. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75173720 215. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2507 75173784 216. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75173784 217. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2507 75173848 218. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75173848 219. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2507 75173912 220. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75173912 221. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2507 75173976 222. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75173976 223. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2507 75174040 224. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75174040 225. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2507 75174104 226. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2507 75174104 227. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75174168 228. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75174168 229. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75174232 230. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75174232 231. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75174296 232. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75174296 233. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75174360 234. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75174360 235. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75174424 236. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75174424 237. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75174488 238. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75174488 239. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75174552 240. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75174552 241. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75174616 242. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75174616 243. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75174680 244. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75174680 245. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75174744 246. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75174744 247. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75174808 248. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75174808 249. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75174872 250. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75174872 251. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75174936 252. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75174936 253. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75175000 254. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
27.2508 75175000 255. Sofa\Hookable\Pipeline->Sofa\Hookable\{closure}() /var/www/html/vendor/sofa/eloquence/src/Mappable/Hooks.php:111
27.2508 75175064 256. App\AboProduct->Sofa\Eloquence\Mappable\{closure}() /var/www/html/vendor/sofa/hookable/src/Pipeline.php:84
I don't really know what is going on, but seeing this stack trace I think here could be the right place to ask. I also suspect this might be related to #96 of @maltsev;
Hopefully someone can help :) Thanks
Please note that I'm using the v5.2.5 of Eloquence.