mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Tweaks
Changed the format of the historical callmap to be plain signature list, as it isn't really a delta file and renamed the file to not be confused with deltas. Added a test to ensure entries in main callmap have history.
This commit is contained in:
parent
90a09a7a9a
commit
8c531fec4b
@ -15,7 +15,6 @@
|
|||||||
* @phan-file-suppress PhanPluginMixedKeyNoKey (read by Phan when analyzing this file)
|
* @phan-file-suppress PhanPluginMixedKeyNoKey (read by Phan when analyzing this file)
|
||||||
*/
|
*/
|
||||||
return [
|
return [
|
||||||
'added' => [
|
|
||||||
'AMQPBasicProperties::__construct' => ['void', 'content_type='=>'string', 'content_encoding='=>'string', 'headers='=>'array', 'delivery_mode='=>'int', 'priority='=>'int', 'correlation_id='=>'string', 'reply_to='=>'string', 'expiration='=>'string', 'message_id='=>'string', 'timestamp='=>'int', 'type='=>'string', 'user_id='=>'string', 'app_id='=>'string', 'cluster_id='=>'string'],
|
'AMQPBasicProperties::__construct' => ['void', 'content_type='=>'string', 'content_encoding='=>'string', 'headers='=>'array', 'delivery_mode='=>'int', 'priority='=>'int', 'correlation_id='=>'string', 'reply_to='=>'string', 'expiration='=>'string', 'message_id='=>'string', 'timestamp='=>'int', 'type='=>'string', 'user_id='=>'string', 'app_id='=>'string', 'cluster_id='=>'string'],
|
||||||
'AMQPBasicProperties::getAppId' => ['string'],
|
'AMQPBasicProperties::getAppId' => ['string'],
|
||||||
'AMQPBasicProperties::getClusterId' => ['string'],
|
'AMQPBasicProperties::getClusterId' => ['string'],
|
||||||
@ -16550,9 +16549,4 @@ return [
|
|||||||
'zlib_encode' => ['string', 'data'=>'string', 'encoding'=>'int', 'level='=>'string|int'],
|
'zlib_encode' => ['string', 'data'=>'string', 'encoding'=>'int', 'level='=>'string|int'],
|
||||||
'zlib_get_coding_type' => ['string|false'],
|
'zlib_get_coding_type' => ['string|false'],
|
||||||
'zookeeper_dispatch' => ['void'],
|
'zookeeper_dispatch' => ['void'],
|
||||||
],
|
|
||||||
'changed' => [
|
|
||||||
],
|
|
||||||
'removed' => [
|
|
||||||
],
|
|
||||||
];
|
];
|
@ -21,25 +21,25 @@ use const DIRECTORY_SEPARATOR;
|
|||||||
class CallMapTest extends \Psalm\Tests\TestCase
|
class CallMapTest extends \Psalm\Tests\TestCase
|
||||||
{
|
{
|
||||||
protected const DICTIONARY_PATH = 'dictionaries';
|
protected const DICTIONARY_PATH = 'dictionaries';
|
||||||
|
|
||||||
public function testDictionaryPathMustBeAReadableDirectory(): void
|
public function testDictionaryPathMustBeAReadableDirectory(): void
|
||||||
{
|
{
|
||||||
self::assertDirectoryExists(self::DICTIONARY_PATH, self::DICTIONARY_PATH . " is not a valid directory");
|
self::assertDirectoryExists(self::DICTIONARY_PATH, self::DICTIONARY_PATH . " is not a valid directory");
|
||||||
self::assertDirectoryIsReadable(self::DICTIONARY_PATH, self::DICTIONARY_PATH . " is not a readable directory");
|
self::assertDirectoryIsReadable(self::DICTIONARY_PATH, self::DICTIONARY_PATH . " is not a readable directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testDictionaryPathMustBeAReadableDirectory
|
* @depends testDictionaryPathMustBeAReadableDirectory
|
||||||
*/
|
*/
|
||||||
public function testMainCallmapFileExists(): string
|
public function testMainCallmapFileExists(): string
|
||||||
{
|
{
|
||||||
$callMapFilePath = self::DICTIONARY_PATH . DIRECTORY_SEPARATOR . 'CallMap.php';
|
$callMapFilePath = self::DICTIONARY_PATH . DIRECTORY_SEPARATOR . 'CallMap.php';
|
||||||
|
|
||||||
self::assertFileExists($callMapFilePath, "Main CallMap " . $callMapFilePath . " file not found");
|
self::assertFileExists($callMapFilePath, "Main CallMap " . $callMapFilePath . " file not found");
|
||||||
|
|
||||||
return $callMapFilePath;
|
return $callMapFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testMainCallmapFileExists
|
* @depends testMainCallmapFileExists
|
||||||
* @return array<string, array<int|string,string>>
|
* @return array<string, array<int|string,string>>
|
||||||
@ -51,12 +51,12 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
* @psalm-suppress UnresolvableInclude
|
* @psalm-suppress UnresolvableInclude
|
||||||
*/
|
*/
|
||||||
$mainCallMap = include($callMapFilePath);
|
$mainCallMap = include($callMapFilePath);
|
||||||
|
|
||||||
/** @psalm-suppress RedundantConditionGivenDocblockType */
|
/** @psalm-suppress RedundantConditionGivenDocblockType */
|
||||||
self::assertIsArray($mainCallMap, "Main CallMap file " . $callMapFilePath . " does not contain a readable array");
|
self::assertIsArray($mainCallMap, "Main CallMap file " . $callMapFilePath . " does not contain a readable array");
|
||||||
return $mainCallMap;
|
return $mainCallMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testDictionaryPathMustBeAReadableDirectory
|
* @depends testDictionaryPathMustBeAReadableDirectory
|
||||||
* @return array<string, array{
|
* @return array<string, array{
|
||||||
@ -80,7 +80,7 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
RegexIterator::MATCH,
|
RegexIterator::MATCH,
|
||||||
RegexIterator::USE_KEY
|
RegexIterator::USE_KEY
|
||||||
);
|
);
|
||||||
|
|
||||||
$deltaFiles = [];
|
$deltaFiles = [];
|
||||||
foreach ($deltaFileIterator as $deltaFile => $deltaFilePath) {
|
foreach ($deltaFileIterator as $deltaFile => $deltaFilePath) {
|
||||||
if (!is_file($deltaFilePath)) {
|
if (!is_file($deltaFilePath)) {
|
||||||
@ -99,23 +99,31 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
*/
|
*/
|
||||||
$deltaFiles[$deltaFile] = include($deltaFilePath);
|
$deltaFiles[$deltaFile] = include($deltaFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
uksort($deltaFiles, 'strnatcasecmp');
|
uksort($deltaFiles, 'strnatcasecmp');
|
||||||
|
|
||||||
|
$deltaFiles = [
|
||||||
|
'CallMap_historical.php' => [
|
||||||
|
'added' => include 'dictionaries/CallMap_historical.php',
|
||||||
|
'changed' => [],
|
||||||
|
'removed' => [],
|
||||||
|
]
|
||||||
|
] + $deltaFiles;
|
||||||
|
|
||||||
foreach ($deltaFiles as $name => $deltaFile) {
|
foreach ($deltaFiles as $name => $deltaFile) {
|
||||||
/** @psalm-suppress RedundantConditionGivenDocblockType */
|
/** @psalm-suppress RedundantConditionGivenDocblockType */
|
||||||
self::assertIsArray($deltaFile, "Delta file " . $name . " doesn't contain a readable array");
|
self::assertIsArray($deltaFile, "Delta file " . $name . " doesn't contain a readable array");
|
||||||
self::assertArrayHasKey('added', $deltaFile, "Delta file " . $name . " has no 'added' section");
|
self::assertArrayHasKey('added', $deltaFile, "Delta file " . $name . " has no 'added' section");
|
||||||
self::assertArrayHasKey('changed', $deltaFile, "Delta file " . $name . " has no 'changed' section");
|
self::assertArrayHasKey('changed', $deltaFile, "Delta file " . $name . " has no 'changed' section");
|
||||||
self::assertArrayHasKey('removed', $deltaFile, "Delta file " . $name . " has no 'removed' section");
|
self::assertArrayHasKey('removed', $deltaFile, "Delta file " . $name . " has no 'removed' section");
|
||||||
/** @psalm-suppress RedundantConditionGivenDocblockType */
|
/** @psalm-suppress RedundantCondition */
|
||||||
self::assertIsArray($deltaFile['added'], "'added' section in Delta file " . $name . " doesn't contain a readable array");
|
self::assertIsArray($deltaFile['added'], "'added' section in Delta file " . $name . " doesn't contain a readable array");
|
||||||
/** @psalm-suppress RedundantConditionGivenDocblockType */
|
/** @psalm-suppress RedundantCondition */
|
||||||
self::assertIsArray($deltaFile['removed'], "'removed' section in Delta file " . $name . " doesn't contain a readable array");
|
self::assertIsArray($deltaFile['removed'], "'removed' section in Delta file " . $name . " doesn't contain a readable array");
|
||||||
/** @psalm-suppress RedundantConditionGivenDocblockType */
|
/** @psalm-suppress RedundantCondition */
|
||||||
self::assertIsArray($deltaFile['changed'], "'changed' section in Delta file " . $name . " doesn't contain a readable array");
|
self::assertIsArray($deltaFile['changed'], "'changed' section in Delta file " . $name . " doesn't contain a readable array");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $deltaFiles;
|
return $deltaFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +158,7 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testMainCallmapFileContainsACallmap
|
* @depends testMainCallmapFileContainsACallmap
|
||||||
* @depends testDeltaFilesContainAddedChangedAndRemovedSections
|
* @depends testDeltaFilesContainAddedChangedAndRemovedSections
|
||||||
@ -192,6 +200,7 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testMainCallmapFileContainsACallmap
|
* @depends testMainCallmapFileContainsACallmap
|
||||||
* @depends testDeltaFilesContainAddedChangedAndRemovedSections
|
* @depends testDeltaFilesContainAddedChangedAndRemovedSections
|
||||||
@ -213,7 +222,7 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
self::assertStringIsParsableType($type, "Function " . $function . " in main CallMap contains invalid type declaration " . $type);
|
self::assertStringIsParsableType($type, "Function " . $function . " in main CallMap contains invalid type declaration " . $type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($deltaFiles as $name => $deltaFile) {
|
foreach ($deltaFiles as $name => $deltaFile) {
|
||||||
foreach (['added', 'removed'] as $section) {
|
foreach (['added', 'removed'] as $section) {
|
||||||
foreach ($deltaFile[$section] as $function => $signature) {
|
foreach ($deltaFile[$section] as $function => $signature) {
|
||||||
@ -237,7 +246,7 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testDeltaFilesContainAddedChangedAndRemovedSections
|
* @depends testDeltaFilesContainAddedChangedAndRemovedSections
|
||||||
* @depends testCallmapKeysAreStringsAndValuesAreSignatures
|
* @depends testCallmapKeysAreStringsAndValuesAreSignatures
|
||||||
@ -266,13 +275,13 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
[], // Compare against empty array to get handy diff in output
|
[], // Compare against empty array to get handy diff in output
|
||||||
"Deltafile " . $name . " tries to change non-existing functions"
|
"Deltafile " . $name . " tries to change non-existing functions"
|
||||||
);
|
);
|
||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
array_values($nonExistingRemovedFunctions),
|
array_values($nonExistingRemovedFunctions),
|
||||||
[], // Compare against empty array to get handy diff in output
|
[], // Compare against empty array to get handy diff in output
|
||||||
"Deltafile " . $name . " tries to remove non-existing functions"
|
"Deltafile " . $name . " tries to remove non-existing functions"
|
||||||
);
|
);
|
||||||
|
|
||||||
$newFunctions = array_diff($newFunctions, $removedFunctions);
|
$newFunctions = array_diff($newFunctions, $removedFunctions);
|
||||||
$newFunctions = array_merge($newFunctions, $addedFunctions);
|
$newFunctions = array_merge($newFunctions, $addedFunctions);
|
||||||
$deletedFunctions = array_diff($deletedFunctions, $addedFunctions);
|
$deletedFunctions = array_diff($deletedFunctions, $addedFunctions);
|
||||||
@ -280,7 +289,7 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
}
|
}
|
||||||
return $deletedFunctions;
|
return $deletedFunctions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testDeltaFilesContainAddedChangedAndRemovedSections
|
* @depends testDeltaFilesContainAddedChangedAndRemovedSections
|
||||||
* @depends testCallmapKeysAreStringsAndValuesAreSignatures
|
* @depends testCallmapKeysAreStringsAndValuesAreSignatures
|
||||||
@ -306,7 +315,7 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
[], // Compare against empty array to get handy diff in output
|
[], // Compare against empty array to get handy diff in output
|
||||||
"Deltafile " . $name . " adds already existing functions"
|
"Deltafile " . $name . " adds already existing functions"
|
||||||
);
|
);
|
||||||
|
|
||||||
$newFunctions = array_diff_key($newFunctions, $deltaFile['removed']);
|
$newFunctions = array_diff_key($newFunctions, $deltaFile['removed']);
|
||||||
foreach ($deltaFile['changed'] as $function => ['new' => $new]) {
|
foreach ($deltaFile['changed'] as $function => ['new' => $new]) {
|
||||||
$newFunctions[$function] = $new;
|
$newFunctions[$function] = $new;
|
||||||
@ -315,7 +324,7 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
}
|
}
|
||||||
return $newFunctions;
|
return $newFunctions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testDeltaFilesContainAddedChangedAndRemovedSections
|
* @depends testDeltaFilesContainAddedChangedAndRemovedSections
|
||||||
* @depends testCallmapKeysAreStringsAndValuesAreSignatures
|
* @depends testCallmapKeysAreStringsAndValuesAreSignatures
|
||||||
@ -354,7 +363,7 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testMainCallmapFileContainsACallmap
|
* @depends testMainCallmapFileContainsACallmap
|
||||||
* @depends testExistingFunctionsCanNotBeAdded
|
* @depends testExistingFunctionsCanNotBeAdded
|
||||||
@ -365,16 +374,34 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
public function testFunctionsAddedInDeltaFilesArePresentInMainCallmap(array $mainCallMap, array $newFunctions): array
|
public function testFunctionsAddedInDeltaFilesArePresentInMainCallmap(array $mainCallMap, array $newFunctions): array
|
||||||
{
|
{
|
||||||
$missingNewFunctions = array_diff(array_keys($newFunctions), array_keys($mainCallMap));
|
$missingNewFunctions = array_diff(array_keys($newFunctions), array_keys($mainCallMap));
|
||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
array_values($missingNewFunctions),
|
array_values($missingNewFunctions),
|
||||||
[], // Compare against empty array to get handy diff in output
|
[], // Compare against empty array to get handy diff in output
|
||||||
"Not all functions added in delta files are present in main CallMap file"
|
"Not all functions added in delta files are present in main CallMap file"
|
||||||
);
|
);
|
||||||
|
|
||||||
return $newFunctions;
|
return $newFunctions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @depends testMainCallmapFileContainsACallmap
|
||||||
|
* @depends testExistingFunctionsCanNotBeAdded
|
||||||
|
* @depends testCallmapKeysAreStringsAndValuesAreSignatures
|
||||||
|
* @param array<string, array<int|string,string>> $mainCallMap
|
||||||
|
* @param array<string, array<int|string,string>> $newFunctions
|
||||||
|
*/
|
||||||
|
public function testFunctionsPresentInMainCallmapAreAddedInDeltaFiles(array $mainCallMap, array $newFunctions): void
|
||||||
|
{
|
||||||
|
$strayNewFunctions = array_diff(array_keys($mainCallMap), array_keys($newFunctions));
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
[], // Compare against empty array to get handy diff in output
|
||||||
|
array_values($strayNewFunctions),
|
||||||
|
"Not all functions present in main CallMap file are added in delta files"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testMainCallmapFileContainsACallmap
|
* @depends testMainCallmapFileContainsACallmap
|
||||||
* @depends testChangedAndRemovedFunctionsMustExist
|
* @depends testChangedAndRemovedFunctionsMustExist
|
||||||
@ -385,17 +412,18 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
public function testFunctionsRemovedInDeltaFilesAreAbsentFromMainCallmap(array $mainCallMap, array $removedFunctions): void
|
public function testFunctionsRemovedInDeltaFilesAreAbsentFromMainCallmap(array $mainCallMap, array $removedFunctions): void
|
||||||
{
|
{
|
||||||
$stillPresentRemovedFunctions = array_intersect($removedFunctions, array_keys($mainCallMap));
|
$stillPresentRemovedFunctions = array_intersect($removedFunctions, array_keys($mainCallMap));
|
||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
[], // Compare against empty array to get handy diff in output
|
[], // Compare against empty array to get handy diff in output
|
||||||
array_values($stillPresentRemovedFunctions),
|
array_values($stillPresentRemovedFunctions),
|
||||||
"Not all functions removed in delta files are absent in main CallMap file"
|
"Not all functions removed in delta files are absent in main CallMap file"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testMainCallmapFileContainsACallmap
|
* @depends testMainCallmapFileContainsACallmap
|
||||||
* @depends testFunctionsAddedInDeltaFilesArePresentInMainCallmap
|
* @depends testFunctionsAddedInDeltaFilesArePresentInMainCallmap
|
||||||
|
* @depends testFunctionsPresentInMainCallmapAreAddedInDeltaFiles
|
||||||
* @param array<string, array<int|string,string>> $mainCallMap
|
* @param array<string, array<int|string,string>> $mainCallMap
|
||||||
* @param array<string, array<int|string,string>> $newFunctions
|
* @param array<string, array<int|string,string>> $newFunctions
|
||||||
*/
|
*/
|
||||||
@ -404,14 +432,14 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
$existingFunctions = array_intersect_key($mainCallMap, $newFunctions);
|
$existingFunctions = array_intersect_key($mainCallMap, $newFunctions);
|
||||||
ksort($existingFunctions);
|
ksort($existingFunctions);
|
||||||
ksort($newFunctions);
|
ksort($newFunctions);
|
||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
$newFunctions,
|
$newFunctions,
|
||||||
$existingFunctions,
|
$existingFunctions,
|
||||||
"Signatures in CallMap file don't match most recent signatures in delta files"
|
"Signatures in CallMap file don't match most recent signatures in delta files"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testDeltaFilesContainAddedChangedAndRemovedSections
|
* @depends testDeltaFilesContainAddedChangedAndRemovedSections
|
||||||
* @depends testSignatureKeysAreZeroOrStringAndValuesAreTypes
|
* @depends testSignatureKeysAreZeroOrStringAndValuesAreTypes
|
||||||
@ -442,13 +470,13 @@ class CallMapTest extends \Psalm\Tests\TestCase
|
|||||||
$overlapOutgoing = array_intersect_key($outgoingSignatures, $incomingSignatures);
|
$overlapOutgoing = array_intersect_key($outgoingSignatures, $incomingSignatures);
|
||||||
if (count($overlapOutgoing) !== 0) {
|
if (count($overlapOutgoing) !== 0) {
|
||||||
$overlapIncoming = array_intersect_key($incomingSignatures, $outgoingSignatures);
|
$overlapIncoming = array_intersect_key($incomingSignatures, $outgoingSignatures);
|
||||||
|
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
$overlapOutgoing,
|
$overlapOutgoing,
|
||||||
$overlapIncoming,
|
$overlapIncoming,
|
||||||
"Outgoing signatures in " . $deltaFileNames[$i] . " don't match corresponding incoming signatures in " . $deltaFileNames[$j]
|
"Outgoing signatures in " . $deltaFileNames[$i] . " don't match corresponding incoming signatures in " . $deltaFileNames[$j]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Don't check what has already been matched
|
// Don't check what has already been matched
|
||||||
$outgoingSignatures = array_diff_key($outgoingSignatures, $overlapOutgoing);
|
$outgoingSignatures = array_diff_key($outgoingSignatures, $overlapOutgoing);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user