Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong rgt-value when creating child node on PHP 7.2 #55

Open
nivv opened this issue May 3, 2018 · 2 comments
Open

Wrong rgt-value when creating child node on PHP 7.2 #55

nivv opened this issue May 3, 2018 · 2 comments
Labels

Comments

@nivv
Copy link

nivv commented May 3, 2018

Wrong rgt-value when creating child node on PHP 7.2

I have this test:

  /** @test **/
    public function store_category()
    {
        // Arrange
        $root = factory(\App\Category::class)->create( ['name' => 'Root', 'depth' => 0]);
    
        // Act
        $response = $this->actingAsAdmin('api')
        ->json('POST', $this->endpoint, [
            'name' => 'New Category',
            'parent_id' => $root->id,
        ]);
    
        // Assert
        $response->assertStatus(200);
        $response->assertJson([
            'tree' => [
                'root' => true,
                'name' => 'Root',
                'children' => [
                    [
                    'name'  => 'New Category',
                    'lft'   => 2,
                    'rgt'   => 3
                    ]
                ]
            ]
        ]);

        $this->assertDatabaseHas('categories', [
            'name' =>  'New Category',
            'slug' =>  'new-category',
            'lft'  =>  2,
            'rgt'  =>  3
        ]);
        $this->assertDatabaseHas('categories', [
            'name' =>  'Root',
            'lft'  =>  1,
            'rgt'  =>  4
        ]);
    }

This works on PHP 7.0 and PHP 7.1 but fails with PHP 7.2

To get the test to pass on PHP 7.2 the last assertion (the one checking the root in the database) has to be changed to below

        $this->assertDatabaseHas('categories', [
            'name' =>  'Root',
            'lft'  =>  1,
            'rgt'  =>  3
        ]);

The actual store function in my app

    public function store(CreateCategoryRequest $request)
    {
        $parent = $request->input('parent_id');
        $category = new Category;
        $category->fill($request->all());
        $category->save();
        $category->makeChildOf($parent);

        return $this->categoryTree($request, $category);
    }
@nivv
Copy link
Author

nivv commented May 4, 2018

This seems to be a problem with SQLite on PHP 7.2, test is working as expected when using a MySQL-database.

@aqlx86
Copy link

aqlx86 commented Sep 11, 2018

same issue php 7.0, mysql

@gazsp gazsp added the PHP7.2 label Sep 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants