SchemaGeneratorTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @since 4.3.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\TestSuite\Schema;
  16. use Cake\Datasource\ConnectionManager;
  17. use Cake\TestSuite\Schema\SchemaGenerator;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * SchemaGenerator Test
  21. */
  22. class SchemaGeneratorTest extends TestCase
  23. {
  24. /**
  25. * test reload on a table subset.
  26. *
  27. * @return void
  28. */
  29. public function testReload()
  30. {
  31. $generator = new SchemaGenerator(__DIR__ . '/test_schema.php', 'test');
  32. // only drop tables we'll create again.
  33. $tables = ['schema_generator', 'schema_generator_comment'];
  34. $generator->reload($tables);
  35. $connection = ConnectionManager::get('test');
  36. $schema = $connection->getSchemaCollection();
  37. $tables = $schema->listTables();
  38. $this->assertContains('schema_generator', $tables);
  39. $this->assertContains('schema_generator_comment', $tables);
  40. foreach ($tables as $table) {
  41. $meta = $schema->describe($table);
  42. foreach ($meta->dropSql($connection) as $stmt) {
  43. $connection->execute($stmt);
  44. }
  45. }
  46. }
  47. }