Skip to content

refactor: fix phpstan no type specified model tests#10022

Open
adiprsa wants to merge 1 commit intocodeigniter4:developfrom
adiprsa:fix/PHPSTAN-no-type-specified-ModelTest
Open

refactor: fix phpstan no type specified model tests#10022
adiprsa wants to merge 1 commit intocodeigniter4:developfrom
adiprsa:fix/PHPSTAN-no-type-specified-ModelTest

Conversation

@adiprsa
Copy link
Contributor

@adiprsa adiprsa commented Mar 6, 2026

Description
#7731

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

/**
* @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}
*/
protected $_options = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stop.
@michalsn @paulbalandan
It all looks like a dead code. Can you tell me where the array is currently being used and how to set the properties in the object?

this is the behavior of v4.0.x only then there was an options array and attributes appeared later.

I assume all Entity tests need to be reviewed again.

@adiprsa right now I'm not sure if the tests are correct, at least we use $attributes instead of object properties. Plus $deleted doesn't seem to exist (deleted_at)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found PR #2002

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests should be similar:

    public function testInsertBatchNewEntityWithDateTime(): void
    {
        $entity = new class () extends Entity {
            protected $attributes = [
                'id'         => null,
                'name'       => null,
                'email'      => null,
                'country'    => null,
                'deleted_at' => null,
                'created_at' => null,
                'updated_at' => null,
            ];
            protected $dates = [
                'created_at',
                'updated_at',
                'deleted_at',
            ];
        };

        $entityTwo = clone $entity;

        $this->createModel(UserModel::class);

        $entity->name       = 'Mark One';
        $entity->email      = 'markone@example.com';
        $entity->country    = 'India';
        $entity->deleted_at = null;
        $entity->created_at = new Time('now');

        $entityTwo->name       = 'Mark Two';
        $entityTwo->email      = 'marktwo@example.com';
        $entityTwo->country    = 'India';
        $entityTwo->deleted_at = null;
        $entityTwo->created_at = $entity->created_at;

        $this->setPrivateProperty($this->model, 'useTimestamps', true);
        $this->assertSame(2, $this->model->insertBatch([$entity, $entityTwo]));
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems correct - these tests should be updated. Good catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants