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