test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / db / TestORMRowTest.php
blobf65642b800fc18df267338e83168634e91261e7a
1 <?php
3 /**
4 * Tests for the TestORMRow class.
5 * TestORMRow is a dummy class to be able to test the abstract ORMRow class.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
22 * @file
23 * @since 1.20
25 * @ingroup Test
27 * @group ORM
29 * The database group has as a side effect that temporal database tables are created. This makes
30 * it possible to test without poisoning a production database.
31 * @group Database
33 * Some of the tests takes more time, and needs therefor longer time before they can be aborted
34 * as non-functional. The reason why tests are aborted is assumed to be set up of temporal databases
35 * that hold the first tests in a pending state awaiting access to the database.
36 * @group medium
38 * @licence GNU GPL v2+
39 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
41 require_once __DIR__ . "/ORMRowTest.php";
43 class TestORMRowTest extends ORMRowTest {
45 /**
46 * @since 1.20
47 * @return string
49 protected function getRowClass() {
50 return 'TestORMRow';
53 /**
54 * @since 1.20
55 * @return IORMTable
57 protected function getTableInstance() {
58 return TestORMTable::singleton();
61 protected function setUp() {
62 parent::setUp();
64 $dbw = wfGetDB( DB_MASTER );
66 $isSqlite = $GLOBALS['wgDBtype'] === 'sqlite';
67 $isPostgres = $GLOBALS['wgDBtype'] === 'postgres';
69 $idField = $isSqlite ? 'INTEGER' : 'INT unsigned';
70 $primaryKey = $isSqlite ? 'PRIMARY KEY AUTOINCREMENT' : 'auto_increment PRIMARY KEY';
72 if ( $isPostgres ) {
73 $dbw->query(
74 'CREATE TABLE IF NOT EXISTS ' . $dbw->tableName( 'orm_test' ) . "(
75 test_id serial PRIMARY KEY,
76 test_name TEXT NOT NULL DEFAULT '',
77 test_age INTEGER NOT NULL DEFAULT 0,
78 test_height REAL NOT NULL DEFAULT 0,
79 test_awesome INTEGER NOT NULL DEFAULT 0,
80 test_stuff BYTEA,
81 test_moarstuff BYTEA,
82 test_time TIMESTAMPTZ
83 );",
84 __METHOD__
86 } else {
87 $dbw->query(
88 'CREATE TABLE IF NOT EXISTS ' . $dbw->tableName( 'orm_test' ) . '(
89 test_id ' . $idField . ' NOT NULL ' . $primaryKey . ',
90 test_name VARCHAR(255) NOT NULL,
91 test_age TINYINT unsigned NOT NULL,
92 test_height FLOAT NOT NULL,
93 test_awesome TINYINT unsigned NOT NULL,
94 test_stuff BLOB NOT NULL,
95 test_moarstuff BLOB NOT NULL,
96 test_time varbinary(14) NOT NULL
97 );',
98 __METHOD__
103 protected function tearDown() {
104 $dbw = wfGetDB( DB_MASTER );
105 $dbw->dropTable( 'orm_test', __METHOD__ );
107 parent::tearDown();
110 public function constructorTestProvider() {
111 $dbw = wfGetDB( DB_MASTER );
112 return array(
113 array(
114 array(
115 'name' => 'Foobar',
116 'time' => $dbw->timestamp( '20120101020202' ),
117 'age' => 42,
118 'height' => 9000.1,
119 'awesome' => true,
120 'stuff' => array( 13, 11, 7, 5, 3, 2 ),
121 'moarstuff' => (object)array( 'foo' => 'bar', 'bar' => array( 4, 2 ), 'baz' => true )
123 true
129 * @since 1.21
130 * @return array
132 protected function getMockValues() {
133 return array(
134 'id' => 1,
135 'str' => 'foobar4645645',
136 'int' => 42,
137 'float' => 4.2,
138 'bool' => '',
139 'array' => array( 42, 'foobar' ),
140 'blob' => new stdClass()
145 class TestORMRow extends ORMRow {
148 class TestORMTable extends ORMTable {
151 * Returns the name of the database table objects of this type are stored in.
153 * @since 1.20
155 * @return string
157 public function getName() {
158 return 'orm_test';
162 * Returns the name of a IORMRow implementing class that
163 * represents single rows in this table.
165 * @since 1.20
167 * @return string
169 public function getRowClass() {
170 return 'TestORMRow';
174 * Returns an array with the fields and their types this object contains.
175 * This corresponds directly to the fields in the database, without prefix.
177 * field name => type
179 * Allowed types:
180 * * id
181 * * str
182 * * int
183 * * float
184 * * bool
185 * * array
186 * * blob
188 * @since 1.20
190 * @return array
192 public function getFields() {
193 return array(
194 'id' => 'id',
195 'name' => 'str',
196 'age' => 'int',
197 'height' => 'float',
198 'awesome' => 'bool',
199 'stuff' => 'array',
200 'moarstuff' => 'blob',
201 'time' => 'str', // TS_MW
206 * Gets the db field prefix.
208 * @since 1.20
210 * @return string
212 protected function getFieldPrefix() {
213 return 'test_';