Skip to content

Commit 063b6dc

Browse files
committed
fix: streamline temporary file path generation in tests
1 parent 6acd7cf commit 063b6dc

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

tests/src/Generators/DocBlockHeaderTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public function testToArrayWithAddStructureName(): void
307307

308308
public function testFromComposerWithSingleAuthor(): void
309309
{
310-
$testComposerPath = sys_get_temp_dir() . '/test-composer-' . uniqid() . '.json';
310+
$testComposerPath = sys_get_temp_dir().'/test-composer-'.uniqid().'.json';
311311
$composerData = [
312312
'name' => 'test/package',
313313
'authors' => [
@@ -332,7 +332,7 @@ public function testFromComposerWithSingleAuthor(): void
332332

333333
public function testFromComposerWithMultipleAuthors(): void
334334
{
335-
$testComposerPath = sys_get_temp_dir() . '/test-composer-' . uniqid() . '.json';
335+
$testComposerPath = sys_get_temp_dir().'/test-composer-'.uniqid().'.json';
336336
$composerData = [
337337
'name' => 'test/package',
338338
'authors' => [
@@ -359,7 +359,7 @@ public function testFromComposerWithMultipleAuthors(): void
359359

360360
public function testFromComposerWithAuthorWithoutEmail(): void
361361
{
362-
$testComposerPath = sys_get_temp_dir() . '/test-composer-' . uniqid() . '.json';
362+
$testComposerPath = sys_get_temp_dir().'/test-composer-'.uniqid().'.json';
363363
$composerData = [
364364
'name' => 'test/package',
365365
'authors' => [
@@ -382,7 +382,7 @@ public function testFromComposerWithAuthorWithoutEmail(): void
382382

383383
public function testFromComposerWithNoAuthors(): void
384384
{
385-
$testComposerPath = sys_get_temp_dir() . '/test-composer-' . uniqid() . '.json';
385+
$testComposerPath = sys_get_temp_dir().'/test-composer-'.uniqid().'.json';
386386
$composerData = [
387387
'name' => 'test/package',
388388
'license' => 'MIT',
@@ -402,7 +402,7 @@ public function testFromComposerWithNoAuthors(): void
402402

403403
public function testFromComposerWithNoLicense(): void
404404
{
405-
$testComposerPath = sys_get_temp_dir() . '/test-composer-' . uniqid() . '.json';
405+
$testComposerPath = sys_get_temp_dir().'/test-composer-'.uniqid().'.json';
406406
$composerData = [
407407
'name' => 'test/package',
408408
'authors' => [
@@ -424,7 +424,7 @@ public function testFromComposerWithNoLicense(): void
424424

425425
public function testFromComposerWithAdditionalAnnotations(): void
426426
{
427-
$testComposerPath = sys_get_temp_dir() . '/test-composer-' . uniqid() . '.json';
427+
$testComposerPath = sys_get_temp_dir().'/test-composer-'.uniqid().'.json';
428428
$composerData = [
429429
'name' => 'test/package',
430430
'authors' => [
@@ -452,7 +452,7 @@ public function testFromComposerWithAdditionalAnnotations(): void
452452

453453
public function testFromComposerWithCustomParameters(): void
454454
{
455-
$testComposerPath = sys_get_temp_dir() . '/test-composer-' . uniqid() . '.json';
455+
$testComposerPath = sys_get_temp_dir().'/test-composer-'.uniqid().'.json';
456456
$composerData = [
457457
'name' => 'test/package',
458458
'authors' => [

tests/src/Rules/DocBlockHeaderFixerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ public function testIsAnonymousClassWithAttribute(): void
952952
self::assertTrue($result);
953953
}
954954

955+
#[\PHPUnit\Framework\Attributes\RequiresPhp('>= 8.2')]
955956
public function testIsAnonymousClassWithReadonlyModifier(): void
956957
{
957958
$code = '<?php $obj = new readonly class {};';
@@ -974,6 +975,7 @@ public function testIsAnonymousClassWithReadonlyModifier(): void
974975
self::assertTrue($result);
975976
}
976977

978+
#[\PHPUnit\Framework\Attributes\RequiresPhp('>= 8.2')]
977979
public function testSkipsAnonymousClassWithReadonlyModifier(): void
978980
{
979981
$code = '<?php $obj = new readonly class {};';

tests/src/Service/ComposerServiceTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class ComposerServiceTest extends TestCase
3333

3434
protected function setUp(): void
3535
{
36-
$this->testComposerJsonPath = sys_get_temp_dir() . '/test-composer-' . uniqid() . '.json';
36+
$this->testComposerJsonPath = sys_get_temp_dir().'/test-composer-'.uniqid().'.json';
3737
}
3838

3939
protected function tearDown(): void
@@ -71,7 +71,7 @@ public function testReadComposerJsonThrowsExceptionWhenFileDoesNotExist(): void
7171
public function testReadComposerJsonThrowsExceptionWhenFileCannotBeRead(): void
7272
{
7373
// Create an empty directory to simulate unreadable file
74-
$dirPath = sys_get_temp_dir() . '/test-dir-' . uniqid();
74+
$dirPath = sys_get_temp_dir().'/test-dir-'.uniqid();
7575
mkdir($dirPath);
7676

7777
$this->expectException(RuntimeException::class);
@@ -88,7 +88,7 @@ public function testReadComposerJsonThrowsExceptionWhenFileCannotBeRead(): void
8888
public function testReadComposerJsonThrowsExceptionOnReadFailure(): void
8989
{
9090
// Create a file with no read permissions to force file_get_contents to return false
91-
$invalidPath = sys_get_temp_dir() . '/test-unreadable-' . uniqid() . '.json';
91+
$invalidPath = sys_get_temp_dir().'/test-unreadable-'.uniqid().'.json';
9292
file_put_contents($invalidPath, '{}');
9393

9494
// Make file unreadable (this may not work on all systems, especially Windows)
@@ -171,9 +171,12 @@ public function testExtractAuthorsWithValidAuthors(): void
171171

172172
self::assertCount(2, $result);
173173
self::assertSame('John Doe', $result[0]['name']);
174+
/* @phpstan-ignore-next-line offsetAccess.notFound */
174175
self::assertSame('john@example.com', $result[0]['email']);
176+
/* @phpstan-ignore-next-line offsetAccess.notFound */
175177
self::assertSame('Developer', $result[0]['role']);
176178
self::assertSame('Jane Smith', $result[1]['name']);
179+
/* @phpstan-ignore-next-line offsetAccess.notFound */
177180
self::assertSame('jane@example.com', $result[1]['email']);
178181
}
179182

@@ -241,6 +244,7 @@ public function testGetPrimaryAuthor(): void
241244

242245
self::assertNotNull($result);
243246
self::assertSame('John Doe', $result['name']);
247+
/* @phpstan-ignore-next-line offsetAccess.notFound */
244248
self::assertSame('john@example.com', $result['email']);
245249
}
246250

0 commit comments

Comments
 (0)