কোড সদৃশতা যাচাই করতে ব্যবহৃত ম্যাজেন্টো 2 কমান্ডের কিছু বর্ণনা এখানে দেওয়া হল।
কোড সদৃশ / অনুলিপি-পরীক্ষা করার জন্য আদেশটি নীচে রয়েছে।
php bin/magento dev:tests:run static
এই কমান্ডটি প্রথমে dev/tests/staticফোল্ডারে যাবে। এখানে আপনি এই পরীক্ষার স্যুটটির জন্য ডিক্লারেশন ফাইল phpunit.xML.dist দেখতে পাবেন ।
<testsuites>
<testsuite name="Less Static Code Analysis">
<file>testsuite/Magento/Test/Less/LiveCodeTest.php</file>
</testsuite>
<testsuite name="Javascript Static Code Analysis">
<file>testsuite/Magento/Test/Js/LiveCodeTest.php</file>
</testsuite>
<testsuite name="PHP Coding Standard Verification">
<file>testsuite/Magento/Test/Php/LiveCodeTest.php</file>
</testsuite>
<testsuite name="Code Integrity Tests">
<directory>testsuite/Magento/Test/Integrity</directory>
</testsuite>
<testsuite name="Xss Unsafe Output Test">
<file>testsuite/Magento/Test/Php/XssPhtmlTemplateTest.php</file>
</testsuite>
</testsuites>
এই ফাইলটিতে আপনি উপরের কোডটি পাবেন যা বিভিন্ন কোড পরীক্ষার জন্য কোন ফাইলটি নির্বাহ করতে হবে তা সংজ্ঞায়িত করবে।
সঙ্কুচিত করতে আপনি দেখতে পাবেন PHP Coding Standard Verification testsuiteএটি ফাইল টেস্টসুইট / ম্যাজেন্টো / টেস্ট / পিএইচপি / লাইভকোডেস্ট.পিএফ চালাবে
আপনি যখন এই ফাইলটি খুলবেন, আপনি বিভিন্ন ধরণের কোডের সমস্যাগুলি পরীক্ষা করতে বিভিন্ন ফাংশন পাবেন। যে ফাংশনটি কার্যকর করা হবে তা হ'লtestCopyPaste
public function testCopyPaste()
{
$reportFile = self::$reportDir . '/phpcpd_report.xml';
$copyPasteDetector = new CopyPasteDetector($reportFile);
if (!$copyPasteDetector->canRun()) {
$this->markTestSkipped('PHP Copy/Paste Detector is not available.');
}
$blackList = [];
foreach (glob(__DIR__ . '/_files/phpcpd/blacklist/*.txt') as $list) {
$blackList = array_merge($blackList, file($list, FILE_IGNORE_NEW_LINES));
}
$copyPasteDetector->setBlackList($blackList);
$result = $copyPasteDetector->run([BP]);
$output = "";
if (file_exists($reportFile)) {
$output = file_get_contents($reportFile);
}
$this->assertTrue(
$result,
"PHP Copy/Paste Detector has found error(s):" . PHP_EOL . $output
);
}
এখানে, আপনি একটি কোড পাবেন যা এই কোড চেক থেকে কোনও ফাইল / ফোল্ডারকে কালো তালিকাভুক্ত করতে ব্যবহৃত হবে।
foreach (glob(__DIR__ . '/_files/phpcpd/blacklist/*.txt') as $list) {
$blackList = array_merge($blackList, file($list, FILE_IGNORE_NEW_LINES));
}
এই foreachফাংশনটি ডিভ / টেস্টস / স্ট্যাটিক / টেস্টুয়েট / ম্যাজেন্টো / টেস্ট / পিএইচপি / _ ফাইলস / পিএইচসিপিডি / ব্ল্যাকলিস্টের লোকেশনে.txt যুক্ত যে কোনও ফাইলের জন্য যাচাই করবে । এটি ফাইলটি পড়বে এবং অনুলিপি করে কপি পেস্ট কোড সনাক্তকরণ প্রক্রিয়া থেকে বাদ দিতে সমস্ত ফোল্ডার।
কোডে সমস্ত ব্ল্যাকলিস্ট ফাইল / ফোল্ডার যুক্ত করার পরে, এটি কোডের নীচে চলবে।
$result = $copyPasteDetector->run([BP]);
এই কোড চালানো হবে runফাংশন দেব / পরীক্ষার / স্ট্যাটিক / ফ্রেমওয়ার্ক / Magento / TestFramework / CodingStandard / টুল / CopyPasteDetector.php ফাইল।
public function run(array $whiteList)
{
$blackListStr = ' ';
foreach ($this->blacklist as $file) {
$file = escapeshellarg(trim($file));
if (!$file) {
continue;
}
$blackListStr .= '--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);
exec($command, $output, $exitCode);
return !(bool)$exitCode;
}
এখানে কোড তালিকায় সমস্ত blacklistedফোল্ডার / ফাইল যুক্ত করে --exclude।
এর পরে এটি vendor/bin/phpcpdকমান্ড চালাবে ।
এখানে কমান্ড নিজেই Magento আছে
Testকোড অনুসারে সমস্ত ফাইল বাদ দেয়
--names-exclude "*Test.php"
এটি কোড অনুসারে ১৩ টি লাইনের চেয়ে কম সমস্ত কোড সদৃশও এড়িয়ে গেছে
--min-lines 13
এই কমান্ড কার্যকর করার জন্য আউটপুট testCopyPasteফাংশনে সংজ্ঞায়িত ফাইলে যুক্ত করা হবে । অনুলিপি-পেস্ট সনাক্তকরণের ফাইলের নামটি phpcpd_report.xML যা dev / টেস্টস / স্থির / প্রতিবেদনের স্থানে অবস্থিত।
কমান্ডটি সফলভাবে প্রয়োগের পরে, ফাইলগুলি প্রতিবেদন করতে আউটপুট যুক্ত করা হবে।