CollectionTest.php 2.4 KB

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