PHP Master: Write Cutting-edge Code php unit db testing

PHP Master: Write Cutting-edge Code php unit db testing
Database Testing - Assertions p.269

In code below one table from dataset… the other table from where came to get compared together?

class My_DaoTest extends PHPUnit_Extensions_Database_TestCase
{
  private $dao;
  // getConnection() and getDataSet() implementations from earlier➥
       go here
  protected function setUp()
  {
    $this->dao = new My_Dao;
    // any other required setup – connecting to the database, etc.
  }
  public function testDoStuff()
  {
    $this->dao->doStuff();
    // asserting table row count
    $expected_row_count = 2;
    $actual_row_count = $this->getConnection()->getRowCount
➥
      ('table_name');
    $this->assertEquals($expected_row_count, $actual_row_count);
    // asserting table / query result set equality
    $expected_table = $this->createMySQLXMLDataSet
➥
      ('/path/to/expected_table.xml')
      ->getTable('table_name');
    $actual_table = $this->getConnection()->createQueryTable➥
      ('table_name',
      'SELECT * FROM table_name WHERE ...');
    $this->assertTablesEqual($expected_table, $actual_table);
  }
}

Hi,

The test table to compare against is created on this line:

$expected_table = $this->createMySQLXMLDataSet('/path/to/expected_table.xml') ->getTable('table_name');

The createMySQLXMLDataSet method is part of the PHPUnit_Extensions_Database_TestCase class that your test class extends from.

what is simply the resource of these tables - come from the same resource [so equal] but differ way get?

The data for $expected_table is coming from an XML file which describes how the results should look. The data for $actual_table is being queried from a real database.

But
$expected_table is coming from an XML file which describes how the results should look.
has lesser rows since is for sample hasn’t it?
these should NOT be EQUAL, SHOULD BE?

Yes I expect that the XML file is only a subset of the full table, but the query that is getting the data for $actual_table is using a WHERE clause so probably just a small amount of data from the DB is being selected, which obviously should match what’s in the XML file for the test to pass.

so you must put a where select (statement) rows with knowledge… of xml data set…