1<?php
2
3/**
4 * Modelled on Sebastian Bergmann's PHPUnit_Extensions_PhptTestCase class.
5 *
6 * @see https://github.com/sebastianbergmann/phpunit/blob/master/src/Extensions/PhptTestCase.php
7 * @author Sam Smith <samsmith@wikimedia.org>
8 * @coversNothing
9 */
10class LessFileCompilationTest extends ResourceLoaderTestCase {
11
12	/**
13	 * @var string
14	 */
15	protected $file;
16
17	/**
18	 * @var ResourceLoaderModule The ResourceLoader module that contains
19	 *   the file
20	 */
21	protected $module;
22
23	/**
24	 * @param string $file
25	 * @param ResourceLoaderModule $module The ResourceLoader module that
26	 *   contains the file
27	 */
28	public function __construct( $file, ResourceLoaderModule $module ) {
29		parent::__construct( 'testLessFileCompilation' );
30
31		$this->file = $file;
32		$this->module = $module;
33	}
34
35	public function testLessFileCompilation() {
36		$thisString = $this->toString();
37		$this->assertIsReadable( $this->file, "$thisString must refer to a readable file" );
38
39		$rlContext = $this->getResourceLoaderContext();
40
41		// Bleh
42		$method = new ReflectionMethod( $this->module, 'compileLessString' );
43		$method->setAccessible( true );
44		$fileContents = file_get_contents( $this->file );
45		$this->assertNotNull( $method->invoke( $this->module, $fileContents, $this->file, $rlContext ) );
46	}
47
48	public function toString() : string {
49		$moduleName = $this->module->getName();
50
51		return "{$this->file} in the \"{$moduleName}\" module";
52	}
53}
54