CollectionTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. public $fixtures = [
  28. 'core.user'
  29. ];
  30. /**
  31. * Setup function
  32. *
  33. * @return void
  34. */
  35. public function setUp() {
  36. parent::setUp();
  37. $this->connection = ConnectionManager::get('test');
  38. Cache::clear(false, '_cake_model_');
  39. Cache::enable();
  40. }
  41. /**
  42. * Teardown function
  43. *
  44. * @return void
  45. */
  46. public function tearDown() {
  47. parent::tearDown();
  48. unset($this->connection);
  49. }
  50. /**
  51. * Test that describing non-existent tables fails.
  52. *
  53. * Tests for positive describe() calls are in each platformSchema
  54. * test case.
  55. *
  56. * @expectedException \Cake\Database\Exception
  57. * @return void
  58. */
  59. public function testDescribeIncorrectTable() {
  60. $schema = new Collection($this->connection);
  61. $this->assertNull($schema->describe('derp'));
  62. }
  63. /**
  64. * Tests that schema metadata is cached
  65. *
  66. * @return void
  67. */
  68. public function testDescribeCache() {
  69. $schema = $this->connection->schemaCollection();
  70. $table = $this->connection->schemaCollection()->describe('users');
  71. Cache::delete('test_users', '_cake_model_');
  72. $schema->cacheMetadata(true);
  73. $result = $schema->describe('users');
  74. $this->assertEquals($table, $result);
  75. $result = Cache::read('test_users', '_cake_model_');
  76. $this->assertEquals($table, $result);
  77. }
  78. }