TestCaseTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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-2014 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/Test/PHPUnit/DatabaseTestCase.php";
  23. require_once "Zend/Test/PHPUnit/Db/Connection.php";
  24. require_once "Zend/Db/Adapter/Abstract.php";
  25. require_once "Zend/Db/Adapter/Pdo/Sqlite.php";
  26. require_once "Zend/Db/Table.php";
  27. require_once "Zend/Db/Table/Rowset.php";
  28. require_once "Zend/Test/DbAdapter.php";
  29. /**
  30. * @category Zend
  31. * @package Zend_Test
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2014 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. class Zend_Test_PHPUnit_Db_TestCaseTest extends Zend_Test_PHPUnit_DatabaseTestCase
  38. {
  39. /**
  40. * Contains a Database Connection
  41. *
  42. * @var PHPUnit_Extensions_Database_DB_IDatabaseConnection
  43. */
  44. protected $_connectionMock = null;
  45. /**
  46. * Returns the test database connection.
  47. *
  48. * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
  49. */
  50. protected function getConnection()
  51. {
  52. if($this->_connectionMock == null) {
  53. $this->_connectionMock = $this->getMock(
  54. 'Zend_Test_PHPUnit_Db_Connection', array(), array(new Zend_Test_DbAdapter(), "schema")
  55. );
  56. }
  57. return $this->_connectionMock;
  58. }
  59. /**
  60. * Returns the test dataset.
  61. *
  62. * @return PHPUnit_Extensions_Database_DataSet_IDataSet
  63. */
  64. protected function getDataSet()
  65. {
  66. return new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array());
  67. }
  68. public function testDatabaseTesterIsInitialized()
  69. {
  70. $this->assertTrue($this->databaseTester instanceof PHPUnit_Extensions_Database_ITester);
  71. }
  72. public function testDatabaseTesterNestsDefaultConnection()
  73. {
  74. $this->assertTrue($this->databaseTester->getConnection() instanceof PHPUnit_Extensions_Database_DB_IDatabaseConnection);
  75. }
  76. public function testCheckZendDbConnectionConvenienceMethodReturnType()
  77. {
  78. $mock = $this->getMock('Zend_Db_Adapter_Pdo_Sqlite', array('delete'), array(), "Zend_Db_Adapter_Mock", false);
  79. $this->assertTrue($this->createZendDbConnection($mock, "test") instanceof Zend_Test_PHPUnit_Db_Connection);
  80. }
  81. public function testCreateDbTableDataSetConvenienceMethodReturnType()
  82. {
  83. $tableMock = $this->getMock('Zend_Db_Table', array(), array(), "", false);
  84. $tableDataSet = $this->createDbTableDataSet(array($tableMock));
  85. $this->assertTrue($tableDataSet instanceof Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet);
  86. }
  87. public function testCreateDbTableConvenienceMethodReturnType()
  88. {
  89. $mock = $this->getMock('Zend_Db_Table', array(), array(), "", false);
  90. $table = $this->createDbTable($mock);
  91. $this->assertTrue($table instanceof Zend_Test_PHPUnit_Db_DataSet_DbTable);
  92. }
  93. public function testCreateDbRowsetConvenienceMethodReturnType()
  94. {
  95. $mock = $this->getMock('Zend_Db_Table_Rowset', array(), array(array()));
  96. $mock->expects($this->once())->method('toArray')->will($this->returnValue(array("foo" => 1, "bar" => 1)));
  97. $rowset = $this->createDbRowset($mock, "fooTable");
  98. $this->assertTrue($rowset instanceof Zend_Test_PHPUnit_Db_DataSet_DbRowset);
  99. }
  100. public function testGetAdapterConvenienceMethod()
  101. {
  102. $this->_connectionMock->expects($this->once())
  103. ->method('getConnection');
  104. $this->getAdapter();
  105. }
  106. }