oldScriptName = $_SERVER['SCRIPT_NAME']; $_SERVER['SCRIPT_NAME'] = $_SERVER['SCRIPT_NAME'] . " console"; // update won't execute w/o this, see Common::isRunningConsoleCommand() ArchiveTableCreator::clear(); DbHelper::getTablesInstalled($forceReload = true); // force reload so internal cache in Mysql.php is refreshed Updates_2_10_0_b5::$archiveBlobTables = null; } public function tearDown(): void { $_SERVER['SCRIPT_NAME'] = $this->oldScriptName; parent::tearDown(); } public function test_UpdateCommand_SuccessfullyExecutesUpdate() { $result = $this->applicationTester->run(array( 'command' => 'core:update', '--yes' => true )); $this->assertEquals(0, $result, $this->getCommandDisplayOutputErrorMessage()); $this->assertDryRunExecuted($this->applicationTester->getDisplay()); // make sure update went through $this->assertEquals(Version::VERSION, Option::get('version_core')); } public function test_UpdateCommand_DoesntExecuteSql_WhenUserSaysNo() { /** @var QuestionHelper $dialog */ $dialog = $this->application->getHelperSet()->get('question'); $dialog->setInputStream($this->getInputStream("N\n")); $result = $this->applicationTester->run(array( 'command' => 'core:update' )); $this->assertEquals(0, $result, $this->getCommandDisplayOutputErrorMessage()); $this->assertDryRunExecuted($this->applicationTester->getDisplay()); // make sure update did not go through $this->assertEquals(self::VERSION_TO_UPDATE_FROM, Option::get('version_core')); } public function test_UpdateCommand_DoesNotExecuteUpdate_IfPiwikUpToDate() { Option::set('version_core', Version::VERSION); $result = $this->applicationTester->run(array( 'command' => 'core:update', '--yes' => true )); $this->assertEquals(0, $result, $this->getCommandDisplayOutputErrorMessage()); // check no update occurred self::assertStringContainsString("Everything is already up to date.", $this->applicationTester->getDisplay()); $this->assertEquals(Version::VERSION, Option::get('version_core')); } public function test_UpdateCommand_ReturnsCorrectExitCode_WhenErrorOccurs() { // create a blob table, then drop it manually so update 2.10.0-b10 will fail $tableName = ArchiveTableCreator::getBlobTable(Date::factory('2015-01-01')); Db::exec("DROP TABLE $tableName"); $result = $this->applicationTester->run(array( 'command' => 'core:update', '--yes' => true )); $this->assertEquals(1, $result, $this->getCommandDisplayOutputErrorMessage()); self::assertStringContainsString("Matomo could not be updated! See above for more information.", $this->applicationTester->getDisplay()); } private function assertDryRunExecuted($output) { self::assertStringContainsString("Note: this is a Dry Run", $output); self::assertStringContainsString(self::EXPECTED_SQL_FROM_2_10, $output); } }