Skip to content

Commit 810c15d

Browse files
committed
fix: phpstan errors
1 parent 53b984e commit 810c15d

File tree

8 files changed

+32
-60
lines changed

8 files changed

+32
-60
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ jobs:
4242
if: steps.cached-composer-dependencies.outputs.cache-hit != 'true'
4343
run: composer install
4444

45+
- name: 🛠️ Prepare environment
46+
run: |
47+
mkdir -p ./.build/php-cs-fixer
48+
mkdir -p ./.build/phpstan
49+
mkdir -p ./.build/phpunit
50+
4551
- name: 🚨 Run coding standards task
4652
run: composer cs:diff
4753
env:

src/Bridge/Laravel/Factories/Factory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ protected function store(Collection $results): void
119119
$orm = app(ORMInterface::class);
120120

121121
$repository = $orm->getRepository($this->modelName());
122+
// @phpstan-ignore-next-line
122123
$repository->persist($entity);
123124
});
124125
}

src/Testing/Concerns/InteractsWithDatabase.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66

77
use Cycle\Database\DatabaseProviderInterface;
88
use Exception;
9-
use Illuminate\Database\Eloquent\Model;
10-
use Illuminate\Database\Eloquent\SoftDeletes;
119
use PHPUnit\Framework\Constraint\Constraint;
1210
use PHPUnit\Framework\Constraint\LogicalNot as ReverseConstraint;
1311
use WayOfDev\Cycle\Testing\Constraints\CountInDatabase;
1412
use WayOfDev\Cycle\Testing\Constraints\HasInDatabase;
1513
use WayOfDev\Cycle\Testing\Constraints\NotSoftDeletedInDatabase;
1614
use WayOfDev\Cycle\Testing\Constraints\SoftDeletedInDatabase;
1715

18-
use function in_array;
19-
2016
/**
2117
* @method void assertThat($value, Constraint $constraint, string $message = '')
2218
*/
@@ -133,15 +129,6 @@ protected function assertNotSoftDeleted($table, array $data = [], $connection =
133129
return $this;
134130
}
135131

136-
/**
137-
* @param string|object $model
138-
*/
139-
protected function isSoftDeletableModel($model): bool
140-
{
141-
return $model instanceof Model
142-
&& in_array(SoftDeletes::class, class_uses_recursive($model));
143-
}
144-
145132
/**
146133
* @param string|object $table
147134
*/

src/Testing/Constraints/HasInDatabase.php

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66

77
use Cycle\Database\DatabaseInterface;
88
use Cycle\Database\DatabaseProviderInterface;
9+
use Cycle\Database\Query\SelectQuery;
910
use JsonException;
1011
use PHPUnit\Framework\Constraint\Constraint;
1112
use Throwable;
1213

13-
use function array_key_first;
14-
use function array_keys;
1514
use function json_encode;
1615
use function sprintf;
1716

@@ -30,11 +29,9 @@ public function __construct(DatabaseProviderInterface $database, array $data)
3029
$this->database = $database->database();
3130
}
3231

33-
/**
34-
* @param string $table
35-
*/
36-
public function matches($table): bool
32+
public function matches(mixed $table): bool
3733
{
34+
/** @var SelectQuery $tableInterface */
3835
$tableInterface = $this->database->table($table);
3936

4037
try {
@@ -52,10 +49,9 @@ public function matches($table): bool
5249
public function failureDescription(mixed $table): string
5350
{
5451
return sprintf(
55-
"a row in the table [%s] matches the attributes %s.\n\n%s",
52+
'a row in the table [%s] matches the attributes %s.',
5653
$table,
57-
$this->toString(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE),
58-
$this->getAdditionalInfo($table)
54+
$this->toString(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
5955
);
6056
}
6157

@@ -66,34 +62,4 @@ public function toString(int $options = 0): string
6662
{
6763
return json_encode($this->data, JSON_THROW_ON_ERROR | $options);
6864
}
69-
70-
protected function getAdditionalInfo(string $table): string
71-
{
72-
$query = $this->database->table($table);
73-
74-
$similarResults = $query->where(
75-
array_key_first($this->data),
76-
$this->data[array_key_first($this->data)]
77-
)->select(array_keys($this->data))->limit($this->show)->get();
78-
79-
if ($similarResults->isNotEmpty()) {
80-
$description = 'Found similar results: ' . json_encode($similarResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
81-
} else {
82-
$query = $this->database->table($table);
83-
84-
$results = $query->select(array_keys($this->data))->limit($this->show)->get();
85-
86-
if ($results->isEmpty()) {
87-
return 'The table is empty';
88-
}
89-
90-
$description = 'Found: ' . json_encode($results, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
91-
}
92-
93-
if ($query->count() > $this->show) {
94-
$description .= sprintf(' and %s others', $query->count() - $this->show);
95-
}
96-
97-
return $description;
98-
}
9965
}

src/Testing/Constraints/NotSoftDeletedInDatabase.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Cycle\Database\DatabaseInterface;
88
use Cycle\Database\DatabaseProviderInterface;
9+
use Cycle\Database\Query\SelectQuery;
910
use PHPUnit\Framework\Constraint\Constraint;
1011

1112
use function json_encode;
@@ -30,9 +31,12 @@ public function __construct(DatabaseProviderInterface $database, array $data, st
3031

3132
public function matches($table): bool
3233
{
33-
return $this->database->table($table)
34+
/** @var SelectQuery $query */
35+
$query = $this->database->table($table);
36+
37+
return $query
3438
->where($this->data)
35-
->whereNull($this->deletedAtColumn)
39+
->where($this->deletedAtColumn, null)
3640
->count() > 0;
3741
}
3842

@@ -53,11 +57,12 @@ public function toString(): string
5357

5458
protected function getAdditionalInfo($table)
5559
{
60+
/** @var SelectQuery $query */
5661
$query = $this->database->table($table);
5762

58-
$results = $query->limit($this->show)->get();
63+
$results = $query->limit($this->show)->fetchAll();
5964

60-
if ($results->isEmpty()) {
65+
if ([] === $results) {
6166
return 'The table is empty';
6267
}
6368

src/Testing/Constraints/SoftDeletedInDatabase.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Cycle\Database\DatabaseInterface;
88
use Cycle\Database\DatabaseProviderInterface;
9+
use Cycle\Database\Query\SelectQuery;
910
use PHPUnit\Framework\Constraint\Constraint;
1011

1112
use function json_encode;
@@ -30,9 +31,12 @@ public function __construct(DatabaseProviderInterface $database, array $data, st
3031

3132
public function matches($table): bool
3233
{
33-
return $this->database->table($table)
34+
/** @var SelectQuery $query */
35+
$query = $this->database->table($table);
36+
37+
return $query
3438
->where($this->data)
35-
->whereNotNull($this->deletedAtColumn)
39+
->where($this->deletedAtColumn, 'IS NOT', null)
3640
->count() > 0;
3741
}
3842

@@ -53,11 +57,12 @@ public function toString(): string
5357

5458
protected function getAdditionalInfo($table): string
5559
{
60+
/** @var SelectQuery $query */
5661
$query = $this->database->table($table);
5762

58-
$results = $query->limit($this->show)->get();
63+
$results = $query->limit($this->show)->fetchAll();
5964

60-
if ($results->isEmpty()) {
65+
if ([] === $results) {
6166
return 'The table is empty';
6267
}
6368

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

tests/app/database/migrations/cycle/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)