lazychaser / laravel-nestedset

Effective tree structures in Laravel 4-8
3.66k stars 473 forks source link

Tests testDescendants & testAncestors are failing #334

Open antonkomarev opened 5 years ago

antonkomarev commented 5 years ago

PHP 7.1.26 Laravel 5.7.19 Branch v4 (as it seems to be the latest one)

Possibly related to PR #315

I just cloned your repo, made composer install and executed vendor/bin/phpunit.

1) ScopedNodeTest::testDescendants
Failed asserting that 0 matches expected 1.

/code/laravel-nestedset/tests/ScopedNodeTest.php:106

2) ScopedNodeTest::testAncestors
Failed asserting that 0 matches expected 1.

/code/laravel-nestedset/tests/ScopedNodeTest.php:123
kelyak commented 5 years ago

Strange, I ran the test before making the PR. I'll try to find some time to look into it this week-end.

kelyak commented 5 years ago

Could the issue be related to the laravel version ? Because I tried with php 5.6 and 7.2 without issue

jariwiklund commented 5 years ago

I have the same issue with laravel 5.7.22 The bug seems to stem from the inner Eloquent handling of Model-properties. If I simply add a $parentNode->ancestors; call in my code, after the $parentNode->appendNode($node); call, the bug seems to be worked around regarding ancestors. But how this should be implemented in the NodeTrait, so that Capsule::table('menu_items')->insert($data); will make the test succeed, I am very unsure of.

Ciaro commented 5 years ago

I have provided a fix for this in my fork: https://github.com/Ciaro/laravel-nestedset/commits/fix-scoped-relationships: have a look and see if it fixes the issue for you :)

antonkomarev commented 5 years ago

@Ciaro that's better to post as PR in this repository.

Ciaro commented 5 years ago

@antonkomarev Hi, I prepared a PR for this. This will however require a new v5 cause of the BC towards lower Laravel versions.