Failed to connect to database by setUp () error
class ChanTest extends PHPUnit_Framework_TestCase
{
protected $db;
protected function setUp()
{
$this->db = new Core\Database('unitest');
}
public function testData($a, $b, $c)
{
$this->assertEquals($a + $b, $c);
}
public function testProvider()
{
$this->db->query('SELECT `a`, `b`, `c` FROM `units`');
return $this->db->rows();
}
}
Connecting to a database by itself works
class ChanTest extends PHPUnit_Framework_TestCase
{
protected $db;
protected function setUp()
{
$this->db = new Core\Database('unitest');
}
public function testData($a, $b, $c)
{
$this->db->query('SELECT `a`, `b`, `c` FROM `units`');
foreach ($this->db->rows() as $item) {
$this->assertEquals($item['a'] + $item['b'], $item['c']);
}
}
}
If I connect the dataProvider database via setUp function, this is the answer Fatal error: Call to a member function query(), but if the connection to the database itself works, can I dataProviderget the parameter setUp function?
source
share