TYPO3 CMS  TYPO3_8-7
ConnectionMigratorTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
30 
34 class ConnectionMigratorTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
35 {
39  protected $platform;
40 
44  protected $subject;
45 
49  protected $maxIdentifierLength = -1;
50 
54  protected function setUp()
55  {
56  parent::setUp();
57 
58  $platformMock = $this->prophesize(MySqlPlatform::class);
59  $platformMock->quoteIdentifier(Argument::any())->willReturnArgument(0);
60  $this->platform = $platformMock->reveal();
61 
62  $connectionMock = $this->prophesize(Connection::class);
63  $connectionMock->getDatabasePlatform()->willReturn($this->platform);
64  $connectionMock->quoteIdentifier(Argument::any())->willReturnArgument(0);
65 
66  $this->maxIdentifierLength = PlatformInformation::getMaxIdentifierLength($this->platform);
67 
68  $this->subject = $this->getAccessibleMock(ConnectionMigrator::class, null, [], '', false);
69  $this->subject->_set('connection', $connectionMock->reveal());
70  }
71 
76  {
77  $originalSchemaDiff = GeneralUtility::makeInstance(SchemaDiff::class, null, null, [$this->getTable()]);
78  $renamedSchemaDiff = $this->subject->_call('migrateUnprefixedRemovedTablesToRenames', $originalSchemaDiff);
79 
80  $this->assertStringStartsWith('zzz_deleted_', $renamedSchemaDiff->changedTables[0]->newName);
81  $this->assertEquals(
82  $this->maxIdentifierLength,
83  strlen($renamedSchemaDiff->changedTables[0]->newName)
84  );
85  }
86 
91  {
92  $table = $this->getTable();
93  $tableDiff = new TableDiff($table->getName());
94  $originalSchemaDiff = new SchemaDiff(null, [$tableDiff]);
95  $originalSchemaDiff->changedTables[0]->removedColumns[] = $this->getColumn();
96  $renamedSchemaDiff = $this->subject->_call('migrateUnprefixedRemovedFieldsToRenames', $originalSchemaDiff);
97 
98  $this->assertStringStartsWith(
99  'zzz_deleted_',
100  $renamedSchemaDiff->changedTables[0]->changedColumns[0]->column->getName()
101  );
102  $this->assertEquals(
103  $this->maxIdentifierLength,
104  strlen($renamedSchemaDiff->changedTables[0]->changedColumns[0]->column->getName())
105  );
106  }
107 
113  protected function getTable(): Table
114  {
115  $tableName = 'table_name_that_is_ridiculously_long_' . bin2hex(random_bytes(100));
117  Table::class,
118  $tableName
119  );
120 
121  return $table;
122  }
123 
130  protected function getColumn(): Column
131  {
132  $columnName = 'column_name_that_is_ridiculously_long_' . bin2hex(random_bytes(100));
134  Column::class,
135  $columnName,
136  Type::getType('string')
137  );
138 
139  return $column;
140  }
141 }
static static getMaxIdentifierLength(AbstractPlatform $platform)
static makeInstance($className,... $constructorArguments)