QueryDataSetTest.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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-2015 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/DbAdapter.php";
  23. /**
  24. * @see Zend_Test_PHPUnit_Db_DataSet_DataSetTestCase
  25. */
  26. require_once "Zend/Test/PHPUnit/Db/DataSet/DataSetTestCase.php";
  27. /**
  28. * @see Zend_Test_PHPUnit_Db_DataSet_QueryTable
  29. */
  30. require_once "Zend/Test/PHPUnit/Db/DataSet/QueryDataSet.php";
  31. require_once 'Zend/Db/Select.php';
  32. /**
  33. * @category Zend
  34. * @package Zend_Test
  35. * @subpackage UnitTests
  36. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. * @group Zend_Test
  39. */
  40. class Zend_Test_PHPUnit_Db_DataSet_QueryDataSetTest extends Zend_Test_PHPUnit_Db_DataSet_DataSetTestCase
  41. {
  42. public function testCreateQueryDataSetWithoutZendDbAdapterThrowsException()
  43. {
  44. $connectionMock = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection');
  45. $this->setExpectedException('Zend_Test_PHPUnit_Db_Exception');
  46. $queryDataSet = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet($connectionMock);
  47. }
  48. public function testCreateQueryDataSetWithZendDbAdapter()
  49. {
  50. $this->decorateConnectionMockWithZendAdapter();
  51. $queryDataSet = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet($this->connectionMock);
  52. }
  53. public function testAddTableWithoutQueryParameterCreatesSelectWildcardAll()
  54. {
  55. $fixtureTableName = "foo";
  56. $adapterMock = $this->getMock('Zend_Test_DbAdapter');
  57. $selectMock = $this->getMock('Zend_Db_Select', array(), array($adapterMock));
  58. $adapterMock->expects($this->once())
  59. ->method('select')
  60. ->will($this->returnValue($selectMock));
  61. $this->decorateConnectionGetConnectionWith($adapterMock);
  62. $selectMock->expects($this->once())
  63. ->method('from')
  64. ->with($fixtureTableName, Zend_Db_Select::SQL_WILDCARD);
  65. $selectMock->expects($this->once())
  66. ->method('__toString')
  67. ->will($this->returnValue('SELECT * FOM foo'));
  68. $queryDataSet = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet($this->connectionMock);
  69. $queryDataSet->addTable('foo');
  70. }
  71. }