From 09f3c9d2629b0b573b6fb03c4e9871d1ba998c5b Mon Sep 17 00:00:00 2001
From: Olga Kopylova <okopylova@magento.com>
Date: Fri, 21 Oct 2016 10:50:03 -0500
Subject: [PATCH] MAGETWO-58693: Refactor Module_Integration,
 Module_MarketPlace

- improved Copy-Paste static test to allow file names in the blacklist
---
 .../CodingStandard/Tool/CopyPasteDetector.php | 32 +++++++++++++------
 .../Php/_files/phpcpd/blacklist/common.txt    |  4 +--
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/dev/tests/static/framework/Magento/TestFramework/CodingStandard/Tool/CopyPasteDetector.php b/dev/tests/static/framework/Magento/TestFramework/CodingStandard/Tool/CopyPasteDetector.php
index b2d9c164fbd..b2766ebd90d 100644
--- a/dev/tests/static/framework/Magento/TestFramework/CodingStandard/Tool/CopyPasteDetector.php
+++ b/dev/tests/static/framework/Magento/TestFramework/CodingStandard/Tool/CopyPasteDetector.php
@@ -56,8 +56,7 @@ class CopyPasteDetector implements ToolInterface, BlacklistInterface
      */
     public function canRun()
     {
-        $vendorDir = require BP . '/app/etc/vendor_path.php';
-        exec('php ' . BP . '/' . $vendorDir . '/bin/phpcpd --version', $output, $exitCode);
+        exec($this->getCommand() . ' --version', $output, $exitCode);
         return $exitCode === 0;
     }
 
@@ -71,22 +70,37 @@ class CopyPasteDetector implements ToolInterface, BlacklistInterface
      */
     public function run(array $whiteList)
     {
-        $blackListStr = ' ';
+        $blacklistedDirs = [];
+        $blacklistedFileNames = [];
         foreach ($this->blacklist as $file) {
             $file = escapeshellarg(trim($file));
             if (!$file) {
                 continue;
             }
-            $blackListStr .= '--exclude ' . $file . ' ';
+            $ext = pathinfo($file, PATHINFO_EXTENSION);
+            if ($ext != '') {
+                $blacklistedFileNames[] = $file;
+            } else {
+                $blacklistedDirs[] = '--exclude ' . $file . ' ';
+            }
         }
 
-        $vendorDir = require BP . '/app/etc/vendor_path.php';
-        $command = 'php ' . BP . '/' . $vendorDir . '/bin/phpcpd' . ' --log-pmd ' . escapeshellarg(
-                $this->reportFile
-            ) . ' --names-exclude "*Test.php" --min-lines 13' . $blackListStr . ' ' . implode(' ', $whiteList);
-
+        $command = $this->getCommand() . ' --log-pmd ' . escapeshellarg($this->reportFile)
+            . ' --names-exclude ' . join(',', $blacklistedFileNames) . ' --min-lines 13 ' . join(' ', $blacklistedDirs)
+            . ' ' . implode(' ', $whiteList);
         exec($command, $output, $exitCode);
 
         return !(bool)$exitCode;
     }
+
+    /**
+     * Get PHPCPD command
+     *
+     * @return string
+     */
+    private function getCommand()
+    {
+        $vendorDir = require BP . '/app/etc/vendor_path.php';
+        return 'php ' . BP . '/' . $vendorDir . '/bin/phpcpd';
+    }
 }
diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt
index 19b152df88f..3afe3af79b1 100644
--- a/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt
+++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist/common.txt
@@ -197,5 +197,5 @@ Magento/Framework/View/File/Collector/Override
 Magento/Framework/MessageQueue/Consumer/Config/ConsumerConfigItem
 Magento/Framework/MessageQueue/Publisher/Config/PublisherConfigItem
 Magento/Framework/MessageQueue/Topology/Config/ExchangeConfigItem
-Magento/Integration/Model/Config
-Magento/Integration/Model/IntegrationConfig
+IntegrationConfig.php
+*Test.php
-- 
GitLab