CollectionTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Database\Schema;
  16. use Cake\Cache\Cache;
  17. use Cake\Core\Configure;
  18. use Cake\Database\Connection;
  19. use Cake\Database\Schema\Collection;
  20. use Cake\Database\Schema\Table;
  21. use Cake\Datasource\ConnectionManager;
  22. use Cake\TestSuite\TestCase;
  23. /**
  24. * Test case for Collection
  25. */
  26. class CollectionTest extends TestCase
  27. {
  28. public $fixtures = [
  29. 'core.users'
  30. ];
  31. /**
  32. * Setup function
  33. *
  34. * @return void
  35. */
  36. public function setUp()
  37. {
  38. parent::setUp();
  39. $this->connection = ConnectionManager::get('test');
  40. Cache::clear(false, '_cake_model_');
  41. Cache::enable();
  42. }
  43. /**
  44. * Teardown function
  45. *
  46. * @return void
  47. */
  48. public function tearDown()
  49. {
  50. parent::tearDown();
  51. unset($this->connection);
  52. }
  53. /**
  54. * Test that describing non-existent tables fails.
  55. *
  56. * Tests for positive describe() calls are in each platformSchema
  57. * test case.
  58. *
  59. * @expectedException \Cake\Database\Exception
  60. * @return void
  61. */
  62. public function testDescribeIncorrectTable()
  63. {
  64. $schema = new Collection($this->connection);
  65. $this->assertNull($schema->describe('derp'));
  66. }
  67. /**
  68. * Tests that schema metadata is cached
  69. *
  70. * @return void
  71. */
  72. public function testDescribeCache()
  73. {
  74. $schema = $this->connection->schemaCollection();
  75. $table = $this->connection->schemaCollection()->describe('users');
  76. Cache::delete('test_users', '_cake_model_');
  77. $this->connection->cacheMetadata(true);
  78. $schema = $this->connection->schemaCollection();
  79. $result = $schema->describe('users');
  80. $this->assertEquals($table, $result);
  81. $result = Cache::read('test_users', '_cake_model_');
  82. $this->assertEquals($table, $result);
  83. }
  84. }