Avoid bad method call to patchPatch() in DbTestRecorder
[lhc/web/wiklou.git] / tests / parser / DbTestRecorder.php
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.
7 *
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.
12 *
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
17 *
18 * @file
19 * @ingroup Testing
20 */
21
22 use Wikimedia\Rdbms\IMaintainableDatabase;
23
24 class DbTestRecorder extends TestRecorder {
25 public $version;
26 /** @var Database */
27 private $db;
28
29 public function __construct( IMaintainableDatabase $db ) {
30 $this->db = $db;
31 }
32
33 /**
34 * Set up result recording; insert a record for the run with the date
35 * and all that fun stuff
36 */
37 function start() {
38 $this->db->begin( __METHOD__ );
39
40 if ( !$this->db->tableExists( 'testrun' )
41 || !$this->db->tableExists( 'testitem' )
42 ) {
43 print "WARNING> `testrun` table not found in database. Trying to create table.\n";
44 $updater = DatabaseUpdater::newForDB( $this->db );
45 $this->db->sourceFile( $updater->patchPath( $this->db, 'patch-testrun.sql' ) );
46 echo "OK, resuming.\n";
47 }
48
49 $this->db->insert( 'testrun',
50 [
51 'tr_date' => $this->db->timestamp(),
52 'tr_mw_version' => $this->version,
53 'tr_php_version' => PHP_VERSION,
54 'tr_db_version' => $this->db->getServerVersion(),
55 'tr_uname' => php_uname()
56 ],
57 __METHOD__ );
58 if ( $this->db->getType() === 'postgres' ) {
59 $this->curRun = $this->db->currentSequenceValue( 'testrun_id_seq' );
60 } else {
61 $this->curRun = $this->db->insertId();
62 }
63 }
64
65 /**
66 * Record an individual test item's success or failure to the db
67 *
68 * @param array $test
69 * @param ParserTestResult $result
70 */
71 function record( $test, ParserTestResult $result ) {
72 $this->db->insert( 'testitem',
73 [
74 'ti_run' => $this->curRun,
75 'ti_name' => $test['desc'],
76 'ti_success' => $result->isSuccess() ? 1 : 0,
77 ],
78 __METHOD__ );
79 }
80
81 /**
82 * Commit transaction and clean up for result recording
83 */
84 function end() {
85 $this->db->commit( __METHOD__ );
86 }
87 }