CollectionTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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\Schema\Collection;
  22. use Cake\Database\Schema\Table;
  23. use Cake\Datasource\ConnectionManager;
  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. $schema = $this->connection->schemaCollection();
  72. $table = $this->connection->schemaCollection()->describe('users');
  73. Cache::delete('test_users', '_cake_model_');
  74. $schema->cacheMetadata(true);
  75. $result = $schema->describe('users');
  76. $this->assertEquals($table, $result);
  77. $result = Cache::read('test_users', '_cake_model_');
  78. $this->assertEquals($table, $result);
  79. }
  80. }