Skip to content

Commit

Permalink
Merge pull request #120 from PHPCSStandards/testutils/add-tests-for-j…
Browse files Browse the repository at this point in the history
…s-css-test-skipping-phpcs-4.x

TestUtils\UtilityMethodTestCase: add test for the skipJSCSSTestsOnPHPCS4() method
  • Loading branch information
jrfnl committed Mar 26, 2020
2 parents 0ba4de2 + 75fd255 commit 4838f12
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Tests/TestUtils/UtilityMethodTestCase/SkipCSJSTest.js
@@ -0,0 +1,3 @@
<?php

var i = 0;
75 changes: 75 additions & 0 deletions Tests/TestUtils/UtilityMethodTestCase/SkipCSJSTest.php
@@ -0,0 +1,75 @@
<?php
/**
* PHPCSUtils, utility functions and classes for PHP_CodeSniffer sniff developers.
*
* @package PHPCSUtils
* @copyright 2019-2020 PHPCSUtils Contributors
* @license https://opensource.org/licenses/LGPL-3.0 LGPL3
* @link https://github.com/PHPCSStandards/PHPCSUtils
*/

namespace PHPCSUtils\Tests\TestUtils\UtilityMethodTestCase;

use PHPCSUtils\TestUtils\UtilityMethodTestCase;

/**
* Tests for the \PHPCSUtils\TestUtils\UtilityMethodTestCase class.
*
* @covers \PHPCSUtils\TestUtils\UtilityMethodTestCase::skipJSCSSTestsOnPHPCS4
*
* @group testutils
*
* @since 1.0.0
*/
class SkipJSCSSTest extends UtilityMethodTestCase
{

/**
* The file extension of the test case file (without leading dot).
*
* @var string
*/
protected static $fileExtension = 'js';

/**
* Overload the test skipping method.
*
* @before
*
* @return void
*/
public function skipJSCSSTestsOnPHPCS4()
{
// Deliberately left empty.
}

/**
* Test that the skipJSCSSTestsOnPHPCS4() skips JS/CSS file tests on PHPCS 4.x.
*
* @doesNotPerformAssertions
*
* @return void
*/
public function testSkipJsCss()
{
if (\version_compare(static::$phpcsVersion, '3.99.99', '>') === true) {
$msg = 'JS and CSS support has been removed in PHPCS 4.';
$exception = 'PHPUnit\Framework\SkippedTestError';
if (\class_exists('PHPUnit_Framework_SkippedTestError')) {
// PHPUnit < 6.
$exception = 'PHPUnit_Framework_SkippedTestError';
}

if (\method_exists($this, 'expectException')) {
// PHPUnit 5+.
$this->expectException($exception);
$this->expectExceptionMessage($msg);
} else {
// PHPUnit 4.
$this->setExpectedException($exception, $msg);
}
}

parent::skipJSCSSTestsOnPHPCS4();
}
}

0 comments on commit 4838f12

Please sign in to comment.