gallery: Fix phan annotation for ImageGalleryBase::getImages
[mediawiki.git] / tests / parser / DbTestRecorder.php
blobcc9cfc76b1830c4455d3c96788d380b5452c0686
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
19 * @ingroup Testing
22 use MediaWiki\Installer\DatabaseUpdater;
23 use Wikimedia\Rdbms\IMaintainableDatabase;
25 class DbTestRecorder extends TestRecorder {
26 /** @var string */
27 public $version;
28 /** @var IMaintainableDatabase */
29 private $db;
30 /** @var int */
31 private $curRun;
33 public function __construct( $db ) {
34 $this->db = $db;
37 /**
38 * Set up result recording; insert a record for the run with the date
39 * and all that fun stuff
41 public function start() {
42 $this->db->begin( __METHOD__ );
44 if ( !$this->db->tableExists( 'testrun', __METHOD__ )
45 || !$this->db->tableExists( 'testitem', __METHOD__ )
46 ) {
47 print "WARNING> `testrun` table not found in database. Trying to create table.\n";
48 $updater = DatabaseUpdater::newForDB( $this->db );
49 $this->db->sourceFile( $updater->patchPath( $this->db, 'patch-testrun.sql' ) );
50 echo "OK, resuming.\n";
53 $this->db->newInsertQueryBuilder()
54 ->insertInto( 'testrun' )
55 ->row( [
56 'tr_date' => $this->db->timestamp(),
57 'tr_mw_version' => $this->version,
58 'tr_php_version' => PHP_VERSION,
59 'tr_db_version' => $this->db->getServerVersion(),
60 'tr_uname' => php_uname()
61 ] )
62 ->caller( __METHOD__ )
63 ->execute();
64 $this->curRun = $this->db->insertId();
67 /**
68 * Record an individual test item's success or failure to the db
70 * @param ParserTestResult $result
72 public function record( ParserTestResult $result ) {
73 $desc = $result->getDescription();
74 $this->db->newInsertQueryBuilder()
75 ->insertInto( 'testitem' )
76 ->row( [
77 'ti_run' => $this->curRun,
78 'ti_name' => $desc,
79 'ti_success' => $result->isSuccess() ? 1 : 0,
80 ] )
81 ->caller( __METHOD__ )
82 ->execute();
85 /**
86 * Commit transaction and clean up for result recording
88 public function end() {
89 $this->db->commit( __METHOD__ );