CollectionTest.php 2.4 KB

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