SimpleTesterTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/Db/SimpleTester.php";
  23. require_once "Zend/Test/PHPUnit/Db/Connection.php";
  24. require_once "Zend/Test/DbAdapter.php";
  25. require_once "PHPUnit/Extensions/Database/DataSet/IDataSet.php";
  26. require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
  27. require_once "Zend/Test/PHPUnit/Db/Exception.php";
  28. /**
  29. * @category Zend
  30. * @package Zend_Test
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2014 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. class Zend_Test_PHPUnit_Db_SimpleTesterTest extends PHPUnit_Framework_TestCase
  37. {
  38. public function testGetConnection()
  39. {
  40. $testAdapter = $this->getMock('Zend_Test_DbAdapter');
  41. $testAdapter->expects($this->any())
  42. ->method('delete')
  43. ->will($this->throwException(new Exception));
  44. $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
  45. $databaseTester = new Zend_Test_PHPUnit_Db_SimpleTester($connection);
  46. $this->assertSame($connection, $databaseTester->getConnection());
  47. }
  48. public function testSetupDatabase()
  49. {
  50. $testAdapter = $this->getMock('Zend_Test_DbAdapter');
  51. $testAdapter->expects($this->any())
  52. ->method('delete')
  53. ->will($this->throwException(new Exception));
  54. $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
  55. $databaseTester = new Zend_Test_PHPUnit_Db_SimpleTester($connection);
  56. $dataSet = $this->getMock('PHPUnit_Extensions_Database_DataSet_IDataSet');
  57. $dataSet->expects($this->any())
  58. ->method('getIterator')
  59. ->will($this->returnValue($this->getMock('Iterator')));
  60. $dataSet->expects($this->any())
  61. ->method('getReverseIterator')
  62. ->will($this->returnValue($this->getMock('Iterator')));
  63. $databaseTester->setUpDatabase($dataSet);
  64. }
  65. public function testInvalidConnectionGivenThrowsException()
  66. {
  67. $this->setExpectedException("Zend_Test_PHPUnit_Db_Exception");
  68. $connection = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection');
  69. $databaseTester = new Zend_Test_PHPUnit_Db_SimpleTester($connection);
  70. }
  71. }