AbstractTestCase.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Test
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once "Zend/Db/Table/Abstract.php";
  23. require_once "Zend/Db/Table.php";
  24. require_once "Zend/Test/PHPUnit/Db/DataSet/DbTableDataSet.php";
  25. require_once "PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php";
  26. require_once "Zend/Test/PHPUnit/Db/SimpleTester.php";
  27. require_once "Zend/Test/PHPUnit/Db/DataSet/DbRowset.php";
  28. /**
  29. * @category Zend
  30. * @package Zend_Test
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. * @group Zend_Test
  35. */
  36. abstract class Zend_Test_PHPUnit_Db_Integration_AbstractTestCase extends PHPUnit_Framework_TestCase
  37. {
  38. /**
  39. * @var Zend_Db_Adapter_Abstract
  40. */
  41. protected $dbAdapter;
  42. public function testZendDbTableDataSet()
  43. {
  44. $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
  45. $dataSet->addTable($this->createFooTable());
  46. $dataSet->addTable($this->createBarTable());
  47. $this->assertEquals(
  48. "foo", $dataSet->getTableMetaData('foo')->getTableName()
  49. );
  50. $this->assertEquals(
  51. "bar", $dataSet->getTableMetaData("bar")->getTableName()
  52. );
  53. $this->assertEquals(array("foo", "bar"), $dataSet->getTableNames());
  54. }
  55. public function testZendDbTableEqualsXmlDataSet()
  56. {
  57. $fooTable = $this->createFooTable();
  58. $fooTable->insert(array("id" => null, "foo" => "foo", "bar" => "bar", "baz" => "baz"));
  59. $fooTable->insert(array("id" => null, "foo" => "bar", "bar" => "bar", "baz" => "bar"));
  60. $fooTable->insert(array("id" => null, "foo" => "baz", "bar" => "baz", "baz" => "baz"));
  61. $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
  62. $dataSet->addTable($fooTable);
  63. $xmlDataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(
  64. dirname(__FILE__)."/_files/sqliteIntegrationFixture.xml"
  65. );
  66. $this->assertTrue($xmlDataSet->assertEquals($dataSet));
  67. }
  68. /**
  69. * @return Zend_Test_PHPUnit_Db_Connection
  70. */
  71. public function getConnection()
  72. {
  73. return new Zend_Test_PHPUnit_Db_Connection($this->dbAdapter, 'foo');
  74. }
  75. public function testSimpleTesterSetupAndRowsetEquals()
  76. {
  77. $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(
  78. dirname(__FILE__)."/_files/sqliteIntegrationFixture.xml"
  79. );
  80. $fooDataTable = $dataSet->getTable("foo");
  81. $tester = new Zend_Test_PHPUnit_Db_SimpleTester($this->getConnection());
  82. $tester->setUpDatabase($dataSet);
  83. $fooTable = $this->createFooTable();
  84. $rows = $fooTable->fetchAll();
  85. $this->assertEquals(3, count($rows));
  86. $rowsetTable = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($rows);
  87. $rowsetTable->assertEquals($fooDataTable);
  88. }
  89. /**
  90. * @return Zend_Test_PHPUnit_Db_TableFoo
  91. */
  92. public function createFooTable()
  93. {
  94. $table = new Zend_Test_PHPUnit_Db_TableFoo(array('db' => $this->dbAdapter));
  95. return $table;
  96. }
  97. /**
  98. * @return Zend_Test_PHPUnit_Db_TableBar
  99. */
  100. public function createBarTable()
  101. {
  102. $table = new Zend_Test_PHPUnit_Db_TableBar(array('db' => $this->dbAdapter));
  103. return $table;
  104. }
  105. }
  106. class Zend_Test_PHPUnit_Db_TableFoo extends Zend_Db_Table_Abstract
  107. {
  108. protected $_name = "foo";
  109. protected $_primary = "id";
  110. }
  111. class Zend_Test_PHPUnit_Db_TableBar extends Zend_Db_Table_Abstract
  112. {
  113. protected $_name = "bar";
  114. protected $_primary = "id";
  115. }