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
22 use MediaWiki\Installer\DatabaseUpdater
;
23 use Wikimedia\Rdbms\IMaintainableDatabase
;
25 class DbTestRecorder
extends TestRecorder
{
28 /** @var IMaintainableDatabase */
33 public function __construct( $db ) {
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__
)
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' )
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()
62 ->caller( __METHOD__
)
64 $this->curRun
= $this->db
->insertId();
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' )
77 'ti_run' => $this->curRun
,
79 'ti_success' => $result->isSuccess() ?
1 : 0,
81 ->caller( __METHOD__
)
86 * Commit transaction and clean up for result recording
88 public function end() {
89 $this->db
->commit( __METHOD__
);