Skip to content

Commit

Permalink
Update dev tools, cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkhamez committed Jan 28, 2024
1 parent a1c6ff8 commit b8de051
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 26 deletions.
1 change: 0 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/.env
/.php_cs.cache
/.php-cs-fixer.cache
/.phpunit.cache
/var/cache/*
!/var/cache/.gitkeep
/var/logs/*
Expand Down
2 changes: 1 addition & 1 deletion backend/.phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// Note that the **only** effect of choosing `'5.6'` is to infer
// that functions removed in php 7.0 exist.
// (See `backward_compatibility_checks` for additional options)
'target_php_version' => '8.0',
'target_php_version' => '8.1',

// A list of directories that should be parsed for class and
// method information. After excluding the directories
Expand Down
2 changes: 1 addition & 1 deletion backend/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"openapi src --output ../web/application-api-3.yml --exclude src/Controller/User"
],
"phan": "PHAN_DISABLE_XDEBUG_WARN=1 phan --color",
"phpstan": "phpstan analyse --level 8 --ansi --memory-limit 512M --xdebug src tests",
"phpstan": "phpstan analyse --level 8 --ansi --memory-limit 512M src tests",
"psalm": "psalm",
"test": "phpunit --colors=always",
"test:cov": "phpunit --colors=always --coverage-html var/phpunit",
Expand Down
6 changes: 6 additions & 0 deletions backend/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ parameters:
-
message: '#Cannot call method (.*) on (.*)#'
path: %currentWorkingDirectory%/tests/*
-
message: '#Parameter \#1 \$prefix of method (.*)assertStringStartsWith\(\) expects non-empty-string, string given.#'
path: %currentWorkingDirectory%/tests/*
-
message: '#Class Tests\\Client extends @final class GuzzleHttp\\Client.#'
path: %currentWorkingDirectory%/tests/Client.php
-
message: '#Class Tests\\Logger extends @final class Monolog\\Logger.#'
path: %currentWorkingDirectory%/tests/Logger.php
-
message: '#Method (.*) should return (.*) but returns (.*)#'
path: %currentWorkingDirectory%/tests/*
Expand Down
2 changes: 1 addition & 1 deletion backend/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.cache">
cacheDirectory="var/cache/.phpunit.cache">
<testsuites>
<testsuite name="Neucore">
<directory>tests</directory>
Expand Down
4 changes: 3 additions & 1 deletion backend/psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
cacheDirectory="var/cache/.psalm"
errorLevel="6"
resolveFromConfigFile="true"
phpVersion="8.0"
phpVersion="8.1"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
Expand Down
8 changes: 4 additions & 4 deletions backend/tests/Unit/Command/Traits/EsiRateLimitedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testCheckForErrors_RateLimit()
$this->assertSame(1, count($this->testLogger->getHandler()->getRecords()));
$this->assertMatchesRegularExpression(
'/sleeping \d+ second/',
$this->testLogger->getHandler()->getRecords()[0]['message']
$this->testLogger->getMessages()[0]
);
}

Expand All @@ -71,7 +71,7 @@ public function testCheckForErrors_Throttled()
$this->assertLessThanOrEqual(5, $this->getSleepInSeconds());
$this->assertMatchesRegularExpression(
"/EsiRateLimited: hit 'throttled', sleeping \d+ seconds/",
$this->testLogger->getHandler()->getRecords()[0]['message']
$this->testLogger->getMessages()[0]
);
}

Expand All @@ -86,8 +86,8 @@ public function testCheckForErrors_ErrorLimit()
$this->assertLessThanOrEqual(20, $this->getSleepInSeconds());
$this->assertStringStartsWith(
'EsiRateLimited: hit error limit, sleeping ',
$this->testLogger->getHandler()->getRecords()[0]['message']
$this->testLogger->getMessages()[0]
);
$this->assertStringEndsWith(' seconds', $this->testLogger->getHandler()->getRecords()[0]['message']);
$this->assertStringEndsWith(' seconds', $this->testLogger->getMessages()[0]);
}
}
8 changes: 4 additions & 4 deletions backend/tests/Unit/Middleware/Psr15/RateLimitAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public function testProcess_active()
$response->getBody()->__toString()
);

$logs = $this->logger->getHandler()->getRecords();
$logs = $this->logger->getMessages();
$this->assertSame(1, count($logs));
$this->assertStringStartsWith(
"API Rate Limit: App $this->appId 'Test app', limit exceeded with 51 request in ", // ... ~5.5 seconds.
$logs[0]['message']
$logs[0]
);
}

Expand Down Expand Up @@ -129,11 +129,11 @@ public function testProcess_configured_notActive()
$this->assertFalse($response->hasHeader(RateLimit::HEADER_REMAIN));
$this->assertFalse($response->hasHeader(RateLimit::HEADER_RESET));

$logs = $this->logger->getHandler()->getRecords();
$logs = $this->logger->getMessages();
$this->assertSame(1, count($logs));
$this->assertStringStartsWith(
"API Rate Limit: App $this->appId 'Test app', limit exceeded with 51 request in ", // ... ~5.5 seconds.
$logs[0]['message']
$logs[0]
);
}

Expand Down
4 changes: 2 additions & 2 deletions backend/tests/Unit/Middleware/Psr15/RateLimitIPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public function testProcess_Active()
$response->getBody()->__toString()
);

$logs = $logger->getHandler()->getRecords();
$logs = $logger->getMessages();
$this->assertSame(1, count($logs));
$this->assertStringStartsWith(
'IP Rate Limit: '.self::$ip.', App-ID '.self::$appIdp.', '.
'limit exceeded with 51 request in ', // ... ~5.5 seconds.
$logs[0]['message']
$logs[0]
);
}
}
12 changes: 6 additions & 6 deletions backend/tests/Unit/Service/EsiDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ public function testFetchCharacter_404NotFound()
$this->client->setResponse(new Response(404));
$char = $this->esiData->fetchCharacter(123);

$this->assertStringContainsString('404', $this->log->getHandler()->getRecords()[0]['message']);
$this->assertStringContainsString('404', $this->log->getMessages()[0]);
$this->assertNull($char);
$this->assertStringStartsWith('[404] Error ', $this->log->getHandler()->getRecords()[0]['message']);
$this->assertStringStartsWith('[404] Error ', $this->log->getMessages()[0]);
}

public function testFetchCharacter_404Deleted()
Expand Down Expand Up @@ -350,7 +350,7 @@ public function testFetchCorporationError500()

$corp = $this->esiData->fetchCorporation(123);
$this->assertNull($corp);
$this->assertStringStartsWith('[500] Error ', $this->log->getHandler()->getRecords()[0]['message']);
$this->assertStringStartsWith('[500] Error ', $this->log->getMessages()[0]);
}

public function testFetchCorporationNoFlushNoAlliance()
Expand Down Expand Up @@ -445,7 +445,7 @@ public function testFetchAllianceError500()

$alli = $this->esiData->fetchAlliance(123);
$this->assertNull($alli);
$this->assertStringStartsWith('[500] Error ', $this->log->getHandler()->getRecords()[0]['message']);
$this->assertStringStartsWith('[500] Error ', $this->log->getMessages()[0]);
}

public function testFetchAllianceNoFlush()
Expand Down Expand Up @@ -621,7 +621,7 @@ public function testFetchUniverseNames_InvalidIds()
'... {\"error\":\"Ensure all IDs are valid before resolving.\"}',
$records[3]['message']
);
$this->assertSame([3], $records[3]['context']['IDs']);
$this->assertSame([3], $records[3]['context']['IDs'] ?? []);
}

public function testFetchStructure_NoToken()
Expand Down Expand Up @@ -794,7 +794,7 @@ public function testVerifyRoles_Exception()
{
$this->client->setResponse(new Response(500));
$this->assertFalse($this->esiData->verifyRoles(['Auditor'], 100, 'access-token'));
$this->assertStringStartsWith('[500]', $this->log->getHandler()->getRecords()[0]['message']);
$this->assertStringStartsWith('[500]', $this->log->getMessages()[0]);
}

public function testVerifyRoles_CharacterNotFound()
Expand Down
6 changes: 3 additions & 3 deletions backend/tests/Unit/Service/UserAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function testLogin_Authenticate_NoUserRoleError()
$this->assertSame(UserAuth::LOGIN_AUTHENTICATED_FAIL, $result);
$this->assertSame(
'UserAuth::authenticate(): Role "'.Role::USER.'" not found.',
$this->log->getHandler()->getRecords()[0]['message']
$this->log->getMessages()[0]
);
}

Expand Down Expand Up @@ -226,7 +226,7 @@ public function testLogin_Authenticate_ExistingNoAltLogin()
);

$this->assertSame(UserAuth::LOGIN_ALT_FAILED, $result);
$this->assertSame('Login with alt 9014 denied.', $this->log->getHandler()->getRecords()[0]['message']);
$this->assertSame('Login with alt 9014 denied.', $this->log->getMessages()[0]);
}

public function testLogin_Authenticate_NewOwner()
Expand Down Expand Up @@ -522,7 +522,7 @@ public function testAddToken_SaveFailed()
$this->assertSame(1, count($this->log->getHandler()->getRecords()));
$this->assertStringStartsWith(
'A new entity was found', // EveLogin was not persisted
$this->log->getHandler()->getRecords()[0]['message']
$this->log->getMessages()[0]
);
}

Expand Down
2 changes: 1 addition & 1 deletion backend/tests/Unit/Slim/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public function testInvoke()
$error->__invoke(RequestFactory::createRequest(), $exception, true, true, true);

$this->assertSame('msg', $handler->getRecords()[0]['message']);
$this->assertSame($exception, $handler->getRecords()[0]['context']['exception']);
$this->assertSame($exception, $handler->getRecords()[0]['context']['exception'] ?? null);
}
}
1 change: 1 addition & 0 deletions backend/tests/Unit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TestCase extends \PHPUnit\Framework\TestCase
{
/**
* @throws Exception
* @phan-suppress PhanTypeInvalidThrowsIsInterface
*/
protected function createRequestWithRoute(string $method = 'GET', string $path = null): ServerRequestInterface
{
Expand Down
2 changes: 1 addition & 1 deletion setup/Dockerfile-php83-fpm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN apk update && \
RUN mkdir -p /usr/src/php/ext/apcu && \
curl -fsSL https://pecl.php.net/get/apcu-5.1.23.tgz | tar xvz -C "/usr/src/php/ext/apcu" --strip 1
RUN mkdir -p /usr/src/php/ext/ast && \
curl -fsSL https://pecl.php.net/get/ast-1.1.0.tgz | tar xvz -C "/usr/src/php/ext/ast" --strip 1
curl -fsSL https://pecl.php.net/get/ast-1.1.1.tgz | tar xvz -C "/usr/src/php/ext/ast" --strip 1
RUN mkdir -p /usr/src/php/ext/xdebug && \
curl -fsSL https://pecl.php.net/get/xdebug-3.3.0.tgz | tar xvz -C "/usr/src/php/ext/xdebug" --strip 1
RUN docker-php-ext-install pdo_mysql bcmath gmp zip intl ast apcu xdebug opcache mysqli
Expand Down

0 comments on commit b8de051

Please sign in to comment.