5 * Copyright (c) 2002-2009, Sebastian Bergmann <sb@sebastian-bergmann.de>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * * Neither the name of Sebastian Bergmann nor the names of his
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
39 * @author Mike Lively <m@digitalsandwich.com>
40 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
41 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
43 * @link http://www.phpunit.de/
44 * @since File available since Release 3.2.0
47 require_once 'PHPUnit/Framework/TestCase.php';
48 require_once 'PHPUnit/Extensions/Database/DataSet/QueryTable.php';
49 require_once 'PHPUnit/Extensions/Database/DataSet/DefaultTable.php';
50 require_once 'PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php';
55 * @author Mike Lively <m@digitalsandwich.com>
56 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
57 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
59 * @link http://www.phpunit.de/
60 * @since File available since Release 3.2.0
62 class Extensions_Database_DataSet_QueryTableTest extends PHPUnit_Framework_TestCase
65 * @var PHPUnit_Extensions_Database_DataSet_QueryTable
69 public function setUp()
81 $this->table = new PHPUnit_Extensions_Database_DataSet_QueryTable(
84 new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection(new PDO('sqlite::memory:'), 'test')
88 public static function providerTestGetValue()
91 array(0, 'col1', 'value1'),
92 array(0, 'col2', 'value2'),
93 array(0, 'col3', 'value3'),
94 array(1, 'col1', 'value4'),
95 array(1, 'col2', 'value5'),
96 array(1, 'col3', 'value6'),
100 public function testGetTableMetaData()
102 $metaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('col1', 'col2', 'col3'));
104 $this->assertEquals($metaData, $this->table->getTableMetaData());
107 public function testGetRowCount()
109 $this->assertEquals(2, $this->table->getRowCount());
113 * @dataProvider providerTestGetValue
115 public function testGetValue($row, $column, $value)
117 $this->assertEquals($value, $this->table->getValue($row, $column));
120 public function testGetRow()
122 $this->assertEquals(array('col1' => 'value1', 'col2' => 'value2', 'col3' => 'value3'), $this->table->getRow(0));
125 public function testAssertEquals()
127 $expected_table = new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('col1', 'col2', 'col3')));
128 $expected_table->addRow(array('col1' => 'value1', 'col2' => 'value2', 'col3' => 'value3'));
129 $expected_table->addRow(array('col1' => 'value4', 'col2' => 'value5', 'col3' => 'value6'));
130 $this->assertTrue($this->table->assertEquals($expected_table));
133 public function testAssertEqualsFails()
135 $this->setExpectedException('Exception', 'Expected row count of 2, has a row count of 3');
137 $expected_table = new PHPUnit_Extensions_Database_DataSet_DefaultTable(new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData('table1', array('col1', 'col2', 'col3')));
138 $expected_table->addRow(array('col1' => 'value1', 'col2' => 'value2', 'col3' => 'value3'));
139 $expected_table->addRow(array('col1' => 'value4', 'col2' => 'value5', 'col3' => 'value6'));
140 $expected_table->addRow(array('col1' => 'value7', 'col2' => 'value8', 'col3' => 'value9'));
141 $this->table->assertEquals($expected_table);