diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index f65294a..672d3ee 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -10,11 +10,15 @@ return (new Config()) ->setRules([ - '@PSR12' => true, - 'array_indentation' => true, - '@PHP83Migration' => true, + '@PER-CS' => true, + '@PHP84Migration' => true, + 'fully_qualified_strict_types' => [ + 'import_symbols' => true, + ], + 'global_namespace_import' => true, + ]) ->setFinder($finder) ->setUsingCache(true) ->setCacheFile(__DIR__ . '/tools/cache/.php-cs-fixer.cache') - ->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect()); \ No newline at end of file + ->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect()); diff --git a/docs/usage.md b/docs/usage.md index 545881a..85b06f4 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -27,7 +27,7 @@ Result: Usage: ------ - php-css-lint [--options='{ }'] css_file_or_string_to_lint + php-css-lint [--options='{ }'] input_to_lint Arguments: ---------- @@ -40,17 +40,20 @@ Arguments: * "nonStandards": { "property" => bool }: will merge with the current property Example: --options='{ "constructors": {"o" : false}, "allowedIndentationChars": ["\t"] }' - css_file_or_string_to_lint - The CSS file path (absolute or relative) or a CSS string to be linted + input_to_lint + The CSS file path (absolute or relative) + a glob pattern of file(s) to be linted + or a CSS string to be linted Example: - ./path/to/css_file_path_to_lint.css + "./path/to/css_file_path_to_lint.css" + "./path/to/css_file_path_to_lint/*.css" ".test { color: red; }" Examples: --------- Lint a CSS file: - php-css-lint ./path/to/css_file_path_to_lint.css + php-css-lint "./path/to/css_file_path_to_lint.css" Lint a CSS string: php-css-lint ".test { color: red; }" @@ -64,7 +67,7 @@ Examples: In a terminal, execute: ```sh -php vendor/bin/php-css-lint /path/to/not_valid_file.css +php vendor/bin/php-css-lint "/path/to/not_valid_file.css" ``` Result: @@ -77,6 +80,29 @@ Result: - Unterminated "selector content" (line: 17, char: 0) ``` +### Lint file(s) matching a glob pattern + +See for supported patterns. + +In a terminal, execute: + +```sh +php vendor/bin/php-css-lint "/path/to/*.css" +``` + +Result: + +``` +# Lint CSS file "/path/to/not_valid_file.css"... + => CSS file "/path/to/not_valid_file" is not valid: + + - Unknown CSS property "bordr-top-style" (line: 8, char: 20) + - Unterminated "selector content" (line: 17, char: 0) + +# Lint CSS file "/path/to/valid_file.css"... + => CSS file "/path/to/valid_file" is valid +``` + ### Lint a css string In a terminal, execute: diff --git a/scripts/php-css-lint b/scripts/php-css-lint index ba82697..c494630 100755 --- a/scripts/php-css-lint +++ b/scripts/php-css-lint @@ -5,29 +5,29 @@ echo PHP_EOL . '===========================================================' . PHP_EOL . PHP_EOL . ' ____ _ ____ ____ ____ _ _ _ ' . PHP_EOL . ' | _ \| |__ _ __ / ___/ ___/ ___| | | (_)_ __ | |_ ' . PHP_EOL . - ' | |_) | \'_ \| \'_ \ | | \___ \___ \ | | | | \'_ \| __|' . PHP_EOL . + " | |_) | '_ \| '_ \ | | \___ \___ \ | | | | '_ \| __|" . PHP_EOL . ' | __/| | | | |_) | | |___ ___) |__) | | |___| | | | | |_ ' . PHP_EOL . ' |_| |_| |_| .__/ \____|____/____/ |_____|_|_| |_|\__|' . PHP_EOL . ' |_| ' . PHP_EOL . PHP_EOL . '===========================================================' . PHP_EOL . PHP_EOL; -$sComposerAutoloaderWorkingDirectory = getcwd() . '/vendor/autoload.php'; -if (is_file($sComposerAutoloaderWorkingDirectory)) { - require_once $sComposerAutoloaderWorkingDirectory; +$composerAutoloaderWorkingDirectory = getcwd() . '/vendor/autoload.php'; +if (is_file($composerAutoloaderWorkingDirectory)) { + require_once $composerAutoloaderWorkingDirectory; } if (!class_exists('CssLint\CssLint', true)) { // consider being in bin dir - $sComposerAutoloader = __DIR__ . '/../vendor/autoload.php'; - if (!is_file($sComposerAutoloader)) { + $composerAutoloader = __DIR__ . '/../vendor/autoload.php'; + if (!is_file($composerAutoloader)) { // consider being in vendor/neilime/php-css-lint/scripts - $sComposerAutoloader = __DIR__ . '/../../../autoload.php'; + $composerAutoloader = __DIR__ . '/../../../autoload.php'; } - require_once $sComposerAutoloader; + require_once $composerAutoloader; } -$oCssLintCli = new \CssLint\Cli(); -$iReturnCode = $oCssLintCli->run($_SERVER['argv']); +$cssLintCli = new \CssLint\Cli(); +$returnCode = $cssLintCli->run($_SERVER['argv']); -exit($iReturnCode); +exit($returnCode); diff --git a/src/CssLint/Cli.php b/src/CssLint/Cli.php index 2374c4b..7016705 100644 --- a/src/CssLint/Cli.php +++ b/src/CssLint/Cli.php @@ -4,6 +4,9 @@ namespace CssLint; +use RuntimeException; +use Throwable; + /** * @phpstan-import-type Errors from \CssLint\Linter * @package CssLint @@ -24,58 +27,21 @@ class Cli public function run(array $arguments): int { $cliArgs = $this->parseArguments($arguments); - if ($cliArgs->filePathOrCssString === null || $cliArgs->filePathOrCssString === '' || $cliArgs->filePathOrCssString === '0') { + if ($cliArgs->input === null || $cliArgs->input === '' || $cliArgs->input === '0') { $this->printUsage(); return self::RETURN_CODE_SUCCESS; } - $properties = new \CssLint\Properties(); - if ($cliArgs->options !== null && $cliArgs->options !== '' && $cliArgs->options !== '0') { - $options = json_decode($cliArgs->options, true); - - if (json_last_error() !== 0) { - $errorMessage = json_last_error_msg(); - $this->printError('Unable to parse option argument: ' . $errorMessage); - return self::RETURN_CODE_ERROR; - } - - if (!$options) { - $this->printError('Unable to parse empty option argument'); - return self::RETURN_CODE_ERROR; - } + try { + $properties = $this->getPropertiesFromOptions($cliArgs->options); - if (!is_array($options)) { - $this->printError('Unable to parse option argument: must be a json object'); - return self::RETURN_CODE_ERROR; - } - - $properties->setOptions($options); - } + $cssLinter = new Linter($properties); - $cssLinter = new \CssLint\Linter($properties); - - $filePathOrCssString = $cliArgs->filePathOrCssString; - if (!file_exists($filePathOrCssString)) { - return $this->lintString($cssLinter, $filePathOrCssString); - } - - $filePath = $filePathOrCssString; - if (!is_readable($filePath)) { - $this->printError('File "' . $filePath . '" is not readable'); + return $this->lintInput($cssLinter, $cliArgs->input); + } catch (Throwable $throwable) { + $this->printError($throwable->getMessage()); return self::RETURN_CODE_ERROR; } - - return $this->lintFile($cssLinter, $filePath); - } - - /** - * Retrieve the parsed Cli arguments from given arguments array - * @param string[] $arguments arguments to be parsed (@see $_SERVER['argv']) - * @return \CssLint\CliArgs an instance of Cli arguments object containing parsed arguments - */ - private function parseArguments(array $arguments): \CssLint\CliArgs - { - return new \CssLint\CliArgs($arguments); } /** @@ -86,7 +52,7 @@ private function printUsage(): void $this->printLine('Usage:' . PHP_EOL . '------' . PHP_EOL . PHP_EOL . - ' ' . self::SCRIPT_NAME . " [--options='{ }'] css_file_or_string_to_lint" . PHP_EOL . + ' ' . self::SCRIPT_NAME . " [--options='{ }'] input_to_lint" . PHP_EOL . PHP_EOL . 'Arguments:' . PHP_EOL . '----------' . PHP_EOL . @@ -100,35 +66,143 @@ private function printUsage(): void ' Example: --options=\'{ "constructors": {"o" : false}, "allowedIndentationChars": ["\t"] }\'' . PHP_EOL . PHP_EOL . - ' css_file_or_string_to_lint' . PHP_EOL . - ' The CSS file path (absolute or relative) or a CSS string to be linted' . PHP_EOL . + ' input_to_lint' . PHP_EOL . + ' The CSS file path (absolute or relative)' . PHP_EOL . + ' a glob pattern of file(s) to be linted' . PHP_EOL . + ' or a CSS string to be linted' . PHP_EOL . ' Example:' . PHP_EOL . - ' ./path/to/css_file_path_to_lint.css' . PHP_EOL . + ' "./path/to/css_file_path_to_lint.css"' . PHP_EOL . + ' "./path/to/css_file_path_to_lint/*.css"' . PHP_EOL . ' ".test { color: red; }"' . PHP_EOL . PHP_EOL . 'Examples:' . PHP_EOL . '---------' . PHP_EOL . PHP_EOL . ' Lint a CSS file:' . PHP_EOL . - ' ' . self::SCRIPT_NAME . ' ./path/to/css_file_path_to_lint.css' . PHP_EOL . PHP_EOL . + ' ' . self::SCRIPT_NAME . ' "./path/to/css_file_path_to_lint.css"' . PHP_EOL . PHP_EOL . ' Lint a CSS string:' . PHP_EOL . - ' ' . self::SCRIPT_NAME . ' ".test { color: red; }"' . PHP_EOL . PHP_EOL . + ' ' . self::SCRIPT_NAME . ' ".test { color: red; }"' . PHP_EOL . PHP_EOL . ' Lint with only tabulation as indentation:' . PHP_EOL . ' ' . self::SCRIPT_NAME . ' --options=\'{ "allowedIndentationChars": ["\t"] }\' ".test { color: red; }"' . PHP_EOL . PHP_EOL . PHP_EOL); } + /** + * Retrieve the parsed Cli arguments from given arguments array + * @param string[] $arguments arguments to be parsed (@see $_SERVER['argv']) + * @return CliArgs an instance of Cli arguments object containing parsed arguments + */ + private function parseArguments(array $arguments): CliArgs + { + return new CliArgs($arguments); + } + + /** + * Retrieve the properties from the given options + * @param string $options the options to be parsed + */ + private function getPropertiesFromOptions(?string $options): Properties + { + $properties = new Properties(); + if ($options === null || $options === '' || $options === '0') { + return $properties; + } + + $options = json_decode($options, true); + + if (json_last_error() !== 0) { + $errorMessage = json_last_error_msg(); + throw new RuntimeException('Unable to parse option argument: ' . $errorMessage); + } + + if (!$options) { + throw new RuntimeException('Unable to parse empty option argument'); + } + + if (!is_array($options)) { + throw new RuntimeException('Unable to parse option argument: must be a json object'); + } + + $properties->setOptions($options); + + return $properties; + } + + private function lintInput(Linter $cssLinter, string $input): int + { + if (file_exists($input)) { + return $this->lintFile($cssLinter, $input); + } + + if ($this->isGlobPattern($input)) { + return $this->lintGlob($input); + } + + return $this->lintString($cssLinter, $input); + } + + /** + * Checks if a given string is a glob pattern. + * + * A glob pattern typically includes wildcard characters: + * - '*' matches any sequence of characters. + * - '?' matches any single character. + * - '[]' matches any one character in the specified set. + * + * Optionally, if using the GLOB_BRACE flag, brace patterns like {foo,bar} are also valid. + * + * @param string $pattern The string to evaluate. + * @return bool True if the string is a glob pattern, false otherwise. + */ + private function isGlobPattern(string $pattern): bool + { + // Must be one line, no unscaped spaces + if (preg_match('/\s/', $pattern)) { + return false; + } + + // Check for basic wildcard characters. + if (str_contains($pattern, '*') || str_contains($pattern, '?') || str_contains($pattern, '[')) { + return true; + } + + // Optionally check for brace patterns, used with GLOB_BRACE. + return str_contains($pattern, '{') || str_contains($pattern, '}'); + } + + private function lintGlob(string $glob): int + { + $cssLinter = new Linter(); + $files = glob($glob); + if ($files === [] || $files === false) { + $this->printError('No files found for glob "' . $glob . '"'); + return self::RETURN_CODE_ERROR; + } + + $returnCode = self::RETURN_CODE_SUCCESS; + foreach ($files as $file) { + $returnCode = max($returnCode, $this->lintFile($cssLinter, $file)); + } + + return $returnCode; + } + /** * Performs lint on a given file path - * @param \CssLint\Linter $cssLinter the instance of the linter + * @param Linter $cssLinter the instance of the linter * @param string $filePath the path of the file to be linted * @return int the return code related to the execution of the linter */ - private function lintFile(\CssLint\Linter $cssLinter, string $filePath): int + private function lintFile(Linter $cssLinter, string $filePath): int { $this->printLine('# Lint CSS file "' . $filePath . '"...'); + if (!is_readable($filePath)) { + $this->printError('File "' . $filePath . '" is not readable'); + return self::RETURN_CODE_ERROR; + } + if ($cssLinter->lintFile($filePath)) { $this->printLine("\033[32m => CSS file \"" . $filePath . "\" is valid\033[0m" . PHP_EOL); return self::RETURN_CODE_SUCCESS; @@ -142,11 +216,11 @@ private function lintFile(\CssLint\Linter $cssLinter, string $filePath): int /** * Performs lint on a given string - * @param \CssLint\Linter $cssLinter the instance of the linter + * @param Linter $cssLinter the instance of the linter * @param string $stringValue the CSS string to be linted * @return int the return code related to the execution of the linter */ - private function lintString(\CssLint\Linter $cssLinter, string $stringValue): int + private function lintString(Linter $cssLinter, string $stringValue): int { $this->printLine('# Lint CSS string...'); diff --git a/src/CssLint/CliArgs.php b/src/CssLint/CliArgs.php index 6eba7ed..ed3202e 100644 --- a/src/CssLint/CliArgs.php +++ b/src/CssLint/CliArgs.php @@ -11,7 +11,7 @@ */ class CliArgs { - public ?string $filePathOrCssString = null; + public ?string $input = null; public ?string $options = null; @@ -29,7 +29,7 @@ public function __construct(array $arguments) array_shift($arguments); - $this->filePathOrCssString = array_pop($arguments); + $this->input = array_pop($arguments); if ($arguments !== []) { $parsedArguments = $this->parseArguments($arguments); diff --git a/src/CssLint/Linter.php b/src/CssLint/Linter.php index 3189db1..e10cd6a 100644 --- a/src/CssLint/Linter.php +++ b/src/CssLint/Linter.php @@ -4,6 +4,9 @@ namespace CssLint; +use InvalidArgumentException; +use RuntimeException; + /** * @package CssLint * @phpstan-type Errors array @@ -24,7 +27,7 @@ class Linter /** * Class to provide css properties knowledge - * @var \CssLint\Properties|null + * @var Properties|null */ protected $cssLintProperties; @@ -78,11 +81,11 @@ class Linter /** * Constructor - * @param \CssLint\Properties $oProperties (optional) an instance of the "\CssLint\Properties" helper + * @param Properties $oProperties (optional) an instance of the "\CssLint\Properties" helper */ - public function __construct(\CssLint\Properties $oProperties = null) + public function __construct(?Properties $oProperties = null) { - if ($oProperties instanceof \CssLint\Properties) { + if ($oProperties instanceof Properties) { $this->setCssLintProperties($oProperties); } } @@ -114,20 +117,20 @@ public function lintString(string $stringValue): bool * Performs lint for a given file path * @param string $sFilePath : a path of an existing and readable file * @return boolean : true if the file is a valid css file, else false - * @throws \InvalidArgumentException - * @throws \RuntimeException + * @throws InvalidArgumentException + * @throws RuntimeException */ public function lintFile(string $sFilePath): bool { if (!file_exists($sFilePath)) { - throw new \InvalidArgumentException(sprintf( + throw new InvalidArgumentException(sprintf( 'Argument "$sFilePath" "%s" is not an existing file path', $sFilePath )); } if (!is_readable($sFilePath)) { - throw new \InvalidArgumentException(sprintf( + throw new InvalidArgumentException(sprintf( 'Argument "$sFilePath" "%s" is not a readable file path', $sFilePath )); @@ -135,7 +138,7 @@ public function lintFile(string $sFilePath): bool $rFileHandle = fopen($sFilePath, 'r'); if ($rFileHandle === false) { - throw new \RuntimeException('An error occurred while opening file "' . $sFilePath . '"'); + throw new RuntimeException('An error occurred while opening file "' . $sFilePath . '"'); } $this->initLint(); @@ -148,7 +151,7 @@ public function lintFile(string $sFilePath): bool } if (!feof($rFileHandle)) { - throw new \RuntimeException('An error occurred while reading file "' . $sFilePath . '"'); + throw new RuntimeException('An error occurred while reading file "' . $sFilePath . '"'); } fclose($rFileHandle); @@ -694,19 +697,19 @@ protected function setComment(bool $comment): void /** * Return an instance of the "\CssLint\Properties" helper, initialize a new one if not define already */ - public function getCssLintProperties(): \CssLint\Properties + public function getCssLintProperties(): Properties { if ($this->cssLintProperties) { return $this->cssLintProperties; } - return $this->cssLintProperties = new \CssLint\Properties(); + return $this->cssLintProperties = new Properties(); } /** * Set an instance of the "\CssLint\Properties" helper */ - public function setCssLintProperties(\CssLint\Properties $cssLintProperties): self + public function setCssLintProperties(Properties $cssLintProperties): self { $this->cssLintProperties = $cssLintProperties; return $this; diff --git a/tests/TestSuite/CliTest.php b/tests/TestSuite/CliTest.php index 181fbfd..5a3ace3 100644 --- a/tests/TestSuite/CliTest.php +++ b/tests/TestSuite/CliTest.php @@ -2,21 +2,23 @@ namespace TestSuite; -class CliTest extends \PHPUnit\Framework\TestCase +use CssLint\Cli; +use PHPUnit\Framework\TestCase; + +class CliTest extends TestCase { - /** - * @var \CssLint\Cli - */ - protected $cli; + private $testFilesDir; /** - * @var string + * @var Cli */ - protected $phpVersion; + private $cli; protected function setUp(): void { - $this->cli = new \CssLint\Cli(); + $this->testFilesDir = realpath(__DIR__ . '/../_files'); + + $this->cli = new Cli(); } public function testRunWithoutArgumentMustReturnsErrorCode() @@ -34,7 +36,11 @@ public function testRunWithValidStringShouldReturnSuccessCode() "\033[32m => CSS string is valid\033[0m" . PHP_EOL . PHP_EOL ); - $this->assertEquals(0, $this->cli->run(['php-css-lint', '.test { display: block; }'])); + $this->assertEquals( + 0, + $this->cli->run(['php-css-lint', '.test { display: block; }']), + $this->getActualOutput() + ); } public function testRunWithNotValidStringShouldReturnErrorCode() @@ -54,7 +60,7 @@ public function testRunWithNotValidStringShouldReturnErrorCode() public function testRunWithValidFileShouldReturnSuccessCode() { - $fileToLint = realpath(__DIR__ . '/../_files/valid.css'); + $fileToLint = $this->testFilesDir . '/valid.css'; $this->expectOutputString( "# Lint CSS file \"$fileToLint\"..." . PHP_EOL . "\033[32m => CSS file \"$fileToLint\" is valid\033[0m" . PHP_EOL . @@ -65,7 +71,7 @@ public function testRunWithValidFileShouldReturnSuccessCode() public function testRunWithNotValidFileShouldReturnErrorCode() { - $fileToLint = realpath(__DIR__ . '/../_files/not_valid.css'); + $fileToLint = $this->testFilesDir . '/not_valid.css'; $this->expectOutputString( "# Lint CSS file \"$fileToLint\"..." . PHP_EOL . @@ -78,6 +84,43 @@ public function testRunWithNotValidFileShouldReturnErrorCode() $this->assertEquals(1, $this->cli->run(['php-css-lint', $fileToLint])); } + public function testRunWithGlobShouldReturnSuccessCode() + { + $fileToLint = $this->testFilesDir . '/valid.css'; + $this->expectOutputString( + "# Lint CSS file \"$fileToLint\"..." . PHP_EOL . + "\033[32m => CSS file \"$fileToLint\" is valid\033[0m" . PHP_EOL . + PHP_EOL + ); + $this->assertEquals(0, $this->cli->run(['php-css-lint', $this->testFilesDir . '/valid*.css'])); + } + + public function testRunWithNoFilesGlobShouldReturnErrorCode() + { + $filesToLint = $this->testFilesDir . '/unknown*.css'; + + $this->expectOutputString( + "\033[31m/!\ Error: No files found for glob \"$filesToLint\"\033[0m" . PHP_EOL . + PHP_EOL + ); + $this->assertEquals(1, $this->cli->run(['php-css-lint', $filesToLint])); + } + + + public function testRunWithNotValidFileGlobShouldReturnErrorCode() + { + $fileToLint = $this->testFilesDir . '/not_valid.css'; + $this->expectOutputString( + "# Lint CSS file \"$fileToLint\"..." . PHP_EOL . + "\033[31m => CSS file \"$fileToLint\" is not valid:\033[0m" . PHP_EOL . + PHP_EOL . + "\033[31m - Unknown CSS property \"bordr-top-style\" (line: 8, char: 20)\033[0m" . PHP_EOL . + "\033[31m - Unterminated \"selector content\" (line: 17, char: 0)\033[0m" . PHP_EOL . + PHP_EOL + ); + $this->assertEquals(1, $this->cli->run(['php-css-lint', $this->testFilesDir . '/not_valid*.css'])); + } + public function testRunWithOptionsMustBeUsedByTheLinter() { $this->expectOutputString( diff --git a/tests/TestSuite/LinterTest.php b/tests/TestSuite/LinterTest.php index 4391c44..e723216 100644 --- a/tests/TestSuite/LinterTest.php +++ b/tests/TestSuite/LinterTest.php @@ -5,11 +5,16 @@ use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamDirectory; use org\bovigo\vfs\vfsStreamFile; +use CssLint\Linter; +use CssLint\Properties; +use PHPUnit\Framework\TestCase; +use InvalidArgumentException; +use TypeError; -class LinterTest extends \PHPUnit\Framework\TestCase +class LinterTest extends TestCase { /** - * @var \CssLint\Linter + * @var Linter */ protected $linter; @@ -20,15 +25,15 @@ class LinterTest extends \PHPUnit\Framework\TestCase protected function setUp(): void { - $this->linter = new \CssLint\Linter(); + $this->linter = new Linter(); $this->root = vfsStream::setup('testDir'); } public function testConstructWithCustomCssLintProperties() { - $properties = new \CssLint\Properties(); - $linter = new \CssLint\Linter($properties); + $properties = new Properties(); + $linter = new Linter($properties); $this->assertSame($properties, $linter->getCssLintProperties()); } @@ -127,7 +132,7 @@ public function testLintStringWithWrongSelectorUnexpectedToken() public function testLintStringWithWrongTypeParam() { - $this->expectException(\TypeError::class); + $this->expectException(TypeError::class); $this->expectExceptionMessage( 'CssLint\Linter::lintString(): Argument #1 ($stringValue) must be of type string, array given' ); @@ -136,7 +141,7 @@ public function testLintStringWithWrongTypeParam() public function testLintFileWithWrongTypeParam() { - $this->expectException(\TypeError::class); + $this->expectException(TypeError::class); $this->expectExceptionMessage( 'CssLint\Linter::lintFile(): Argument #1 ($sFilePath) must be of type string, array given' ); @@ -145,14 +150,14 @@ public function testLintFileWithWrongTypeParam() public function testLintFileWithUnknownFilePathParam() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Argument "$sFilePath" "wrong" is not an existing file path'); $this->linter->lintFile('wrong'); } public function testLintFileWithUnreadableFilePathParam() { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Argument "$sFilePath" "vfs://testDir/foo.txt" is not a readable file path'); $testFile = new vfsStreamFile('foo.txt', 0o000); @@ -168,7 +173,7 @@ public function testLintFileWithUnreadableFilePathParam() public function testLintBootstrapCssFile() { $this->assertTrue( - $this->linter->lintFile(__DIR__ . '/../_files/bootstrap.css'), + $this->linter->lintFile(__DIR__ . '/../_files/bootstrap.css'), print_r($this->linter->getErrors(), true) ); } @@ -176,14 +181,14 @@ public function testLintBootstrapCssFile() public function testLintFoundationCssFile() { $this->assertTrue( - $this->linter->lintFile(__DIR__ . '/../_files/foundation.css'), + $this->linter->lintFile(__DIR__ . '/../_files/foundation.css'), print_r($this->linter->getErrors(), true) ); } public function testLintNotValidCssFile() { - $this->assertFalse($this->linter->lintFile(__DIR__ . '/../_files/not_valid.css')); + $this->assertFalse($this->linter->lintFile(__DIR__ . '/../_files/not_valid.css')); $this->assertSame([ 'Unknown CSS property "bordr-top-style" (line: 8, char: 20)', 'Unterminated "selector content" (line: 17, char: 0)', diff --git a/tests/TestSuite/PropertiesTest.php b/tests/TestSuite/PropertiesTest.php index 2043cf8..6c76bea 100644 --- a/tests/TestSuite/PropertiesTest.php +++ b/tests/TestSuite/PropertiesTest.php @@ -2,41 +2,44 @@ namespace TestSuite; -class PropertiesTest extends \PHPUnit\Framework\TestCase +use CssLint\Properties; +use PHPUnit\Framework\TestCase; + +class PropertiesTest extends TestCase { public function testShouldReturnTrueWhenGivenStandardPropertyExists() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertTrue($oProperties->propertyExists('align-content')); } public function testShouldReturnTrueWhenGivenConstructorStandardPropertyExists() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertTrue($oProperties->propertyExists('-moz-align-content')); } public function testShouldReturnTrueWhenGivenConstructorNonStandardPropertyExists() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertTrue($oProperties->propertyExists('-moz-font-smoothing')); } public function testShouldReturnTrueWhenGivenPropertyDoesNotExist() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertFalse($oProperties->propertyExists('-wrong-font-smoothing')); } public function testGetAllowedIndentationChars() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertEquals([" "], $oProperties->getAllowedIndentationChars()); } public function testSetAllowedIndentationChars() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $aAllowedIndentationChars = ["\t"]; $oProperties->setAllowedIndentationChars($aAllowedIndentationChars); $this->assertEquals($aAllowedIndentationChars, $oProperties->getAllowedIndentationChars()); @@ -44,19 +47,19 @@ public function testSetAllowedIndentationChars() public function testShouldReturnTrueWhenGivenCharIsAnAllowedIndentationChar() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertTrue($oProperties->isAllowedIndentationChar(" ")); } public function testShouldReturnTrueWhenGivenCharIsNotAnAllowedIndentationChar() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertFalse($oProperties->isAllowedIndentationChar("\t")); } public function testMergeConstructorsShouldDisableAContructor() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertTrue($oProperties->propertyExists('-moz-font-smoothing')); $oProperties->mergeConstructors(['moz' => false]); @@ -65,7 +68,7 @@ public function testMergeConstructorsShouldDisableAContructor() public function testMergeConstructorsShouldAddAContructor() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertFalse($oProperties->propertyExists('-new-font-smoothing')); $oProperties->mergeConstructors(['new' => true]); @@ -74,7 +77,7 @@ public function testMergeConstructorsShouldAddAContructor() public function testMergeStandardsShouldDisableAContructor() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertTrue($oProperties->propertyExists('align-content')); $oProperties->mergeStandards(['align-content' => false]); @@ -83,7 +86,7 @@ public function testMergeStandardsShouldDisableAContructor() public function testMergeStandardsShouldAddAContructor() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertFalse($oProperties->propertyExists('new-content')); $oProperties->mergeStandards(['new-content' => true]); @@ -92,7 +95,7 @@ public function testMergeStandardsShouldAddAContructor() public function testMergeNonStandardsShouldDisableAContructor() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertTrue($oProperties->propertyExists('-moz-font-smoothing')); $oProperties->mergeNonStandards(['font-smoothing' => false]); @@ -101,7 +104,7 @@ public function testMergeNonStandardsShouldDisableAContructor() public function testMergeNonStandardsShouldAddAContructor() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertFalse($oProperties->propertyExists('-moz-new-content')); $oProperties->mergeNonStandards(['new-content' => true]); @@ -110,7 +113,7 @@ public function testMergeNonStandardsShouldAddAContructor() public function testSetOptionsAllowedIndentationChars() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertFalse($oProperties->isAllowedIndentationChar("\t")); $oProperties->setOptions([ @@ -121,7 +124,7 @@ public function testSetOptionsAllowedIndentationChars() public function testSetOptionsConstructors() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertFalse($oProperties->propertyExists('-new-font-smoothing')); $oProperties->setOptions([ @@ -132,7 +135,7 @@ public function testSetOptionsConstructors() public function testSetOptionsStandards() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertFalse($oProperties->propertyExists('new-content')); $oProperties->setOptions([ @@ -143,7 +146,7 @@ public function testSetOptionsStandards() public function testSetOptionsNonStandards() { - $oProperties = new \CssLint\Properties(); + $oProperties = new Properties(); $this->assertFalse($oProperties->propertyExists('-moz-new-content')); $oProperties->setOptions([