From 0b6fe4b2aaa000dc5b8d3bfba49e7ee11cf9583c Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Mon, 30 Aug 2021 13:55:52 +0200 Subject: [PATCH 1/3] AC-943: Create unit test for Magento2\Less\ColourDefinitionSniff check --- .../Sniffs/Less/ColourDefinitionSniff.php | 2 +- .../Tests/Less/ColourDefinitionUnitTest.less | 24 +++++++++++++++ .../Tests/Less/ColourDefinitionUnitTest.php | 29 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 Magento2/Tests/Less/ColourDefinitionUnitTest.less create mode 100644 Magento2/Tests/Less/ColourDefinitionUnitTest.php diff --git a/Magento2/Sniffs/Less/ColourDefinitionSniff.php b/Magento2/Sniffs/Less/ColourDefinitionSniff.php index 82568824..afebb9a9 100644 --- a/Magento2/Sniffs/Less/ColourDefinitionSniff.php +++ b/Magento2/Sniffs/Less/ColourDefinitionSniff.php @@ -42,7 +42,7 @@ public function process(File $phpcsFile, $stackPtr) $variablePtr = $phpcsFile->findPrevious(T_ASPERAND, $stackPtr); if ((false === $variablePtr) || ($tokens[$stackPtr]['line'] !== $tokens[$variablePtr]['line'])) { - $phpcsFile->addError('Hexadecimal value should be used for variable', $stackPtr, 'NotInVariable'); + $phpcsFile->addError('Hexadecimal value should be get from a variable', $stackPtr, 'NotInVariable'); } $expected = strtolower($colour); diff --git a/Magento2/Tests/Less/ColourDefinitionUnitTest.less b/Magento2/Tests/Less/ColourDefinitionUnitTest.less new file mode 100644 index 00000000..e32323f9 --- /dev/null +++ b/Magento2/Tests/Less/ColourDefinitionUnitTest.less @@ -0,0 +1,24 @@ +// /** +// * Copyright © Magento, Inc. All rights reserved. +// * See COPYING.txt for license details. +// */ + +@red: #aaaaaa; +@blue: #00F; +@green: #0f0; + +.my{ + color: @red; +} + +.foo { + color: #aaa; +} + +.baz { + color: @blue; +} + +.bar { + color: @green; +} diff --git a/Magento2/Tests/Less/ColourDefinitionUnitTest.php b/Magento2/Tests/Less/ColourDefinitionUnitTest.php new file mode 100644 index 00000000..34862ed2 --- /dev/null +++ b/Magento2/Tests/Less/ColourDefinitionUnitTest.php @@ -0,0 +1,29 @@ + 1, + 7 => 1, + 15 => 1, + ]; + } + + /** + * @inheritdoc + */ + public function getWarningList() + { + return []; + } +} From 1153ab2177f93520f507e8e766c837fb1ed39c5d Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 31 Aug 2021 12:07:41 +0200 Subject: [PATCH 2/3] AC-943: Create unit test for Magento2\Less\ColourDefinitionSniff check --- Magento2/Sniffs/Less/ColourDefinitionSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Less/ColourDefinitionSniff.php b/Magento2/Sniffs/Less/ColourDefinitionSniff.php index afebb9a9..945abffd 100644 --- a/Magento2/Sniffs/Less/ColourDefinitionSniff.php +++ b/Magento2/Sniffs/Less/ColourDefinitionSniff.php @@ -42,7 +42,7 @@ public function process(File $phpcsFile, $stackPtr) $variablePtr = $phpcsFile->findPrevious(T_ASPERAND, $stackPtr); if ((false === $variablePtr) || ($tokens[$stackPtr]['line'] !== $tokens[$variablePtr]['line'])) { - $phpcsFile->addError('Hexadecimal value should be get from a variable', $stackPtr, 'NotInVariable'); + $phpcsFile->addError('A variable should be used for a CSS colour', $stackPtr, 'NotInVariable'); } $expected = strtolower($colour); From 33d319696542441162c71fab1925bcb3357d90c5 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Wed, 1 Sep 2021 17:00:18 +0200 Subject: [PATCH 3/3] AC-943: Create unit test for Magento2\Less\ColourDefinitionSniff check --- Magento2/Tests/Less/ColourDefinitionUnitTest.less | 1 + Magento2/Tests/Less/ColourDefinitionUnitTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Magento2/Tests/Less/ColourDefinitionUnitTest.less b/Magento2/Tests/Less/ColourDefinitionUnitTest.less index e32323f9..49af23a9 100644 --- a/Magento2/Tests/Less/ColourDefinitionUnitTest.less +++ b/Magento2/Tests/Less/ColourDefinitionUnitTest.less @@ -6,6 +6,7 @@ @red: #aaaaaa; @blue: #00F; @green: #0f0; +@purple: #abcdef; .my{ color: @red; diff --git a/Magento2/Tests/Less/ColourDefinitionUnitTest.php b/Magento2/Tests/Less/ColourDefinitionUnitTest.php index 34862ed2..890a39ca 100644 --- a/Magento2/Tests/Less/ColourDefinitionUnitTest.php +++ b/Magento2/Tests/Less/ColourDefinitionUnitTest.php @@ -15,7 +15,7 @@ public function getErrorList() return [ 6 => 1, 7 => 1, - 15 => 1, + 16 => 1, ]; }