diff --git a/webapp/src/Controller/API/ProblemController.php b/webapp/src/Controller/API/ProblemController.php index 5ab516db4c..61e2ccb39f 100644 --- a/webapp/src/Controller/API/ProblemController.php +++ b/webapp/src/Controller/API/ProblemController.php @@ -58,7 +58,7 @@ public function __construct( /** * Add one or more problems. * - * @return int[] + * @return string[] * @throws BadRequestHttpException * @throws NonUniqueResultException */ @@ -105,7 +105,7 @@ public function addProblemsAction(Request $request): array $data = Yaml::parseFile($file->getRealPath(), Yaml::PARSE_DATETIME); $messages = []; if ($this->importExportService->importProblemsData($contest, $data, $ids, $messages)) { - return $ids; + return $ids ?? []; } $message = "Error while adding problems"; if (!empty($messages)) { diff --git a/webapp/src/Controller/Jury/RejudgingController.php b/webapp/src/Controller/Jury/RejudgingController.php index 96ac5ed604..da05c10a79 100644 --- a/webapp/src/Controller/Jury/RejudgingController.php +++ b/webapp/src/Controller/Jury/RejudgingController.php @@ -788,20 +788,8 @@ public function createAction(Request $request): Response } else { $redirect = $this->generateUrl('jury_index'); } - } elseif ($res instanceof Rejudging) { - $redirect = $this->generateUrl('jury_rejudging', ['rejudgingId' => $res->getRejudgingid()]); } else { - $redirect = match ($table) { - 'contest' => $this->generateUrl('jury_contest', ['contestId' => $id]), - 'judgehost' => $this->generateUrl('jury_judgehost', ['judgehostid' => $id]), - 'language' => $this->generateUrl('jury_language', ['langId' => $id]), - 'problem' => $this->generateUrl('jury_problem', ['probId' => $id]), - 'submission' => $this->generateUrl('jury_submission', ['submitId' => $id]), - 'team' => $this->generateUrl('jury_team', ['teamId' => $id]), - // This case never happens, since we already check above. - // Add it here to silence linter warnings. - default => throw new BadRequestHttpException(sprintf('unknown table %s in rejudging', $table)), - }; + $redirect = $this->generateUrl('jury_rejudging', ['rejudgingId' => $res->getRejudgingid()]); } $progressReporter(100, '', $redirect); diff --git a/webapp/src/Controller/Team/SubmissionController.php b/webapp/src/Controller/Team/SubmissionController.php index 27e565054f..037d679c4d 100644 --- a/webapp/src/Controller/Team/SubmissionController.php +++ b/webapp/src/Controller/Team/SubmissionController.php @@ -78,7 +78,7 @@ public function createAction(Request $request, ?Problem $problem = null): Respon $problem = $form->get('problem')->getData(); /** @var Language $language */ $language = $form->get('language')->getData(); - /** @var UploadedFile[] $files */ + /** @var UploadedFile[]|UploadedFile $files */ $files = $form->get('code')->getData(); if (!is_array($files)) { $files = [$files]; diff --git a/webapp/src/DataFixtures/DefaultData/UserFixture.php b/webapp/src/DataFixtures/DefaultData/UserFixture.php index b200d7bfed..9aade4e18c 100644 --- a/webapp/src/DataFixtures/DefaultData/UserFixture.php +++ b/webapp/src/DataFixtures/DefaultData/UserFixture.php @@ -89,7 +89,7 @@ protected function getRestapiPassword(): string if ($credential === '' || $credential[0] === '#') { continue; } - /** @var string[] $items */ + /** @var list $items */ $items = preg_split("/\s+/", $credential); if (count($items) !== 4) { throw new Exception("Error parsing REST API credentials. Invalid format in line $lineno."); diff --git a/webapp/src/DataFixtures/Test/RejudgingStatesFixture.php b/webapp/src/DataFixtures/Test/RejudgingStatesFixture.php index 205d76fdd3..fe7b893955 100644 --- a/webapp/src/DataFixtures/Test/RejudgingStatesFixture.php +++ b/webapp/src/DataFixtures/Test/RejudgingStatesFixture.php @@ -45,7 +45,7 @@ public function load(ObjectManager $manager): void $manager->flush(); // One rejudging can consist of submissions of multiple contests foreach ($rejudgingStage[4] as $contestName) { - /** @var Contest $contest */ + /** @var Contest|null $contest */ $contest = $manager->getRepository(Contest::class)->findOneBy(['shortname' => $contestName]); /** @var Team $team */ $team = $manager->getRepository(Team::class)->findOneBy(['name' => 'Example teamname']); diff --git a/webapp/src/Doctrine/DBAL/Types/JsonType.php b/webapp/src/Doctrine/DBAL/Types/JsonType.php index 8650cc912a..1c15e5e299 100644 --- a/webapp/src/Doctrine/DBAL/Types/JsonType.php +++ b/webapp/src/Doctrine/DBAL/Types/JsonType.php @@ -29,10 +29,13 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st } /** - * @return string|false|null - * @throws ConversionException + * @template T + * @param T $value + * + * @return (T is null ? null : string) + * @throws \JsonException */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string { if ($value === null) { return null; diff --git a/webapp/src/Entity/Testcase.php b/webapp/src/Entity/Testcase.php index 6bf6d35d7d..fedc72875e 100644 --- a/webapp/src/Entity/Testcase.php +++ b/webapp/src/Entity/Testcase.php @@ -94,7 +94,7 @@ class Testcase private Collection $judging_runs; /** - * @var Collection> + * @var Collection */ #[ORM\OneToMany(mappedBy: 'testcase', targetEntity: ExternalRun::class)] #[Serializer\Exclude] diff --git a/webapp/src/Form/Type/ExecutableType.php b/webapp/src/Form/Type/ExecutableType.php deleted file mode 100644 index 82293e5b3b..0000000000 --- a/webapp/src/Form/Type/ExecutableType.php +++ /dev/null @@ -1,49 +0,0 @@ -add('execid', TextType::class, [ - 'label' => 'ID', - ]); - $builder->add('description'); - $builder->add('type', ChoiceType::class, [ - 'choices' => [ - 'compare' => 'compare', - 'compile' => 'compile', - 'run' => 'run', - 'debug' => 'debug', - ] - ]); - $builder->add('save', SubmitType::class); - - // Remove ID field when doing an edit. - $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { - /** @var Executable|null $executable */ - $executable = $event->getData(); - $form = $event->getForm(); - - if ($executable && $executable->getExecid() !== null) { - $form->remove('execid'); - } - }); - } - - public function configureOptions(OptionsResolver $resolver): void - { - $resolver->setDefaults(['data_class' => Executable::class]); - } -} diff --git a/webapp/src/FosRestBundle/FlattenExceptionHandler.php b/webapp/src/FosRestBundle/FlattenExceptionHandler.php index d0fc918a78..f8e9ef9766 100644 --- a/webapp/src/FosRestBundle/FlattenExceptionHandler.php +++ b/webapp/src/FosRestBundle/FlattenExceptionHandler.php @@ -39,7 +39,7 @@ public static function getSubscribingMethods(): array } /** - * @param array{params: string[]} $type + * @param array{name: string, params: string[]} $type * * @return array{code: int, message: string} */ @@ -49,8 +49,7 @@ public function serializeToJson( array $type, Context $context ): array { - return $visitor->visitArray($this->convertToArray($exception, $context), - $type); + return $visitor->visitArray($this->convertToArray($exception, $context), $type); } /** diff --git a/webapp/src/Security/DOMJudgeIPAuthenticator.php b/webapp/src/Security/DOMJudgeIPAuthenticator.php index 507d481142..fe8993baf1 100644 --- a/webapp/src/Security/DOMJudgeIPAuthenticator.php +++ b/webapp/src/Security/DOMJudgeIPAuthenticator.php @@ -122,8 +122,7 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token, && $request->isMethod('POST') && $request->request->get('loginmethod') === 'ipaddress') { // Use target URL from session if set. - if ($firewallName !== null && - $targetUrl = $this->getTargetPath($request->getSession(), $firewallName)) { + if ($targetUrl = $this->getTargetPath($request->getSession(), $firewallName)) { $this->removeTargetPath($request->getSession(), $firewallName); return new RedirectResponse($targetUrl); } diff --git a/webapp/src/Security/DOMJudgeXHeadersAuthenticator.php b/webapp/src/Security/DOMJudgeXHeadersAuthenticator.php index 0c6b5d2682..87ea15ee58 100644 --- a/webapp/src/Security/DOMJudgeXHeadersAuthenticator.php +++ b/webapp/src/Security/DOMJudgeXHeadersAuthenticator.php @@ -76,8 +76,7 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token, && $request->isMethod('POST') && $request->request->get('loginmethod') === 'xheaders') { // Use target URL from session if set. - if ($firewallName !== null && - $targetUrl = $this->getTargetPath($request->getSession(), $firewallName)) { + if ($targetUrl = $this->getTargetPath($request->getSession(), $firewallName)) { $this->removeTargetPath($request->getSession(), $firewallName); return new RedirectResponse($targetUrl); } diff --git a/webapp/src/Serializer/Shadowing/EventDataDenormalizer.php b/webapp/src/Serializer/Shadowing/EventDataDenormalizer.php index c95ac90a1d..d01d27483e 100644 --- a/webapp/src/Serializer/Shadowing/EventDataDenormalizer.php +++ b/webapp/src/Serializer/Shadowing/EventDataDenormalizer.php @@ -49,7 +49,7 @@ public function denormalize( } /** - * @param array{api_version?: string, event_type?: EventType} $context + * @param array{api_version?: string, event_type?: mixed} $context */ public function supportsDenormalization( mixed $data, diff --git a/webapp/src/Service/AssetUpdateService.php b/webapp/src/Service/AssetUpdateService.php index feb6936e35..01409c8a52 100644 --- a/webapp/src/Service/AssetUpdateService.php +++ b/webapp/src/Service/AssetUpdateService.php @@ -14,7 +14,7 @@ public function __construct(protected readonly DOMJudgeService $dj, protected re /** * Update assets for the given entity. */ - public function updateAssets(AssetEntityInterface &$entity): void + public function updateAssets(AssetEntityInterface $entity): void { $fs = new Filesystem(); diff --git a/webapp/src/Service/ConfigurationService.php b/webapp/src/Service/ConfigurationService.php index 30f6df2ccb..cfc308382d 100644 --- a/webapp/src/Service/ConfigurationService.php +++ b/webapp/src/Service/ConfigurationService.php @@ -111,7 +111,7 @@ public function all(bool $onlyIfPublic = false): array /** * Get all configuration specifications. * - * @return ConfigurationSpecification[] + * @return array */ public function getConfigSpecification(): array { @@ -160,6 +160,7 @@ function (ConfigCacheInterface $cache) { * * @throws NonUniqueResultException * @param array|null $options + * @param-out array $options * @param array> $dataToSet * @return array Error per item */ @@ -176,7 +177,7 @@ public function saveChanges( } unset($spec); - /** @var Configuration[] $options */ + /** @var array $options */ $options = $options ?? $this->em->createQueryBuilder() ->from(Configuration::class, 'c', 'c.name') ->select('c') diff --git a/webapp/src/Service/EventLogService.php b/webapp/src/Service/EventLogService.php index 1a21f5929a..e400701c01 100644 --- a/webapp/src/Service/EventLogService.php +++ b/webapp/src/Service/EventLogService.php @@ -299,7 +299,7 @@ public function log( // Generate JSON content if not set, for deletes this is only the ID. if ($action === self::ACTION_DELETE) { - $json = array_values(array_map(fn($id) => ['id' => (string)$id], $ids)); + $json = array_map(fn($id) => ['id' => (string)$id], $ids); } elseif ($json === null) { $url = $type === 'contests' ? '' : ('/' . $type); diff --git a/webapp/src/Service/ExternalContestSourceService.php b/webapp/src/Service/ExternalContestSourceService.php index 719aee8e30..709d3ea3c8 100644 --- a/webapp/src/Service/ExternalContestSourceService.php +++ b/webapp/src/Service/ExternalContestSourceService.php @@ -219,7 +219,7 @@ public function getApiProviderName(): ?string throw new LogicException('The contest source is not valid'); } - return $this->cachedApiInfoData?->provider?->name ?? $this->cachedApiInfoData?->name; + return $this->cachedApiInfoData?->provider->name ?? $this->cachedApiInfoData?->name; } public function getApiProviderVersion(): ?string @@ -228,7 +228,7 @@ public function getApiProviderVersion(): ?string throw new LogicException('The contest source is not valid'); } - return $this->cachedApiInfoData?->provider?->version ?? $this->cachedApiInfoData?->domjudge?->version; + return $this->cachedApiInfoData?->provider->version ?? $this->cachedApiInfoData?->domjudge?->version; } public function getApiProviderBuildDate(): ?string @@ -1426,7 +1426,7 @@ protected function importSubmission(Event $event, EventData $data): void } } else { // First, check if we actually have the source for this submission in the data. - if (empty($data->files[0]?->href)) { + if (empty($data->files[0]->href)) { $this->addOrUpdateWarning($event, $data->id, ExternalSourceWarning::TYPE_SUBMISSION_ERROR, [ 'message' => 'No source files in event', ]); diff --git a/webapp/src/Service/ICPCCmsService.php b/webapp/src/Service/ICPCCmsService.php index ff5c308deb..da28564035 100644 --- a/webapp/src/Service/ICPCCmsService.php +++ b/webapp/src/Service/ICPCCmsService.php @@ -152,6 +152,8 @@ public function importTeams(string $token, string $contest, ?string &$message = /** * Upload standings to the ICPC CMS + * + * @param-out string $message */ public function uploadStandings(string $token, string $contest, ?string &$message = null): bool { diff --git a/webapp/src/Service/ImportExportService.php b/webapp/src/Service/ImportExportService.php index 2039c7bf06..dd2de043dc 100644 --- a/webapp/src/Service/ImportExportService.php +++ b/webapp/src/Service/ImportExportService.php @@ -44,8 +44,35 @@ public function __construct( /** * Get the YAML data for a given contest. * - * @return array> $contest + * @return array{ + * id: string, + * formal_name: string, + * name: string, + * start_time: string, + * end_time: string, + * duration: string, + * penalty_time: int, + * activate_time: string, + * warning_message?: string, + * medals: array{ + * gold: int, + * silver: int, + * bronze: int + * }, + * scoreboard_freeze_time?: string, + * scoreboard_freeze_duration?: string, + * scoreboard_thaw_time?: string, + * finalize_time?: string, + * deactivate_time?: string, + * problems?: list + * } */ public function getContestYamlData(Contest $contest, bool $includeProblems = true): array { @@ -390,7 +417,9 @@ public function importProblemsData(Contest $contest, array $problems, ?array &$i $this->em->persist($contestProblem); $this->em->flush(); - $ids[] = $problem->getExternalid(); + if ($problem->getExternalid()) { + $ids[] = $problem->getExternalid(); + } } $this->em->flush(); @@ -862,7 +891,7 @@ public function importOrganizationsJson(array $data, ?string &$message = null, ? /** * Import organization data from the given array. * - * @param array $organizationData + * @param array $organizationData * @param TeamAffiliation[]|null $saved The saved groups * * @throws NonUniqueResultException @@ -993,7 +1022,7 @@ protected function importTeamsTsv(array $content, ?string &$message = null): int 'name' => @$line[4], 'country' => @$line[6], 'externalid' => $affiliationExternalid, - ] + ], ]; } return $this->importTeamData($teamData, $message); @@ -1024,7 +1053,7 @@ public function importTeamsJson(array $data, ?string &$message = null, ?array &$ ], 'team_affiliation' => [ 'externalid' => $team['organization_id'] ?? null, - ] + ], ]; } @@ -1158,6 +1187,7 @@ protected function importTeamData(array $teamData, ?string &$message, ?array &$s $propertyAccessor = PropertyAccess::createPropertyAccessor(); foreach ($teamItem['team_affiliation'] as $field => $value) { $propertyAccessor->setValue($teamAffiliation, $field, $value); + assert($teamAffiliation instanceof TeamAffiliation); } } else { $teamAffiliation @@ -1255,6 +1285,7 @@ protected function importTeamData(array $teamData, ?string &$message, ?array &$s $propertyAccessor = PropertyAccess::createPropertyAccessor(); foreach ($teamItem['team'] as $field => $value) { $propertyAccessor->setValue($team, $field, $value); + assert($team instanceof Team); } $errors = $this->validator->validate($team); @@ -1333,7 +1364,7 @@ protected function importTeamData(array $teamData, ?string &$message, ?array &$s * @param User[]|null $saved The saved users * @param array $accountData @@ -1351,7 +1382,7 @@ protected function importAccountData( if (!empty($accountItem['team'])) { $team = $this->em->getRepository(Team::class)->findOneBy([ 'name' => $accountItem['team']['name'], - 'category' => $accountItem['team']['category'] + 'category' => $accountItem['team']['category'], ]); if ($team === null) { $team = new Team(); @@ -1414,6 +1445,7 @@ protected function importAccountData( $propertyAccessor = PropertyAccess::createPropertyAccessor(); foreach ($accountItem['user'] as $field => $value) { $propertyAccessor->setValue($user, $field, $value); + assert($user instanceof User); } $errors = $this->validator->validate($user); diff --git a/webapp/src/Service/ImportProblemService.php b/webapp/src/Service/ImportProblemService.php index fe97bbe29c..b9cbd94c6f 100644 --- a/webapp/src/Service/ImportProblemService.php +++ b/webapp/src/Service/ImportProblemService.php @@ -224,6 +224,7 @@ public function importZippedProblem( $propertyAccessor = PropertyAccess::createPropertyAccessor(); foreach ($problemProperties as $key => $value) { $propertyAccessor->setValue($problem, $key, $value); + assert($problem instanceof Problem); } $hasErrors = false; @@ -243,6 +244,7 @@ public function importZippedProblem( if ($contestProblem !== null) { foreach ($contestProblemProperties as $key => $value) { $propertyAccessor->setValue($contestProblem, $key, $value); + assert($contestProblem instanceof ContestProblem); } $errors = $this->validator->validate($contestProblem); @@ -763,7 +765,9 @@ public function importZippedProblem( ); if (!$submission) { - $messages['danger'][] = $submissionMessage; + if ($submissionMessage) { + $messages['danger'][] = $submissionMessage; + } } else { $submission = $this->em->getRepository(Submission::class)->find($submission->getSubmitid()); $submission->setExpectedResults($results); @@ -890,7 +894,7 @@ public function importProblemFromRequest(Request $request, ?int $contestId = nul } /** - * @param array{danger: string[], info: string[]} $messages + * @param array{danger?: string[], info?: string[]} $messages */ private function searchAndAddValidator(ZipArchive $zip, ?array &$messages, string $externalId, string $validationMode, ?Problem $problem): bool { @@ -999,7 +1003,7 @@ private function searchAndAddValidator(ZipArchive $zip, ?array &$messages, strin /** * Returns true iff the yaml could be parsed correctly. * - * @param array{danger: string[], info: string[]} $messages + * @param array{danger?: string[], info?: string[]} $messages */ public static function parseYaml(bool|string $problemYaml, array &$messages, string &$validationMode, PropertyAccessor $propertyAccessor, Problem $problem): bool { @@ -1075,6 +1079,7 @@ public static function parseYaml(bool|string $problemYaml, array &$messages, str foreach ($yamlProblemProperties as $key => $value) { try { $propertyAccessor->setValue($problem, $key, $value); + assert($problem instanceof Problem); } catch (Exception $e) { $messages['danger'][] = sprintf('Error: problem.%s: %s', $key, $e->getMessage()); return false; diff --git a/webapp/src/Service/ScoreboardService.php b/webapp/src/Service/ScoreboardService.php index 7ba4ae3267..e0c65e8684 100644 --- a/webapp/src/Service/ScoreboardService.php +++ b/webapp/src/Service/ScoreboardService.php @@ -862,11 +862,12 @@ public function getFilterValues(Contest $contest, bool $jury): array /** * Get the scoreboard Twig data for a given contest. * - * @return array{refresh: array{after: int, url: string, ajax: bool}, static: bool, contest: Contest, - * scoreFilter: Filter, scoreboard: Scoreboard, filterValues: array, - * groupedAffiliations: null|TeamAffiliation[], showFlags: int, showAffiliationLogos: bool, - * showAffiliations: int, showPending: int, showTeamSubmissions: int, scoreInSeconds: bool, - * maxWidth: int, jury?: bool, public?: bool, ajax?: bool} + * @return array{refresh?: array{after: int, url: string, ajax: bool}, static: bool, contest?: Contest, + * scoreFilter?: Filter, scoreboard: Scoreboard, filterValues: array, + * groupedAffiliations: null|array>>, + * showFlags: int, showAffiliationLogos: bool, showAffiliations: int, showPending: int, + * showTeamSubmissions: int, scoreInSeconds: bool, maxWidth: int, jury?: bool, + * public?: bool, ajax?: bool} */ public function getScoreboardTwigData( ?Request $request, diff --git a/webapp/src/Service/StatisticsService.php b/webapp/src/Service/StatisticsService.php index afd7d25075..7dcf9f6181 100644 --- a/webapp/src/Service/StatisticsService.php +++ b/webapp/src/Service/StatisticsService.php @@ -636,7 +636,7 @@ protected function applyFilter(QueryBuilder $queryBuilder, string $filter): Quer } /** - * @param array $array + * @param array $array */ protected static function setOrIncrement(array &$array, int|string $index): void { diff --git a/webapp/src/Service/SubmissionService.php b/webapp/src/Service/SubmissionService.php index 7dc699d43e..60efff8bdd 100644 --- a/webapp/src/Service/SubmissionService.php +++ b/webapp/src/Service/SubmissionService.php @@ -854,7 +854,6 @@ public function getSourceFilename(array $fileData): string */ public function getSubmissionZipResponse(Submission $submission): StreamedResponse { - /** @var SubmissionFile[] $files */ $files = $submission->getFiles(); $zip = new ZipArchive; if (!($tmpfname = tempnam($this->dj->getDomjudgeTmpDir(), "submission_file-"))) { @@ -875,10 +874,9 @@ public function getSubmissionZipResponse(Submission $submission): StreamedRespon public function getSubmissionFileResponse(Submission $submission): StreamedResponse { - /** @var SubmissionFile[] $files */ $files = $submission->getFiles(); - if (count($files) !== 1) { + if ($files->count() !== 1) { throw new ServiceUnavailableHttpException(null, 'Submission does not contain exactly one file.'); } diff --git a/webapp/tests/Unit/BaseTestCase.php b/webapp/tests/Unit/BaseTestCase.php index 71c5688498..abdbc181b3 100644 --- a/webapp/tests/Unit/BaseTestCase.php +++ b/webapp/tests/Unit/BaseTestCase.php @@ -36,6 +36,7 @@ abstract class BaseTestCase extends WebTestCase /** @var string[] */ protected static array $fixtures = []; + /** @var class-string|null */ protected ?string $entityClass = null; protected function setUp(): void @@ -86,11 +87,13 @@ protected function loadFixture(string $fixture): void /** * Resolve any references in the given ID. + * @param class-string|null $class */ protected function resolveReference(int|string $id, ?string $class = null, bool $preferExternalId = false): int|string { // If the object ID contains a :, it is a reference to a fixture item, so get it. if (is_string($id) && str_contains($id, ':')) { + /** @var object $referenceObject */ $referenceObject = $this->fixtureExecutor->getReferenceRepository()->getReference($id, $class ?? $this->entityClass); if ($preferExternalId && method_exists($referenceObject, 'getExternalid')) { return $referenceObject->getExternalid(); diff --git a/webapp/tests/Unit/Controller/API/BaseTestCase.php b/webapp/tests/Unit/Controller/API/BaseTestCase.php index 1549cfcb80..163ed027e1 100644 --- a/webapp/tests/Unit/Controller/API/BaseTestCase.php +++ b/webapp/tests/Unit/Controller/API/BaseTestCase.php @@ -254,10 +254,7 @@ public function testListContestNotFound(): void static::markTestSkipped('No endpoint defined.'); } if (in_array($apiEndpoint, static::$rootEndpoints)) { - // We can not test this, since e.g. /contests always exists. Assert that true is true to not make the test - // risky. - static::assertTrue(true); - return; + static::markTestSkipped('Endpoint is root endpoint'); } // Note that the 42 here is a contest that doesn't exist. $response = $this->verifyApiJsonResponse('GET', "/contests/42/$apiEndpoint", 404, $this->apiUser); @@ -318,7 +315,7 @@ public function testSingle(int|string $id, array $expectedProperties): void $object = $this->verifyApiJsonResponse('GET', $url, 200, $this->apiUser); static::assertIsArray($object); - $object = is_array($object) && count($object)===1 ? $object[0] : $object; + $object = count($object)===1 ? $object[0] : $object; foreach ($expectedProperties as $key => $value) { // Null values can also be absent. static::assertEquals($value, $object[$key] ?? null, $key . ' has correct value.'); diff --git a/webapp/tests/Unit/Controller/API/ContestControllerAdminTest.php b/webapp/tests/Unit/Controller/API/ContestControllerAdminTest.php index dd3c83b806..98991795cd 100644 --- a/webapp/tests/Unit/Controller/API/ContestControllerAdminTest.php +++ b/webapp/tests/Unit/Controller/API/ContestControllerAdminTest.php @@ -77,7 +77,6 @@ public function testAddYaml(): void self::assertIsString($cid); unlink($tempYamlFile); - self::assertIsString($cid); self::assertSame('NWERC 2020 Practice Session', $this->getContest($cid)->getName()); $url = $this->helperGetEndpointURL('contest-yaml', null, $cid); $exportContestYaml = $this->verifyApiResponse('GET', $url, 200, $this->apiUser, null, [], true); @@ -342,7 +341,6 @@ public function testActivateTimeContestYaml( $activate = Utils::toEpochFloat($activateTime); $start = Utils::toEpochFloat($startTime); - self::assertIsString($cid); self::assertSame('New Contest to check Activation', $this->getContest($cid)->getName()); self::assertSame($start, $this->getContest($cid)->getStarttime()); diff --git a/webapp/tests/Unit/Controller/Jury/JuryControllerTestCase.php b/webapp/tests/Unit/Controller/Jury/JuryControllerTestCase.php index 9293cd4248..9b429a86ff 100644 --- a/webapp/tests/Unit/Controller/Jury/JuryControllerTestCase.php +++ b/webapp/tests/Unit/Controller/Jury/JuryControllerTestCase.php @@ -593,7 +593,7 @@ public function testDeleteExtraEntity(): void self::assertSelectorNotExists('body:contains("' . static::$deleteExtra['selector'] . '")'); $this->verifyPageResponse('GET', static::$deleteExtra['deleteurl'], 404); } else { - self::assertTrue(true, "Test skipped"); + self::markTestSkipped('Test skipped'); } } diff --git a/webapp/tests/Unit/Controller/PublicControllerTest.php b/webapp/tests/Unit/Controller/PublicControllerTest.php index c53b43ea77..162fadd928 100644 --- a/webapp/tests/Unit/Controller/PublicControllerTest.php +++ b/webapp/tests/Unit/Controller/PublicControllerTest.php @@ -120,7 +120,7 @@ public function testSelfRegister(array $inputs, string $password, array $fixture } } - /** @var User $user */ + /** @var User|null $user */ $user = static::getContainer() ->get(EntityManagerInterface::class) ->getRepository(User::class) diff --git a/webapp/tests/Unit/Integration/QueuetaskIntegrationTest.php b/webapp/tests/Unit/Integration/QueuetaskIntegrationTest.php index e39e47e3e0..e5c98344b4 100644 --- a/webapp/tests/Unit/Integration/QueuetaskIntegrationTest.php +++ b/webapp/tests/Unit/Integration/QueuetaskIntegrationTest.php @@ -152,9 +152,6 @@ protected function setUp(): void // Using the TestBrowserToken is the easiest way to do this. $user = $this->em->getRepository(User::class)->findAll()[0]; $token = new TestBrowserToken([], $user, 'main'); - if (method_exists($token, 'setAuthenticated')) { - $token->setAuthenticated(true, false); - } self::getContainer()->get('security.untracked_token_storage')->setToken($token); }