Skip to content

Commit 681468a

Browse files
committed
refactor: fix phpstan no type specified model tests
1 parent c134386 commit 681468a

File tree

4 files changed

+46
-178
lines changed

4 files changed

+46
-178
lines changed

tests/system/Models/InsertModelTest.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use CodeIgniter\I18n\Time;
2020
use CodeIgniter\Model;
2121
use Config\Database;
22+
use DateTimeInterface;
2223
use PHPUnit\Framework\Attributes\DataProvider;
2324
use PHPUnit\Framework\Attributes\Group;
2425
use stdClass;
@@ -194,13 +195,17 @@ public function testInsertResultFail(): void
194195
public function testInsertBatchNewEntityWithDateTime(): void
195196
{
196197
$entity = new class () extends Entity {
197-
protected $id;
198-
protected $name;
199-
protected $email;
200-
protected $country;
201-
protected $deleted;
202-
protected $created_at;
203-
protected $updated_at;
198+
protected int $id;
199+
protected string $name;
200+
protected string $email;
201+
protected string $country;
202+
protected bool $deleted;
203+
protected DateTimeInterface $created_at;
204+
protected DateTimeInterface $updated_at;
205+
206+
/**
207+
* @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}
208+
*/
204209
protected $_options = [
205210
'datamap' => [],
206211
'dates' => [
@@ -288,13 +293,17 @@ public function testInsertEntityWithNoDataExceptionNoAllowedData(): void
288293
$this->createModel(UserModel::class);
289294

290295
$entity = new class () extends Entity {
291-
protected $id;
292-
protected $name;
293-
protected $email;
294-
protected $country;
295-
protected $deleted;
296-
protected $created_at;
297-
protected $updated_at;
296+
protected int $id;
297+
protected string $name;
298+
protected string $email;
299+
protected string $country;
300+
protected bool $deleted;
301+
protected DateTimeInterface $created_at;
302+
protected DateTimeInterface $updated_at;
303+
304+
/**
305+
* @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}
306+
*/
298307
protected $_options = [
299308
'datamap' => [],
300309
'dates' => [

tests/system/Models/SaveModelTest.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use CodeIgniter\Entity\Entity;
1818
use CodeIgniter\I18n\Time;
1919
use CodeIgniter\Model;
20+
use DateTimeInterface;
2021
use PHPUnit\Framework\Attributes\Group;
2122
use stdClass;
2223
use Tests\Support\Models\EntityModel;
@@ -239,13 +240,17 @@ public function testEmptySaveData(): void
239240
public function testSaveNewEntityWithDateTime(): void
240241
{
241242
$entity = new class () extends Entity {
242-
protected $id;
243-
protected $name;
244-
protected $email;
245-
protected $country;
246-
protected $deleted;
247-
protected $created_at;
248-
protected $updated_at;
243+
protected int $id;
244+
protected string $name;
245+
protected string $email;
246+
protected string $country;
247+
protected bool $deleted;
248+
protected DateTimeInterface $created_at;
249+
protected DateTimeInterface $updated_at;
250+
251+
/**
252+
* @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}
253+
*/
249254
protected $_options = [
250255
'datamap' => [],
251256
'dates' => [
@@ -272,10 +277,14 @@ public function testSaveNewEntityWithDateTime(): void
272277
public function testSaveNewEntityWithDate(): void
273278
{
274279
$entity = new class () extends Entity {
275-
protected $id;
276-
protected $name;
277-
protected $created_at;
278-
protected $updated_at;
280+
protected int $id;
281+
protected string $name;
282+
protected DateTimeInterface $created_at;
283+
protected DateTimeInterface $updated_at;
284+
285+
/**
286+
* @var array{'datamap': array{}, 'dates': array{string, string, string}, 'casts': array{}}
287+
*/
279288
protected $_options = [
280289
'datamap' => [],
281290
'dates' => [
@@ -295,7 +304,7 @@ public function testSaveNewEntityWithDate(): void
295304
protected $returnType = 'object';
296305
protected $useSoftDeletes = true;
297306
protected $dateFormat = 'date';
298-
public $name = '';
307+
public string $name = '';
299308
};
300309

301310
$entity->name = 'Mark';

utils/phpstan-baseline/loader.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 2092 errors
1+
# total 2062 errors
22

33
includes:
44
- argument.type.neon

utils/phpstan-baseline/missingType.property.neon

Lines changed: 1 addition & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 77 errors
1+
# total 47 errors
22

33
parameters:
44
ignoreErrors:
@@ -236,153 +236,3 @@ parameters:
236236
message: '#^Property CodeIgniter\\Database\\Live\\MySQLi\\NumberNativeTest\:\:\$tests has no type specified\.$#'
237237
count: 1
238238
path: ../../tests/system/Database/Live/MySQLi/NumberNativeTest.php
239-
240-
-
241-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:196\:\:\$_options has no type specified\.$#'
242-
count: 1
243-
path: ../../tests/system/Models/InsertModelTest.php
244-
245-
-
246-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:196\:\:\$country has no type specified\.$#'
247-
count: 1
248-
path: ../../tests/system/Models/InsertModelTest.php
249-
250-
-
251-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:196\:\:\$created_at has no type specified\.$#'
252-
count: 1
253-
path: ../../tests/system/Models/InsertModelTest.php
254-
255-
-
256-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:196\:\:\$deleted has no type specified\.$#'
257-
count: 1
258-
path: ../../tests/system/Models/InsertModelTest.php
259-
260-
-
261-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:196\:\:\$email has no type specified\.$#'
262-
count: 1
263-
path: ../../tests/system/Models/InsertModelTest.php
264-
265-
-
266-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:196\:\:\$id has no type specified\.$#'
267-
count: 1
268-
path: ../../tests/system/Models/InsertModelTest.php
269-
270-
-
271-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:196\:\:\$name has no type specified\.$#'
272-
count: 1
273-
path: ../../tests/system/Models/InsertModelTest.php
274-
275-
-
276-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:196\:\:\$updated_at has no type specified\.$#'
277-
count: 1
278-
path: ../../tests/system/Models/InsertModelTest.php
279-
280-
-
281-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:290\:\:\$_options has no type specified\.$#'
282-
count: 1
283-
path: ../../tests/system/Models/InsertModelTest.php
284-
285-
-
286-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:290\:\:\$country has no type specified\.$#'
287-
count: 1
288-
path: ../../tests/system/Models/InsertModelTest.php
289-
290-
-
291-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:290\:\:\$created_at has no type specified\.$#'
292-
count: 1
293-
path: ../../tests/system/Models/InsertModelTest.php
294-
295-
-
296-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:290\:\:\$deleted has no type specified\.$#'
297-
count: 1
298-
path: ../../tests/system/Models/InsertModelTest.php
299-
300-
-
301-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:290\:\:\$email has no type specified\.$#'
302-
count: 1
303-
path: ../../tests/system/Models/InsertModelTest.php
304-
305-
-
306-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:290\:\:\$id has no type specified\.$#'
307-
count: 1
308-
path: ../../tests/system/Models/InsertModelTest.php
309-
310-
-
311-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:290\:\:\$name has no type specified\.$#'
312-
count: 1
313-
path: ../../tests/system/Models/InsertModelTest.php
314-
315-
-
316-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/InsertModelTest\.php\:290\:\:\$updated_at has no type specified\.$#'
317-
count: 1
318-
path: ../../tests/system/Models/InsertModelTest.php
319-
320-
-
321-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/SaveModelTest\.php\:241\:\:\$_options has no type specified\.$#'
322-
count: 1
323-
path: ../../tests/system/Models/SaveModelTest.php
324-
325-
-
326-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/SaveModelTest\.php\:241\:\:\$country has no type specified\.$#'
327-
count: 1
328-
path: ../../tests/system/Models/SaveModelTest.php
329-
330-
-
331-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/SaveModelTest\.php\:241\:\:\$created_at has no type specified\.$#'
332-
count: 1
333-
path: ../../tests/system/Models/SaveModelTest.php
334-
335-
-
336-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/SaveModelTest\.php\:241\:\:\$deleted has no type specified\.$#'
337-
count: 1
338-
path: ../../tests/system/Models/SaveModelTest.php
339-
340-
-
341-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/SaveModelTest\.php\:241\:\:\$email has no type specified\.$#'
342-
count: 1
343-
path: ../../tests/system/Models/SaveModelTest.php
344-
345-
-
346-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/SaveModelTest\.php\:241\:\:\$id has no type specified\.$#'
347-
count: 1
348-
path: ../../tests/system/Models/SaveModelTest.php
349-
350-
-
351-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/SaveModelTest\.php\:241\:\:\$name has no type specified\.$#'
352-
count: 1
353-
path: ../../tests/system/Models/SaveModelTest.php
354-
355-
-
356-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/SaveModelTest\.php\:241\:\:\$updated_at has no type specified\.$#'
357-
count: 1
358-
path: ../../tests/system/Models/SaveModelTest.php
359-
360-
-
361-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/SaveModelTest\.php\:274\:\:\$_options has no type specified\.$#'
362-
count: 1
363-
path: ../../tests/system/Models/SaveModelTest.php
364-
365-
-
366-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/SaveModelTest\.php\:274\:\:\$created_at has no type specified\.$#'
367-
count: 1
368-
path: ../../tests/system/Models/SaveModelTest.php
369-
370-
-
371-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/SaveModelTest\.php\:274\:\:\$id has no type specified\.$#'
372-
count: 1
373-
path: ../../tests/system/Models/SaveModelTest.php
374-
375-
-
376-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/SaveModelTest\.php\:274\:\:\$name has no type specified\.$#'
377-
count: 1
378-
path: ../../tests/system/Models/SaveModelTest.php
379-
380-
-
381-
message: '#^Property CodeIgniter\\Entity\\Entity@anonymous/tests/system/Models/SaveModelTest\.php\:274\:\:\$updated_at has no type specified\.$#'
382-
count: 1
383-
path: ../../tests/system/Models/SaveModelTest.php
384-
385-
-
386-
message: '#^Property CodeIgniter\\Model@anonymous/tests/system/Models/SaveModelTest\.php\:290\:\:\$name has no type specified\.$#'
387-
count: 1
388-
path: ../../tests/system/Models/SaveModelTest.php

0 commit comments

Comments
 (0)