CollectionTest.php 2.2 KB

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