phpstan level 8 preparation

This commit is contained in:
Spine
2025-07-28 16:55:16 +02:00
parent 889766f032
commit 3e9b2bcb4f
37 changed files with 560 additions and 330 deletions
+30 -24
View File
@@ -42,13 +42,13 @@ class ReportManagerTest extends TestCase {
tagList: 'disco funk metal',
);
$manager = new Manager\Report(new Manager\User());
$report = $manager->create($this->userList[1], $this->collage->id(), 'collage', 'phpunit collage report');
$report = $manager->create($this->userList[1], $this->collage->id, 'collage', 'phpunit collage report');
$this->reportList[] = $report;
$this->assertEquals("phpunit collage report", $report->reason(), 'collage-report-reason');
$this->assertEquals($this->collage->id(), $report->subjectId(), 'collage-report-subject-id');
$this->assertEquals($this->collage->id, $report->subjectId(), 'collage-report-subject-id');
$this->assertEquals(1, $report->resolve($this->userList[0]));
$reportSubject = new Report\Collage($report->id(), $this->collage);
$reportSubject = new Report\Collage($report->id, $this->collage);
$this->assertFileExists(TEMPLATE_PATH . $reportSubject->template(), 'collage-report-template');
$this->assertStringContainsString($this->collage->url(), $reportSubject->bbLink(), 'collage-report-bblink');
$this->assertEquals('Collage Report: ', $reportSubject->titlePrefix(), 'collage-report-title-prefix');
@@ -56,10 +56,12 @@ class ReportManagerTest extends TestCase {
}
public function testReportRequest(): void {
$categoryId = (new Manager\Category())->findIdByName('Comics');
$this->assertNotNull($categoryId, 'report-cat-not-null');
$this->request = (new Manager\Request())->create(
user: $this->userList[1],
bounty: REQUEST_MIN * 1024 * 1024,
categoryId: (new Manager\Category())->findIdByName('Comics'),
categoryId: $categoryId,
year: (int)date('Y'),
title: 'phpunit request report',
image: '',
@@ -78,17 +80,17 @@ class ReportManagerTest extends TestCase {
$manager = new Manager\Report(new Manager\User());
$initial = $manager->remainingTotal();
$report = $manager->create($this->userList[1], $this->request->id(), 'request', 'phpunit report');
$report = $manager->create($this->userList[1], $this->request->id, 'request', 'phpunit report');
$this->reportList[] = $report;
$this->assertEquals($initial + 1, $manager->remainingTotal(), 'request-report-one-more');
$this->assertEquals('New', $report->status(), 'request-report-status-new');
$this->assertEquals('phpunit report', $report->reason(), 'request-report-reason');
$this->assertEquals($this->userList[1]->id(), $report->reporter()?->id(), 'request-report-reporter-id');
$this->assertEquals($this->userList[1]->id, $report->reporter()?->id, 'request-report-reporter-id');
$this->assertEquals('request', $report->subjectType(), 'request-report-subject-type');
$this->assertEquals($this->request->id(), $report->subjectId(), 'request-report-subject-id');
$this->assertEquals($this->request->id, $report->subjectId(), 'request-report-subject-id');
$this->assertEquals(
"<a href=\"reports.php?id={$report->id()}#report{$report->id()}\">Report #{$report->id()}</a>",
"<a href=\"reports.php?id={$report->id}#report{$report->id}\">Report #{$report->id}</a>",
$report->link(),
'request-report-link'
);
@@ -99,7 +101,7 @@ class ReportManagerTest extends TestCase {
$this->assertFalse($report->isClaimed(), 'request-report-not-yet-claimed');
// report specifics
$reqReport = new Report\Request($report->id(), $this->request);
$reqReport = new Report\Request($report->id, $this->request);
$this->assertFileExists(TEMPLATE_PATH . $reqReport->template(), 'request-report-template');
$this->assertStringContainsString($this->request->url(), $reqReport->bbLink(), 'request-report-bblink');
$this->assertEquals('Request Report: ', $reqReport->titlePrefix(), 'request-report-title-prefix');
@@ -117,14 +119,14 @@ class ReportManagerTest extends TestCase {
$this->assertEquals('InProgress', $report->flush()->status(), 'request-report-in-progress');
$claimer = $report->claimer();
$this->assertNotNull($claimer, 'request-report-has-claimer'); /** @phpstan-ignore-line phpstan cannot decide if $resolver is null or not */
$this->assertEquals($this->userList[0]->id(), $claimer->id(), 'request-report-claimer-id');
$this->assertEquals($this->userList[0]->id, $claimer->id, 'request-report-claimer-id');
$this->assertEquals(1, $report->claim(null), 'request-report-unclaim');
$this->assertFalse($report->isClaimed(), 'request-report-is-unclaimed');
// search
$this->assertCount(
1,
(new Search\Report())->setId($report->id())->page(2, 0),
(new Search\Report())->setId($report->id)->page(2, 0),
'request-report-search-id'
);
$this->assertEquals(
@@ -142,7 +144,7 @@ class ReportManagerTest extends TestCase {
$total = $search->setStatus(['InProgress'])->total();
$page = $search->page($total, 0);
$this->assertEquals($total, count($page), 'request-report-page-list');
$this->assertEquals($report->id(), $page[0], 'request-report-page-id');
$this->assertEquals($report->id, $page[0], 'request-report-page-id');
// resolve
$this->assertEquals(1, $report->resolve($this->userList[0]), 'request-report-claim');
@@ -150,31 +152,31 @@ class ReportManagerTest extends TestCase {
$this->assertEquals('Resolved', $report->status(), 'request-report-resolved-status');
$resolver = $report->resolver();
$this->assertNotNull($resolver, 'request-report-has-resolver'); /** @phpstan-ignore-line phpstan cannot decide if $resolver is null or not */
$this->assertEquals($this->userList[0]->id(), $resolver->id(), 'request-report-resolver-id');
$this->assertEquals($this->userList[0]->id, $resolver->id, 'request-report-resolver-id');
$this->assertEquals($initial, $manager->remainingTotal(), 'request-report-initial-total');
}
public function testReportUser(): void {
$manager = new Manager\Report(new Manager\User());
$report = $manager->create($this->userList[0], $this->userList[1]->id(), 'user', 'phpunit user report');
$report = $manager->create($this->userList[0], $this->userList[1]->id, 'user', 'phpunit user report');
$this->reportList[] = $report;
$this->assertInstanceOf(Report::class, $report, 'report-user-create');
$this->assertEquals(
"<a href=\"{$report->url()}\">Report #{$report->id()}</a>",
"<a href=\"{$report->url()}\">Report #{$report->id}</a>",
$report->link(),
'report-link'
);
$this->assertEquals(
"reports.php?id={$report->id()}#report{$report->id()}",
"reports.php?id={$report->id}#report{$report->id}",
$report->location(),
'report-location'
);
$this->assertEquals('phpunit user report', $report->reason(), 'report-reason');
$this->assertEquals('New', $report->status(), 'report-new-status');
$this->assertEquals($this->userList[1]->id(), $report->subjectId(), 'report-subject-id');
$this->assertEquals($this->userList[1]->id, $report->subjectId(), 'report-subject-id');
$this->assertEquals('user', $report->subjectType(), 'report-subject-type');
$this->assertEquals($this->userList[0]->id(), $report->reporter()->id(), 'report-reporter');
$this->assertEquals($this->userList[0]->id, $report->reporter()?->id, 'report-reporter');
$this->assertFalse($report->isClaimed(), 'report-is-not-claimed');
$this->assertNull($report->resolved(), 'report-not-resolved');
$this->assertMatchesRegularExpression('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $report->created(), 'report-created');
@@ -183,9 +185,13 @@ class ReportManagerTest extends TestCase {
$report->addNote('phpunit add note');
$this->assertEquals('phpunit add note', $report->notes(), 'report-add-notes');
$this->assertEquals($report->id(), $manager->findById($report->id())->id(), 'report-user-find');
$this->assertInstanceOf(
Report::class,
$manager->findById($report->id),
'report-user-find'
);
$reportSubject = new Report\User($report->id(), $this->userList[1]);
$reportSubject = new Report\User($report->id, $this->userList[1]);
$this->assertFileExists(TEMPLATE_PATH . $reportSubject->template(), 'user-report-template');
$this->assertStringContainsString($this->userList[1]->username(), $reportSubject->bbLink(), 'user-report-bblink');
$this->assertEquals('User Report: ', $reportSubject->titlePrefix(), 'user-report-title-prefix');
@@ -202,13 +208,13 @@ class ReportManagerTest extends TestCase {
description: 'phpunit collage report description',
tagList: 'disco funk metal',
);
$report = $manager->create($this->userList[1], $this->collage->id(), 'collage', 'phpunit collage report');
$report = $manager->create($this->userList[1], $this->collage->id, 'collage', 'phpunit collage report');
$this->reportList[] = $report;
$report = $manager->create($this->userList[0], $this->userList[1]->id(), 'user', 'phpunit user report');
$report = $manager->create($this->userList[0], $this->userList[1]->id, 'user', 'phpunit user report');
$this->reportList[] = $report;
$list = $manager->decorate(
array_map(fn($r) => $r->id(), $this->reportList),
array_map(fn($r) => $r->id, $this->reportList),
new Manager\Collage(),
new Manager\Comment(),
new Manager\ForumThread(),
@@ -217,7 +223,7 @@ class ReportManagerTest extends TestCase {
);
$this->assertCount(2, $list, 'report-decorate-list');
$this->assertEquals('collage', $list[0]['label'], 'report-list-label');
$this->assertEquals($this->collage->id(), $list[0]['subject']->id(), 'report-list-subject-id');
$this->assertEquals($this->collage->id, $list[0]['subject']->id, 'report-list-subject-id');
$this->assertNull($list[0]['context'], 'report-list-collage-context-null');
}
}