2
0

AbstractTestCase.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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-2010 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 dirname(__FILE__)."/../../../../../TestHelper.php";
  23. require_once "Zend/Db/Table/Abstract.php";
  24. require_once "Zend/Db/Table.php";
  25. require_once "Zend/Test/PHPUnit/Db/DataSet/DbTableDataSet.php";
  26. require_once "PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php";
  27. require_once "Zend/Test/PHPUnit/Db/SimpleTester.php";
  28. require_once "Zend/Test/PHPUnit/Db/DataSet/DbRowset.php";
  29. /**
  30. * @category Zend
  31. * @package Zend_Test
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. * @group Zend_Test
  36. */
  37. abstract class Zend_Test_PHPUnit_Db_Integration_AbstractTestCase extends PHPUnit_Framework_TestCase
  38. {
  39. /**
  40. * @var Zend_Db_Adapter_Abstract
  41. */
  42. protected $dbAdapter;
  43. public function testZendDbTableDataSet()
  44. {
  45. $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
  46. $dataSet->addTable($this->createFooTable());
  47. $dataSet->addTable($this->createBarTable());
  48. $this->assertEquals(
  49. "foo", $dataSet->getTableMetaData('foo')->getTableName()
  50. );
  51. $this->assertEquals(
  52. "bar", $dataSet->getTableMetaData("bar")->getTableName()
  53. );
  54. $this->assertEquals(array("foo", "bar"), $dataSet->getTableNames());
  55. }
  56. public function testZendDbTableEqualsXmlDataSet()
  57. {
  58. $fooTable = $this->createFooTable();
  59. $fooTable->insert(array("id" => null, "foo" => "foo", "bar" => "bar", "baz" => "baz"));
  60. $fooTable->insert(array("id" => null, "foo" => "bar", "bar" => "bar", "baz" => "bar"));
  61. $fooTable->insert(array("id" => null, "foo" => "baz", "bar" => "baz", "baz" => "baz"));
  62. $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
  63. $dataSet->addTable($fooTable);
  64. $xmlDataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(
  65. dirname(__FILE__)."/_files/sqliteIntegrationFixture.xml"
  66. );
  67. $this->assertTrue($xmlDataSet->assertEquals($dataSet));
  68. }
  69. /**
  70. * @return Zend_Test_PHPUnit_Db_Connection
  71. */
  72. public function getConnection()
  73. {
  74. return new Zend_Test_PHPUnit_Db_Connection($this->dbAdapter, 'foo');
  75. }
  76. public function testSimpleTesterSetupAndRowsetEquals()
  77. {
  78. $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(
  79. dirname(__FILE__)."/_files/sqliteIntegrationFixture.xml"
  80. );
  81. $fooDataTable = $dataSet->getTable("foo");
  82. $tester = new Zend_Test_PHPUnit_Db_SimpleTester($this->getConnection());
  83. $tester->setUpDatabase($dataSet);
  84. $fooTable = $this->createFooTable();
  85. $rows = $fooTable->fetchAll();
  86. $this->assertEquals(3, count($rows));
  87. $rowsetTable = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($rows);
  88. $rowsetTable->assertEquals($fooDataTable);
  89. }
  90. /**
  91. * @return Zend_Test_PHPUnit_Db_TableFoo
  92. */
  93. public function createFooTable()
  94. {
  95. $table = new Zend_Test_PHPUnit_Db_TableFoo(array('db' => $this->dbAdapter));
  96. return $table;
  97. }
  98. /**
  99. * @return Zend_Test_PHPUnit_Db_TableBar
  100. */
  101. public function createBarTable()
  102. {
  103. $table = new Zend_Test_PHPUnit_Db_TableBar(array('db' => $this->dbAdapter));
  104. return $table;
  105. }
  106. }
  107. class Zend_Test_PHPUnit_Db_TableFoo extends Zend_Db_Table_Abstract
  108. {
  109. protected $_name = "foo";
  110. protected $_primary = "id";
  111. }
  112. class Zend_Test_PHPUnit_Db_TableBar extends Zend_Db_Table_Abstract
  113. {
  114. protected $_name = "bar";
  115. protected $_primary = "id";
  116. }