-   Notifications  You must be signed in to change notification settings 
- Fork 165
AC-669 install upgrade test #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
   Merged  
  magento-devops-reposync-svc merged 9 commits into magento:develop from svera:AC-669_InstallUpgradeTest        Sep 27, 2021  
    Merged  
 Changes from 7 commits
 Commits 
  Show all changes 
  9 commits   Select commit Hold shift + click to select a range 
 08c7084  AC-669: Create phpcs static check for InstallUpgradeTest 
  svera 38cf408  AC-669: Create phpcs static check for InstallUpgradeTest 
  svera b6bff95  AC-669: Create phpcs static check for InstallUpgradeTest 
  svera 718975a  AC-669: Create phpcs static check for InstallUpgradeTest 
  svera 230facd  AC-669: Create phpcs static check for InstallUpgradeTest 
  svera d47a669  AC-669: Create phpcs static check for InstallUpgradeTest 
  svera 6601b5b  Merge branch 'develop' into AC-669_InstallUpgradeTest 
  svera 97b843c  AC-669: Create phpcs static check for InstallUpgradeTest 
  svera d974210  AC-669: Create phpcs static check for InstallUpgradeTest 
  svera File filter
Filter by extension
Conversations
 Failed to load comments.  
    Loading  
 Jump to
  Jump to file  
  Failed to load files.  
    Loading  
 Diff view
Diff view
There are no files selected for viewing
   This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| declare(strict_types = 1); | ||
|  | ||
| namespace Magento2\Sniffs\Legacy; | ||
|  | ||
| use PHP_CodeSniffer\Files\File; | ||
| use PHP_CodeSniffer\Sniffs\Sniff; | ||
| use SplFileInfo; | ||
|  | ||
| class InstallUpgradeSniff implements Sniff | ||
| { | ||
| private const ERROR_CODE = 'obsoleteScript'; | ||
|  | ||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function register(): array | ||
| { | ||
| return [ | ||
| T_OPEN_TAG | ||
| ]; | ||
| } | ||
|  | ||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| public function process(File $phpcsFile, $stackPtr) | ||
| { | ||
| if ($stackPtr > 0) { | ||
| return; | ||
| } | ||
|  | ||
| $fileInfo = new SplFileInfo($phpcsFile->getFilename()); | ||
|  | ||
| if (strpos($fileInfo->getFilename(), 'install-') === 0) { | ||
| $phpcsFile->addError( | ||
| 'Install scripts are obsolete. ' | ||
| . 'Please use declarative schema approach in module\'s etc/db_schema.xml file', | ||
| 0, | ||
| self::ERROR_CODE | ||
| ); | ||
| } | ||
|  | ||
| if (strpos($fileInfo->getFilename(), 'InstallSchema') === 0) { | ||
| $phpcsFile->addError( | ||
| 'InstallSchema scripts are obsolete. ' | ||
| . 'Please use declarative schema approach in module\'s etc/db_schema.xml file', | ||
| 0, | ||
| self::ERROR_CODE | ||
| ); | ||
| } | ||
|  | ||
| if (strpos($fileInfo->getFilename(), 'InstallData') === 0) { | ||
| $phpcsFile->addError( | ||
| 'InstallData scripts are obsolete. ' | ||
| . 'Please use data patches approach in module\'s Setup/Patch/Data dir', | ||
| 0, | ||
| self::ERROR_CODE | ||
| ); | ||
| } | ||
|  | ||
| if (strpos($fileInfo->getFilename(), 'data-install-') === 0) { | ||
| $phpcsFile->addError( | ||
| 'Install scripts are obsolete. Please create class InstallData in module\'s Setup folder', | ||
| 0, | ||
| self::ERROR_CODE | ||
| ); | ||
| } | ||
|  | ||
| if (strpos($fileInfo->getFilename(), 'upgrade-') === 0) { | ||
| $phpcsFile->addError( | ||
| 'Upgrade scripts are obsolete. ' | ||
| . 'Please use declarative schema approach in module\'s etc/db_schema.xml file', | ||
| 0, | ||
| self::ERROR_CODE | ||
| ); | ||
| } | ||
|  | ||
| if (strpos($fileInfo->getFilename(), 'UpgradeSchema') === 0) { | ||
| $phpcsFile->addError( | ||
| 'UpgradeSchema scripts are obsolete. ' | ||
| . 'Please use declarative schema approach in module\'s etc/db_schema.xml file', | ||
| 0, | ||
| self::ERROR_CODE | ||
| ); | ||
| } | ||
|  | ||
| if (strpos($fileInfo->getFilename(), 'UpgradeData') === 0) { | ||
| $phpcsFile->addError( | ||
| 'UpgradeSchema scripts are obsolete. ' | ||
| . 'Please use data patches approach in module\'s Setup/Patch/Data dir', | ||
| 0, | ||
| self::ERROR_CODE | ||
| ); | ||
| } | ||
|  | ||
| if (strpos($fileInfo->getFilename(), 'data-upgrade-') === 0) { | ||
| $phpcsFile->addError( | ||
| 'Upgrade scripts are obsolete. ' | ||
| . 'Please use data patches approach in module\'s Setup/Patch/Data dir', | ||
| 0, | ||
| self::ERROR_CODE | ||
| ); | ||
| } | ||
|  | ||
| if (strpos($fileInfo->getFilename(), 'recurring') === 0) { | ||
| $phpcsFile->addError( | ||
| 'Recurring scripts are obsolete. Please create class Recurring in module\'s Setup folder', | ||
| 0, | ||
| self::ERROR_CODE | ||
| ); | ||
| } | ||
|  | ||
| if (preg_match('/(sql|data)/', $fileInfo->getPath()) === 1) { | ||
| $phpcsFile->addError( | ||
| $fileInfo->getFilename()." is in an invalid directory ".$fileInfo->getPath().":\n" | ||
| . "- Create a data patch within module's Setup/Patch/Data folder for data upgrades.\n" | ||
| . "- Use declarative schema approach in module's etc/db_schema.xml file for schema changes.", | ||
| 0, | ||
| self::ERROR_CODE | ||
| ); | ||
| } | ||
| } | ||
| } | ||
   This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <?php | ||
| /** | ||
| * Copyright © Magento, Inc. All rights reserved. | ||
| * See COPYING.txt for license details. | ||
| */ | ||
| namespace Magento2\Tests\Legacy; | ||
|  | ||
| use DirectoryIterator; | ||
| use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; | ||
| use RecursiveDirectoryIterator; | ||
| use RecursiveIteratorIterator; | ||
|  | ||
| class InstallUpgradeUnitTest extends AbstractSniffUnitTest | ||
| { | ||
| private $wrongFileNames = [ | ||
| 'data-install-.inc', | ||
| 'data-upgrade-.inc', | ||
| 'install-sample.inc', | ||
| 'InstallData.inc', | ||
| 'InstallSchema.inc', | ||
| 'recurring.inc', | ||
| 'upgrade-.inc', | ||
| 'UpgradeData.inc', | ||
| 'UpgradeSchema.inc', | ||
| 'file.inc', | ||
| 'file2.inc', | ||
| ]; | ||
|  | ||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| protected function getTestFiles($testFileBase): array | ||
| { | ||
| $testFiles = []; | ||
|  | ||
| $dir = __DIR__.'/_files/InstallUpgradeUnitTest'; | ||
| $di = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); | ||
|  | ||
| /** | ||
| * @var DirectoryIterator $file | ||
| */ | ||
| foreach ($di as $file) { | ||
| if ($file->isDir()) { | ||
| continue; | ||
| } | ||
| $path = $file->getPathname(); | ||
| if ($path !== $testFileBase.'php' && substr($path, -5) !== 'fixed' && substr($path, -4) !== '.bak') { | ||
| $testFiles[] = $path; | ||
| } | ||
| } | ||
|  | ||
| // Put them in order. | ||
| sort($testFiles); | ||
|  | ||
| return $testFiles; | ||
| } | ||
|  | ||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function getErrorList($testFile = '') | ||
| { | ||
| if (in_array($testFile, $this->wrongFileNames)) { | ||
| return [ | ||
| 1 => 1 | ||
| ]; | ||
| } | ||
| return []; | ||
| } | ||
|  | ||
| /** | ||
| * @inheritdoc | ||
| */ | ||
| public function getWarningList() | ||
| { | ||
| return []; | ||
| } | ||
| } | 
   1 change: 1 addition & 0 deletions  1   Magento2/Tests/Legacy/_files/InstallUpgradeUnitTest/InstallData.inc          
     This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php | 
   1 change: 1 addition & 0 deletions  1   Magento2/Tests/Legacy/_files/InstallUpgradeUnitTest/InstallSchema.inc          
     This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php | 
   1 change: 1 addition & 0 deletions  1   Magento2/Tests/Legacy/_files/InstallUpgradeUnitTest/UpgradeData.inc          
     This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php | 
   1 change: 1 addition & 0 deletions  1   Magento2/Tests/Legacy/_files/InstallUpgradeUnitTest/UpgradeSchema.inc          
     This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php | 
   1 change: 1 addition & 0 deletions  1   Magento2/Tests/Legacy/_files/InstallUpgradeUnitTest/data-install-.inc          
     This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php | 
   1 change: 1 addition & 0 deletions  1   Magento2/Tests/Legacy/_files/InstallUpgradeUnitTest/data-upgrade-.inc          
     This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php | 
   1 change: 1 addition & 0 deletions  1   Magento2/Tests/Legacy/_files/InstallUpgradeUnitTest/data/file2.inc          
     This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php | 
   1 change: 1 addition & 0 deletions  1   Magento2/Tests/Legacy/_files/InstallUpgradeUnitTest/install-sample.inc          
     This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php | 
   1 change: 1 addition & 0 deletions  1   Magento2/Tests/Legacy/_files/InstallUpgradeUnitTest/recurring.inc          
     This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php | 
   1 change: 1 addition & 0 deletions  1   Magento2/Tests/Legacy/_files/InstallUpgradeUnitTest/sql/file.inc          
     This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php | 
   1 change: 1 addition & 0 deletions  1   Magento2/Tests/Legacy/_files/InstallUpgradeUnitTest/upgrade-.inc          
     This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php | 
   1 change: 1 addition & 0 deletions  1   Magento2/Tests/Legacy/_files/InstallUpgradeUnitTest/valid-file.inc          
     This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
     | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <?php | 
   This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters   
      Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.    
 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are doing the same logic with different data several times. Could you extract a method to simplify it?