GenericTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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/Test/DbAdapter.php";
  24. require_once "Zend/Test/PHPUnit/Db/Metadata/Generic.php";
  25. /**
  26. * @category Zend
  27. * @package Zend_Test
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @group Zend_Test
  32. */
  33. class Zend_Test_PHPUnit_Db_Metadata_GenericTest extends PHPUnit_Framework_TestCase
  34. {
  35. private $adapterMock = null;
  36. private $metadata = null;
  37. public function setUp()
  38. {
  39. $this->adapterMock = $this->getMock('Zend_Test_DbAdapter');
  40. $this->metadata = new Zend_Test_PHPUnit_Db_Metadata_Generic($this->adapterMock, "schema");
  41. }
  42. public function testGetSchema()
  43. {
  44. $this->assertEquals("schema", $this->metadata->getSchema());
  45. }
  46. public function testGetColumnNames()
  47. {
  48. $fixtureTableName = "foo";
  49. $this->adapterMock->expects($this->once())
  50. ->method('describeTable')
  51. ->with($fixtureTableName)
  52. ->will($this->returnValue(array("foo" => 1, "bar" => 2)));
  53. $data = $this->metadata->getTableColumns($fixtureTableName);
  54. $this->assertEquals(array("foo", "bar"), $data);
  55. }
  56. public function testGetTableNames()
  57. {
  58. $this->adapterMock->expects($this->once())
  59. ->method('listTables')
  60. ->will($this->returnValue(array("foo")));
  61. $tables = $this->metadata->getTableNames();
  62. $this->assertEquals(array("foo"), $tables);
  63. }
  64. public function testGetTablePrimaryKey()
  65. {
  66. $fixtureTableName = "foo";
  67. $tableMeta = array(
  68. array('PRIMARY' => false, 'COLUMN_NAME' => 'foo'),
  69. array('PRIMARY' => true, 'COLUMN_NAME' => 'bar'),
  70. array('PRIMARY' => true, 'COLUMN_NAME' => 'baz'),
  71. );
  72. $this->adapterMock->expects($this->once())
  73. ->method('describeTable')
  74. ->with($fixtureTableName)
  75. ->will($this->returnValue($tableMeta));
  76. $primaryKey = $this->metadata->getTablePrimaryKeys($fixtureTableName);
  77. $this->assertEquals(array("bar", "baz"), $primaryKey);
  78. }
  79. public function testGetAllowCascading()
  80. {
  81. $this->assertFalse($this->metadata->allowsCascading());
  82. }
  83. public function testQuoteIdentifierIsDelegated()
  84. {
  85. $fixtureValue = "foo";
  86. $this->adapterMock->expects($this->once())
  87. ->method('quoteIdentifier')
  88. ->with($fixtureValue)
  89. ->will($this->returnValue($fixtureValue));
  90. $actualValue = $this->metadata->quoteSchemaObject($fixtureValue);
  91. $this->assertEquals($fixtureValue, $actualValue);
  92. }
  93. }