I try to test a method that makes a SELECT query and return the rows found. I would like to check that this method doesn't return something else, given a dataset. I found so many docs about creating the dataset but nothing about using it in my case... Thanks for your help.
The method to test is:
class A
{
public static function myMethod()
{
$result = mysql_query("SELECT * FROM user");
[...]
return $rows;
}
}
The test class is:
class ATest extends PHPUnit_Extensions_Database_TestCase
{
protected $pdo;
public function __construct()
{
$this->pdo = new PDO('mysql:host=localhost;dbname=db_name',
'login', 'password');
}
public function getConnection()
{
return $this->createDefaultDBConnection($this->pdo, 'db_name');
}
public function getDataSet()
{
return $this->createFlatXMLDataSet('mydataset.xml');
}
public function testMyMethod()
{
$actual = A::myMethod();
$this->assertEquals(array([...]), $actual);
// For this test, I get a mySQL error "No database selected"
// in A::myMethod()!
}
}
Here is the content of mydataset.xml:
<?xml version="1.0" ?>
<dataset>
<user iduser="1" name="John" />
<user iduser="2" name="James" />
</dataset>