Skip to content

Bug: BaseBuilder::updateBatch() may cause ArgumentCountError #6555

Closed
@kenjis

Description

@kenjis

PHP Version

8.1

CodeIgniter4 Version

4.3 (fee2620)

CodeIgniter4 Installation Method

Git

Which operating systems have you tested for this bug?

macOS

Which server did you use?

cli-server (PHP built-in webserver)

Database

No response

What happened?

ArgumentCountError : 4 arguments are required, 2 given
 /.../CodeIgniter4/system/Database/BaseBuilder.php:2330
 /.../CodeIgniter4/system/Database/BaseBuilder.php:2229
 /.../CodeIgniter4/tests/system/Database/Builder/UpdateTest.php:229

Steps to Reproduce

The following test fails.

    public function testUpdateBatch()
    {
        $builder = new BaseBuilder('%start', $this->db);

        $updateData = [
            [
                'id'          => 2,
                'name'        => 'Comedian',
                'description' => 'There\'s something in your teeth',
            ],
            [
                'id'          => 3,
                'name'        => 'Cab Driver',
                'description' => 'I am yellow',
            ],
        ];

        $this->db->shouldReturn('execute', 1)->shouldReturn('affectedRows', 1);
        $builder->updateBatch($updateData, 'id');

        $query = $this->db->getLastQuery();
        $this->assertInstanceOf(MockQuery::class, $query);

        $expected = <<<'EOF'
            UPDATE "%start"
            SET
            "name" = _u."name",
            "description" = _u."description"
            FROM (
            SELECT 2 "id", 'Comedian' "name", 'There''s something in your teeth' "description" UNION ALL
            SELECT 3 "id", 'Cab Driver' "name", 'I am yellow' "description"
            ) _u
            WHERE "%start"."id" = _u."id"
            EOF;

        $this->assertSame($expected, $query->getQuery());
    }

Expected Output

No error.

Anything else?

See #6373 (review)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions