engineName = $engineName; parent::__construct( $name, $data, $dataName ); } /** * Create a PHPUnit test suite to run the test against all engines * @param string $className Test class name * @return \PHPUnit\Framework\TestSuite */ public static function suite( $className ) { return self::makeSuite( $className ); } protected function tearDown() : void { if ( $this->luaDataProvider ) { $this->luaDataProvider->destroy(); $this->luaDataProvider = null; } if ( $this->engine ) { $this->engine->destroy(); $this->engine = null; } parent::tearDown(); } public function toString(): string { // When running tests written in Lua, return a nicer representation in // the failure message. if ( $this->luaTestName ) { return $this->engineName . ': ' . $this->luaTestName; } return $this->engineName . ': ' . parent::toString(); } /** * Modules that should exist * @return string[] Mapping module names to files */ protected function getTestModules() { return [ 'TestFramework' => __DIR__ . '/TestFramework.lua', ]; } public function provideLuaData() { if ( !$this->luaDataProvider ) { $class = static::$dataProviderClass; $this->luaDataProvider = new $class ( $this->getEngine(), static::$moduleName ); } return $this->luaDataProvider; } /** * @dataProvider provideLuaData * @param string $key * @param string $testName * @param mixed $expected */ public function testLua( $key, $testName, $expected ) { $this->luaTestName = static::$moduleName . "[$key]: $testName"; if ( isset( $this->skipTests[$testName] ) ) { $this->markTestSkipped( $this->skipTests[$testName] ); } else { try { $actual = $this->provideLuaData()->run( $key ); } catch ( Scribunto_LuaError $ex ) { if ( substr( $ex->getLuaMessage(), 0, 6 ) === 'SKIP: ' ) { $this->markTestSkipped( substr( $ex->getLuaMessage(), 6 ) ); } else { throw $ex; } } $this->assertSame( $expected, $actual ); } $this->luaTestName = null; } }