Skip to content

Commit 6dc1349

Browse files
committed
PHPStan 2.0.2
1 parent 51c8e88 commit 6dc1349

7 files changed

+32
-47
lines changed

Tests/Feature/ElasticsearchAuditServiceTest.php

+25-17
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function testIndexDocument(bool $shouldReturnResult, ?bool $expectedResul
6464
{
6565
Config::set('audit.drivers.queue.enabled', $shouldUseQueue);
6666
Queue::fake();
67+
/** @var array<string, mixed> */
6768
$user = $this->getUser()->toArray();
6869
$service = $this->getService(
6970
statuses: [200],
@@ -77,7 +78,7 @@ public function testIndexDocument(bool $shouldReturnResult, ?bool $expectedResul
7778

7879
if ($shouldUseQueue) {
7980
Queue::assertPushed(IndexAuditDocumentJob::class,
80-
fn($job): bool => 'audits' === $job->queue
81+
fn(IndexAuditDocumentJob $job): bool => 'audits' === $job->queue
8182
&& 'redis' === $job->connection
8283
);
8384
}
@@ -91,18 +92,20 @@ public function testIndexDocument(bool $shouldReturnResult, ?bool $expectedResul
9192
public function testSearchDocument(): void
9293
{
9394
$user = $this->getUser();
95+
/** @var array<string, mixed> */
96+
$userArray = $user->toArray();
9497
$service = $this->getService(
9598
statuses: [200, 200, 200],
96-
bodies: [null, null, $user->toArray()],
99+
bodies: [null, null, $userArray],
97100
shouldBind: true,
98101
);
99-
$service->indexDocument($user->toArray());
102+
$service->indexDocument($userArray);
100103
$service->indexDocument(['name' => 'Not John Doe']);
101104

102105
$result = $service->searchAuditDocument($user);
103106

104107
static::assertTrue($result->asBool());
105-
static::assertSame($user->toArray(), $result->asArray());
108+
static::assertSame($userArray, $result->asArray());
106109
}
107110

108111
/**
@@ -111,12 +114,14 @@ public function testSearchDocument(): void
111114
public function testSearch(): void
112115
{
113116
$user = $this->getUser();
117+
/** @var array<string, mixed> */
118+
$userArray = $user->toArray();
114119
$service = $this->getService(
115120
statuses: [200, 200, 200],
116-
bodies: [null, null, $user->toArray()],
121+
bodies: [null, null, $userArray],
117122
shouldBind: true,
118123
);
119-
$service->indexDocument($user->toArray());
124+
$service->indexDocument($userArray);
120125
$service->indexDocument([
121126
'id' => 314159,
122127
'name' => 'Not John Doe',
@@ -137,7 +142,7 @@ public function testSearch(): void
137142
->search(query: $query);
138143

139144
static::assertTrue($result->asBool());
140-
static::assertSame($user->toArray(), $result->asArray());
145+
static::assertSame($userArray, $result->asArray());
141146
}
142147

143148
/**
@@ -146,12 +151,14 @@ public function testSearch(): void
146151
public function testCount(): void
147152
{
148153
$user = $this->getUser();
154+
/** @var array<string, mixed> */
155+
$userArray = $user->toArray();
149156
$service = $this->getService(
150157
statuses: [200, 200, 200],
151158
bodies: [null, null, ['count' => 1]],
152159
shouldBind: true,
153160
);
154-
$service->indexDocument($user->toArray());
161+
$service->indexDocument($userArray);
155162
$service->indexDocument([
156163
'id' => 314159,
157164
'name' => 'Not John Doe',
@@ -184,13 +191,15 @@ public function testCount(): void
184191
public function testDeleteDocument(): void
185192
{
186193
$user = $this->getUser();
194+
/** @var array<string, mixed> */
195+
$userArray = $user->toArray();
187196
$service = $this->getService(
188197
statuses: [200, 200, 200],
189198
bodies: [],
190199
shouldBind: true,
191200
);
192201

193-
$service->indexDocument($user->toArray());
202+
$service->indexDocument($userArray);
194203
$service->indexDocument(['name' => 'Not John Doe']);
195204

196205
$result = $service->deleteAuditDocument($user->id, true);
@@ -221,25 +230,24 @@ public function testPruneDocument(int $threshold, bool $expectedResult): void
221230
public function testAudit(): void
222231
{
223232
Config::set('audit.user.resolver', UserResolver::class);
224-
$service = $this->getService(
225-
statuses: [200, 200],
226-
bodies: [],
227-
shouldBind: true,
228-
);
229233
$user = User::create([
230234
'name' => 'test',
231235
'email' => '[email protected]',
232236
'password' => Hash::make('a_very_strong_password'),
233237
]);
238+
$service = $this->getService(
239+
statuses: [200, 200],
240+
bodies: [null, $user->toArray()],
241+
shouldBind: true,
242+
);
243+
234244
$user->isCustomEvent = true;
235245
$user->setAuditEvent('saving');
236246
$result = $service->audit($user);
237247

238-
static::assertInstanceOf(Audit::class, $result);
239-
240248
$searchResult = $service->searchAuditDocument($user);
241249
static::assertTrue($searchResult->asBool());
242-
static::assertSame($searchResult->asArray(), $searchResult->asArray());
250+
static::assertSame($searchResult->asArray(), $user->toArray());
243251
}
244252

245253
/**

Tests/Feature/ElasticsearchClientTest.php

+1-25
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,6 @@
1313
*/
1414
class ElasticsearchClientTest extends TestCase
1515
{
16-
/**
17-
* @throws Exception
18-
*/
19-
public function testSetClient(): void
20-
{
21-
$client = resolve(ElasticsearchClient::class)
22-
->setClient();
23-
24-
static::assertInstanceOf(ElasticsearchClient::class, $client);
25-
}
26-
2716
/**
2817
* @throws Exception
2918
*/
@@ -40,18 +29,5 @@ public function testSetCaBundle(): void
4029
$caBundlePath = $client->getCaBundlePath();
4130

4231
static::assertSame($caBundlePath, '/find-me');
43-
static::assertInstanceOf(ElasticsearchClient::class, $client);
44-
}
45-
46-
/**
47-
* @throws Exception
48-
*/
49-
public function testBasicAuth(): void
50-
{
51-
Config::set('audit.drivers.elastic.useBasicAuth', false);
52-
$client = resolve(ElasticsearchClient::class)
53-
->setClient();
54-
55-
static::assertInstanceOf(ElasticsearchClient::class, $client);
5632
}
57-
}
33+
}

Tests/Model/User.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use Illuminate\Database\Eloquent\Factories\HasFactory;
66
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Support\Collection;
78
use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
89
use rajmundtoth0\AuditDriver\Traits\ElasticSearchAuditable;
10+
use Carbon\Carbon;
911

1012
/**
1113
* @property int $id

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"larastan/larastan": "*",
4848
"orchestra/testbench": "^8.21|^9.0",
4949
"php-http/mock-client": "^1.6",
50-
"phpstan/phpstan": "^1.10",
50+
"phpstan/phpstan": "^2.0.2",
5151
"phpstan/phpstan-phpunit": "*",
5252
"phpunit/phpunit": "^11.0",
5353
"nyholm/psr7": "^1.8"

src/Client/ElasticsearchClient.php

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public function setHosts(): void
124124
*/
125125
public function updateAliases(string $index): Elasticsearch|Promise
126126
{
127+
$params = [];
127128
$params['body'] = [
128129
'actions' => [
129130
[

src/Models/DocumentModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public function __construct(
88
protected readonly string $index,
99
protected readonly string $type,
1010
protected readonly string $id,
11-
/** @var array<string, mixed> */
11+
/** @var array<mixed> */
1212
protected array $body,
1313
) {
1414
if (!array_key_exists('created_at', $this->body)) {

src/Services/ElasticsearchAuditService.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public function audit(Auditable $model): Audit
8888
{
8989
$this->indexDocument($model->toAudit());
9090
$implementation = new $this->implementation();
91-
assert($implementation instanceof Audit);
9291

9392
return $implementation;
9493
}
@@ -114,7 +113,7 @@ public function prune(Auditable $model, bool $shouldReturnResult = false): bool
114113
}
115114

116115
/**
117-
* @param array<string, mixed> $model
116+
* @param array<mixed> $model
118117
*
119118
* @throws AuditDriverException
120119
* @throws ClientResponseException
@@ -170,7 +169,6 @@ public function searchAuditDocument(
170169

171170
$key = $model->getKey();
172171

173-
assert(method_exists($model, 'getMorphClass'));
174172
$params = [
175173
'index' => $this->index,
176174
'type' => $this->auditType,

0 commit comments

Comments
 (0)