Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions tests/_support/Models/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,4 @@ class UserModel extends Model
protected $returnType = 'object';
protected $useSoftDeletes = true;
protected $dateFormat = 'datetime';
public $name = '';
public $email = '';
public $country = '';
}
51 changes: 19 additions & 32 deletions tests/system/Models/InsertModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,19 @@ public function testInsertResultFail(): void
public function testInsertBatchNewEntityWithDateTime(): void
{
$entity = new class () extends Entity {
protected $id;
protected $name;
protected $email;
protected $country;
protected $deleted;
protected $created_at;
protected $updated_at;
protected $_options = [
'datamap' => [],
'dates' => [
'created_at',
'updated_at',
'deleted_at',
],
'casts' => [],
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',
];
};

Expand All @@ -219,13 +217,13 @@ public function testInsertBatchNewEntityWithDateTime(): void
$entity->name = 'Mark One';
$entity->email = 'markone@example.com';
$entity->country = 'India';
$entity->deleted = 0;
$entity->deleted_at = null;
$entity->created_at = new Time('now');

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

$this->setPrivateProperty($this->model, 'useTimestamps', true);
Expand Down Expand Up @@ -288,21 +286,10 @@ public function testInsertEntityWithNoDataExceptionNoAllowedData(): void
$this->createModel(UserModel::class);

$entity = new class () extends Entity {
protected $id;
protected $name;
protected $email;
protected $country;
protected $deleted;
protected $created_at;
protected $updated_at;
protected $_options = [
'datamap' => [],
'dates' => [
'created_at',
'updated_at',
'deleted_at',
],
'casts' => [],
protected $dates = [
'created_at',
'updated_at',
'deleted_at',
];
};

Expand Down
52 changes: 24 additions & 28 deletions tests/system/Models/SaveModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,19 @@ public function testEmptySaveData(): void
public function testSaveNewEntityWithDateTime(): void
{
$entity = new class () extends Entity {
protected $id;
protected $name;
protected $email;
protected $country;
protected $deleted;
protected $created_at;
protected $updated_at;
protected $_options = [
'datamap' => [],
'dates' => [
'created_at',
'updated_at',
'deleted_at',
],
'casts' => [],
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',
];
};

Expand All @@ -262,7 +260,7 @@ public function testSaveNewEntityWithDateTime(): void
$entity->name = 'Mark';
$entity->email = 'mark@example.com';
$entity->country = 'India';
$entity->deleted = 0;
$entity->deleted_at = null;
$entity->created_at = new Time('now');

$this->setPrivateProperty($this->model, 'useTimestamps', true);
Expand All @@ -272,18 +270,16 @@ public function testSaveNewEntityWithDateTime(): void
public function testSaveNewEntityWithDate(): void
{
$entity = new class () extends Entity {
protected $id;
protected $name;
protected $created_at;
protected $updated_at;
protected $_options = [
'datamap' => [],
'dates' => [
'created_at',
'updated_at',
'deleted_at',
],
'casts' => [],
protected $attributes = [
'id' => null,
'name' => null,
'created_at' => null,
'updated_at' => null,
];
protected $dates = [
'created_at',
'updated_at',
'deleted_at',
];
};

Expand Down
111 changes: 37 additions & 74 deletions tests/system/Models/UpdateModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use CodeIgniter\Entity\Entity;
use CodeIgniter\Exceptions\InvalidArgumentException;
use Config\Database;
use DateTimeInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use stdClass;
Expand Down Expand Up @@ -209,64 +208,34 @@ public function testUpdateBatchValidationFail(): void
public function testUpdateBatchWithEntity(): void
{
$entity1 = new class () extends Entity {
protected int $id;
protected string $name;
protected string $email;
protected string $country;
protected bool $deleted;
protected DateTimeInterface $created_at;
protected DateTimeInterface $updated_at;

/**
* @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}
*/
protected $_options = [
'datamap' => [],
'dates' => [
'created_at',
'updated_at',
'deleted_at',
],
'casts' => [],
protected $attributes = [
'id' => null,
'name' => null,
'country' => null,
'deleted_at' => null,
];
};

$entity2 = new class () extends Entity {
protected int $id;
protected string $name;
protected string $email;
protected string $country;
protected bool $deleted;
protected DateTimeInterface $created_at;
protected DateTimeInterface $updated_at;

/**
* @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}
*/
protected $_options = [
'datamap' => [],
'dates' => [
'created_at',
'updated_at',
'deleted_at',
],
'casts' => [],
protected $dates = [
'created_at',
'updated_at',
'deleted_at',
];
};

$entity1->id = 1;
$entity1->name = 'Jones Martin';
$entity1->country = 'India';
$entity1->deleted = 0;
$entity2 = clone $entity1;

$entity1->id = 1;
$entity1->name = 'Jones Martin';
$entity1->country = 'India';
$entity1->deleted_at = null;
$entity1->syncOriginal();
// Update the entity.
$entity1->country = 'China';

// This entity is not updated.
$entity2->id = 4;
$entity2->name = 'Jones Martin';
$entity2->country = 'India';
$entity2->deleted = 0;
$entity2->id = 4;
$entity2->name = 'Jones Martin';
$entity2->country = 'India';
$entity2->deleted_at = null;
$entity2->syncOriginal();

$model = $this->createModel(UserModel::class);
Expand Down Expand Up @@ -408,33 +377,27 @@ public function testUpdateWithEntityNoAllowedFields(): void
$this->createModel(UserModel::class);

$entity = new class () extends Entity {
protected int $id;
protected string $name;
protected string $email;
protected string $country;
protected bool $deleted;
protected DateTimeInterface $created_at;
protected DateTimeInterface $updated_at;

/**
* @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}
*/
protected $_options = [
'datamap' => [],
'dates' => [
'created_at',
'updated_at',
'deleted_at',
],
'casts' => [],
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',
];
};

$entity->id = 1;
$entity->name = 'Jones Martin';
$entity->email = 'jones@example.org';
$entity->country = 'India';
$entity->deleted = 0;
$entity->id = 1;
$entity->name = 'Jones Martin';
$entity->email = 'jones@example.org';
$entity->country = 'India';
$entity->deleted_at = null;

$id = $this->model->insert($entity);

Expand Down
2 changes: 1 addition & 1 deletion utils/phpstan-baseline/loader.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 2092 errors
# total 2063 errors

includes:
- argument.type.neon
Expand Down
Loading
Loading