Skip to content

Commit

Permalink
Use PHP81 short syntax for merging arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
vmcj committed Nov 1, 2023
1 parent bbf6d59 commit 46ee046
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions webapp/tests/E2E/Controller/ControllerRolesTraversalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function roleCombinations(array $start_roles, array $possible_roles):

foreach ($possible_roles as $element) {
foreach ($results as $combination) {
$results[] = array_merge([$element], $combination);
$results[] = [$element, ...$combination];
}
}
return $results;
Expand Down Expand Up @@ -137,7 +137,7 @@ protected function getAllPages(array $urlsToCheck, string $skip): array
continue;
}
if (!$this->urlExcluded($url, $skip)) {
$urlsToCheck = array_unique(array_merge($urlsToCheck, $this->crawlPageGetLinks($url, 200, $skip)));
$urlsToCheck = array_unique([...$urlsToCheck, ...$this->crawlPageGetLinks($url, 200, $skip)]);
}
$done[] = $url;
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/tests/Unit/Controller/API/AccountBaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function helperVerifyApiUsers(string $myURL, array $objectsBeforeTest, ar
self::assertEquals(1, count($newItems));
}
$listKey = array_keys($newItems)[0];
$newUserPostData = array_merge($newUserPostData, (array)$overwritten);
$newUserPostData = [...$newUserPostData, ...(array)$overwritten];
foreach ($newUserPostData as $key => $expectedValue) {
if ($key !== 'password') {
// For security we don't output the password in the API
Expand Down
2 changes: 1 addition & 1 deletion webapp/tests/Unit/Controller/API/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public function testListWithAbsentIds(): void
fn($id) => $this->resolveReference($id),
array_keys($this->expectedObjects)
);
$ids = array_merge($expectedObjectIds, $this->expectedAbsent);
$ids = [...$expectedObjectIds, ...$this->expectedAbsent];
$url = $this->helperGetEndpointURL($apiEndpoint);
$response = $this->verifyApiJsonResponse('GET', $url . "?" . http_build_query(['ids' => $ids]), 404, $this->apiUser);
static::assertEquals('One or more objects not found', $response['message']);
Expand Down
4 changes: 2 additions & 2 deletions webapp/tests/Unit/Controller/Jury/JuryControllerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public function provideAddCorrectEntities(): Generator
{
$entities = static::$addEntities;
if (!$this->dataSourceIsLocal()) {
$entities = array_merge($entities, static::$addEntitiesNonLocal);
$entities = [...$entities, ...static::$addEntitiesNonLocal];
}
foreach ($entities as $element) {
[$combinedValues, $element] = $this->helperProvideMergeAddEntity($element);
Expand All @@ -469,7 +469,7 @@ public function provideAddFailureEntities(): Generator
{
$entities = static::$addEntitiesFailure;
if (!$this->dataSourceIsLocal()) {
$entities = array_merge($entities, static::$addEntitiesFailureNonLocal);
$entities = [...$entities, ...static::$addEntitiesFailureNonLocal];
}
foreach ($entities as $message => $elementList) {
foreach ($elementList as $element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function testBalloonScoreboard(array $fixtures, bool $public, string $con
$this->verifyPageResponse('HEAD', '/public/problems/'.$id.'/text', $statusCode);
}
$this->verifyPageResponse('GET', '/public/problems', 200);
if (in_array($contestStage, array_merge(['preStart'], $nonActiveStages)) || !$public) {
if (in_array($contestStage, ['preStart', ...$nonActiveStages]) || !$public) {
self::assertSelectorExists('body:contains("No problem texts available at this point.")');
} else {
self::assertSelectorNotExists('body:contains("No problem texts available at this point.")');
Expand Down
2 changes: 1 addition & 1 deletion webapp/tests/Unit/Controller/PublicControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function selfRegisterProvider(): Generator
yield[['username'=>'newinstsamecountry', 'name'=>'CompetingDutchTeam', 'teamName'=>'SupperT3@m','affiliation'=>'new','affiliationName'=>'Vrije Universiteit',
'affiliationShortName'=>'vu','affiliationCountry'=>'NLD'],'demo', $fixtures, $category];
if (count($fixtures)===1) {
yield[['username'=>'reusevaluesofexistinguser', 'name'=>'selfregistered user for example team','email'=>'[email protected]','teamName'=>'EasyEnough','affiliation'=>'none'],'demo', array_merge($fixtures, [SelfRegisteredUserFixture::class]),''];
yield[['username'=>'reusevaluesofexistinguser', 'name'=>'selfregistered user for example team','email'=>'[email protected]','teamName'=>'EasyEnough','affiliation'=>'none'],'demo', [...$fixtures, SelfRegisteredUserFixture::class],''];
}
}
}
Expand Down
35 changes: 16 additions & 19 deletions webapp/tests/Unit/Service/ImportExportServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,27 +542,24 @@ protected function testImportAccounts(int $importCount, ?string $message, bool $
],
];
if ($forTsv) {
$expectedUsers = array_merge($expectedUsers, [
[
'roles' => ['team'],
'name' => 'Team 2 user a',
'username' => 'team02a',
'password' => 'password3',
'ip' => '5.6.7.8',
'team' => [
'id' => 2,
],
$expectedUsers = [...$expectedUsers, [
'roles' => ['team'],
'name' => 'Team 2 user a',
'username' => 'team02a',
'password' => 'password3',
'ip' => '5.6.7.8',
'team' => [
'id' => 2,
],
[
'roles' => ['team'],
'name' => 'Team 2 user b',
'username' => 'team02b',
'password' => 'password4',
'team' => [
'id' => 2,
],
], [
'roles' => ['team'],
'name' => 'Team 2 user b',
'username' => 'team02b',
'password' => 'password4',
'team' => [
'id' => 2,
],
]);
]];
}
$unexpectedUsers = ['analyst1', 'analyst2'];

Expand Down

0 comments on commit 46ee046

Please sign in to comment.