Phuedx has uploaded a new change for review. https://gerrit.wikimedia.org/r/119055
Change subject: Add a LESS test suite ...................................................................... Add a LESS test suite Add the LessTestSuite and LessTestCase test suite and case classes, which represent a set of LESS files to be validated and their validation. Also, add the CoreLessTestSuite test suite, which covers all LESS files (excluding ResourceLoader test fixtures). Bug: 54665 Change-Id: Iedb8dc31e4817d8b4e40b655cf9b8fb092979e90 --- M tests/TestsAutoLoader.php A tests/phpunit/LessTestCase.php A tests/phpunit/LessTestSuite.php M tests/phpunit/suite.xml A tests/phpunit/suites/CoreLessTestSuite.php 5 files changed, 126 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/55/119055/1 diff --git a/tests/TestsAutoLoader.php b/tests/TestsAutoLoader.php index 7a048bf..2c2afc2 100644 --- a/tests/TestsAutoLoader.php +++ b/tests/TestsAutoLoader.php @@ -44,6 +44,8 @@ 'ResourceLoaderTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php", 'ResourceLoaderFileModuleTestModule' => "$testDir/phpunit/ResourceLoaderTestCase.php", 'TestUser' => "$testDir/phpunit/includes/TestUser.php", + 'LessTestSuite' => "$testDir/phpunit/LessTestSuite.php", + 'LessTestCase' => "$testDir/phpunit/LessTestCase.php", # tests/phpunit/includes 'BlockTest' => "$testDir/phpunit/includes/BlockTest.php", diff --git a/tests/phpunit/LessTestCase.php b/tests/phpunit/LessTestCase.php new file mode 100644 index 0000000..62cf07e --- /dev/null +++ b/tests/phpunit/LessTestCase.php @@ -0,0 +1,64 @@ +<?php + +/** + * Modelled on Sebastian Bergmann's PHPUnit_Extensions_PhptTestCase class. + * + * @see https://github.com/sebastianbergmann/phpunit/blob/master/src/Extensions/PhptTestCase.php + * @author Sam Smith <samsm...@wikimedia.org> + */ +class LessTestCase extends PHPUnit_Framework_TestCase { + + /** + * @var string $file + */ + private $file; + + /** + * @param string $file + * @throws PHPUnit_Framework_Exception When the file parameter isn't a + * string or readable file + */ + public function __construct( $file ) { + if ( ! is_string( $file ) || ! is_file( $file ) || ! is_readable( $file ) ) { + throw PHPUnit_Util_InvalidArgumentHelper::factory( 1, 'readable file' ); + } + + $this->file = $file; + } + + public function run( PHPUnit_Framework_TestResult $result = null ) { + if ( ! $result ) { + $result = new PHPUnit_Framework_TestResult(); + } + + // XXX (phuedx, 2014-03-14) #startTest and #endTest should time + // tests automatically. + $result->startTest( $this ); + PHP_Timer::start(); + + $compiler = ResourceLoader::getLessCompiler(); + $exception = null; + + try { + $compiler->compileFile( $this->file ); + } catch ( Exception $e ) { + $exception = $e; + } + + $time = PHP_Timer::stop(); + + if ( $exception ) { + $result->addError( $this, $exception, $time); + } + + $result->endTest( $this, $time ); + } + + public function getName( $withDataSet = true ) { + return $this->toString(); + } + + public function toString() { + return $this->file; + } +} diff --git a/tests/phpunit/LessTestSuite.php b/tests/phpunit/LessTestSuite.php new file mode 100644 index 0000000..3809a82 --- /dev/null +++ b/tests/phpunit/LessTestSuite.php @@ -0,0 +1,33 @@ +<?php + +/** + * Modelled on Sebastian Bergmann's PHPUnit_Extensions_PhptTestSuite class. + * + * @see https://github.com/sebastianbergmann/phpunit/blob/master/src/Extensions/PhptTestSuite.php + * @author Sam Smith <samsm...@wikimedia.org> + */ +class LessTestSuite extends PHPUnit_Framework_TestSuite { + /** + * @param string $paths + * @throws PHPUnit_Framework_Exception When any of the elements of the + * paths parameter isn't a string or a directory + */ + public function __construct( $paths ) { + $paths = (array)$paths; + + $this->setName( implode( ',', $paths ) ); + + foreach ( $paths as $path ) { + if ( ! is_string( $path ) || ! is_dir( $path ) ) { + throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'array of directories'); + } + } + + $fileIterator = new File_Iterator_Facade(); + $files = $fileIterator->getFilesAsArray( $paths, 'less' ); + + foreach ( $files as $file ) { + $this->addTest( new LessTestCase( $file ) ); + } + } +} diff --git a/tests/phpunit/suite.xml b/tests/phpunit/suite.xml index 3e76ff8..0089247 100644 --- a/tests/phpunit/suite.xml +++ b/tests/phpunit/suite.xml @@ -39,6 +39,9 @@ <file>suites/ExtensionsTestSuite.php</file> <file>suites/ExtensionsParserTestSuite.php</file> </testsuite> + <testsuite name="less"> + <file>suites/CoreLessTestSuite.php</file> + </testsuite> </testsuites> <groups> <exclude> diff --git a/tests/phpunit/suites/CoreLessTestSuite.php b/tests/phpunit/suites/CoreLessTestSuite.php new file mode 100644 index 0000000..6b291eb --- /dev/null +++ b/tests/phpunit/suites/CoreLessTestSuite.php @@ -0,0 +1,24 @@ +<?php + +/** + * @author Sam Smith <samsm...@wikimedia.org> + */ +class CoreLessTestSuite { + public static function suite() { + global $IP; + + $resourcesPath = "{$IP}/resources"; + + return new LessTestSuite( array( + "{$resourcesPath}/mediawiki", + "{$resourcesPath}/mediawiki.less", + "{$resourcesPath}/mediawiki.ui/components", + "{$resourcesPath}/mediawiki.ui/mixins", + "{$resourcesPath}/mediawiki.ui/settings", + "{$resourcesPath}/mediawiki.less", + "{$resourcesPath}/styleguide-template/public", + "{$IP}/skins/vector/components", + "{$IP}/skins/vector", + ) ); + } +} -- To view, visit https://gerrit.wikimedia.org/r/119055 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iedb8dc31e4817d8b4e40b655cf9b8fb092979e90 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Phuedx <g...@samsmith.io> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits