QueryDataSetTest.php 2.9 KB

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