CollectionTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\Schema\Collection;
  19. use Cake\Datasource\ConnectionManager;
  20. use Cake\TestSuite\TestCase;
  21. /**
  22. * Test case for Collection
  23. */
  24. class CollectionTest extends TestCase
  25. {
  26. public $fixtures = [
  27. 'core.users'
  28. ];
  29. /**
  30. * Setup function
  31. *
  32. * @return void
  33. */
  34. public function setUp()
  35. {
  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. {
  48. parent::tearDown();
  49. unset($this->connection);
  50. }
  51. /**
  52. * Test that describing non-existent tables fails.
  53. *
  54. * Tests for positive describe() calls are in each platformSchema
  55. * test case.
  56. *
  57. * @expectedException \Cake\Database\Exception
  58. * @return void
  59. */
  60. public function testDescribeIncorrectTable()
  61. {
  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. {
  72. $schema = $this->connection->schemaCollection();
  73. $table = $this->connection->schemaCollection()->describe('users');
  74. Cache::delete('test_users', '_cake_model_');
  75. $this->connection->cacheMetadata(true);
  76. $schema = $this->connection->schemaCollection();
  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. }