Skip to content

Commit

Permalink
MSI: magento#206 - Added strict type static code test
Browse files Browse the repository at this point in the history
  • Loading branch information
DwayneH committed Nov 18, 2017
1 parent c5f3252 commit 6bd6d29
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
29 changes: 26 additions & 3 deletions dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,22 @@ private static function getChangedFilesBaseDir()
* @param array $fileTypes
* @param string $changedFilesBaseDir
* @param string $baseFilesFolder
* @param string $whitelistFile
* @return array
*/
public static function getWhitelist($fileTypes = ['php'], $changedFilesBaseDir = '', $baseFilesFolder = '')
{
public static function getWhitelist(
$fileTypes = ['php'],
$changedFilesBaseDir = '',
$baseFilesFolder = '',
$whitelistFile = '/_files/whitelist/common.txt'
) {
$changedFiles = self::getChangedFilesList($changedFilesBaseDir);
if (empty($changedFiles)) {
return [];
}

$globPatternsFolder = ('' !== $baseFilesFolder) ? $baseFilesFolder : self::getBaseFilesFolder();
$directoriesToCheck = Files::init()->readLists($globPatternsFolder . '/_files/whitelist/common.txt');
$directoriesToCheck = Files::init()->readLists($globPatternsFolder . $whitelistFile);
$targetFiles = self::filterFiles($changedFiles, $fileTypes, $directoriesToCheck);

return $targetFiles;
Expand Down Expand Up @@ -266,4 +271,22 @@ public function testCopyPaste()
"PHP Copy/Paste Detector has found error(s):" . PHP_EOL . $output
);
}

public function testStrictTypes()
{
$filesMissingStrictTyping = [];

foreach (self::getWhitelist(['php'], '', '', '/_files/whitelist/strict_type.txt') as $fileName) {
$file = file_get_contents($fileName);
if (strstr($file, 'strict_types=1') === false) {
$filesMissingStrictTyping[] = $fileName;
}
}

$this->assertEquals(
0,
count($filesMissingStrictTyping),
"Following files are missing strict type declaration:" . PHP_EOL . implode(PHP_EOL, $filesMissingStrictTyping)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Format: <componentType=module|library|theme|language|*> <componentName> <globPattern> or simply <globPattern>
app/code/Magento/Inventory
app/code/Magento/InventoryApi
app/code/Magento/InventoryCatalog
app/code/Magento/InventoryImportExport
app/code/Magento/InventorySales
app/code/Magento/InventorySalesApi

0 comments on commit 6bd6d29

Please sign in to comment.