GenericTest.php 3.5 KB

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