Skip to content

Commit 4774013

Browse files
authored
Merge pull request #2856 from nextcloud/carl/fix-test
fix(tests): Fix migration tests
2 parents bbbbb87 + c703a0b commit 4774013

11 files changed

Lines changed: 126 additions & 49 deletions

lib/Data.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace OCA\Activity;
1111

12-
use Doctrine\DBAL\Platforms\MySQLPlatform;
1312
use OCA\Activity\Filter\AllFilter;
1413
use OCP\Activity\Exceptions\FilterNotFoundException;
1514
use OCP\Activity\IEvent;
@@ -526,8 +525,7 @@ public function expire($expireDays = 365) {
526525
* @psalm-param list<array{0: string, 1: mixed, 2?: string}> $conditions
527526
*/
528527
public function deleteActivities(array $conditions): void {
529-
$platform = $this->connection->getDatabasePlatform();
530-
if ($platform instanceof MySQLPlatform) {
528+
if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL) {
531529
$this->logger->debug('Choosing chunked activity delete for MySQL/MariaDB', ['app' => 'activity']);
532530
$this->deleteActivitiesForMySQL($conditions);
533531
return;

lib/Migration/Version2006Date20170808154933.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace OCA\Activity\Migration;
99

10-
use Doctrine\DBAL\Types\Types;
1110
use OCP\DB\ISchemaWrapper;
11+
use OCP\DB\Types;
1212
use OCP\Migration\IOutput;
1313
use OCP\Migration\SimpleMigrationStep;
1414

@@ -32,55 +32,55 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
3232
'notnull' => true,
3333
'length' => 20,
3434
]);
35-
$table->addColumn('timestamp', 'integer', [
35+
$table->addColumn('timestamp', Types::INTEGER, [
3636
'notnull' => true,
3737
'length' => 4,
3838
'default' => 0,
3939
]);
40-
$table->addColumn('priority', 'integer', [
40+
$table->addColumn('priority', Types::INTEGER, [
4141
'notnull' => true,
4242
'length' => 4,
4343
'default' => 0,
4444
]);
45-
$table->addColumn('type', 'string', [
45+
$table->addColumn('type', Types::STRING, [
4646
'notnull' => false,
4747
'length' => 255,
4848
]);
49-
$table->addColumn('user', 'string', [
49+
$table->addColumn('user', Types::STRING, [
5050
'notnull' => false,
5151
'length' => 64,
5252
]);
53-
$table->addColumn('affecteduser', 'string', [
53+
$table->addColumn('affecteduser', Types::STRING, [
5454
'notnull' => true,
5555
'length' => 64,
5656
]);
57-
$table->addColumn('app', 'string', [
57+
$table->addColumn('app', Types::STRING, [
5858
'notnull' => true,
5959
'length' => 32,
6060
]);
61-
$table->addColumn('subject', 'string', [
61+
$table->addColumn('subject', Types::STRING, [
6262
'notnull' => true,
6363
'length' => 255,
6464
]);
65-
$table->addColumn('subjectparams', 'text', [
65+
$table->addColumn('subjectparams', Types::TEXT, [
6666
'notnull' => true,
6767
]);
68-
$table->addColumn('message', 'string', [
68+
$table->addColumn('message', Types::STRING, [
6969
'notnull' => false,
7070
'length' => 255,
7171
]);
72-
$table->addColumn('messageparams', 'text', [
72+
$table->addColumn('messageparams', Types::TEXT, [
7373
'notnull' => false,
7474
]);
75-
$table->addColumn('file', 'string', [
75+
$table->addColumn('file', Types::STRING, [
7676
'notnull' => false,
7777
'length' => 4000,
7878
]);
79-
$table->addColumn('link', 'string', [
79+
$table->addColumn('link', Types::STRING, [
8080
'notnull' => false,
8181
'length' => 4000,
8282
]);
83-
$table->addColumn('object_type', 'string', [
83+
$table->addColumn('object_type', Types::STRING, [
8484
'notnull' => false,
8585
'length' => 255,
8686
]);
@@ -105,33 +105,33 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
105105
'notnull' => true,
106106
'length' => 20,
107107
]);
108-
$table->addColumn('amq_timestamp', 'integer', [
108+
$table->addColumn('amq_timestamp', Types::INTEGER, [
109109
'notnull' => true,
110110
'length' => 4,
111111
'default' => 0,
112112
]);
113-
$table->addColumn('amq_latest_send', 'integer', [
113+
$table->addColumn('amq_latest_send', Types::INTEGER, [
114114
'notnull' => true,
115115
'length' => 4,
116116
'default' => 0,
117117
]);
118-
$table->addColumn('amq_type', 'string', [
118+
$table->addColumn('amq_type', Types::STRING, [
119119
'notnull' => true,
120120
'length' => 255,
121121
]);
122-
$table->addColumn('amq_affecteduser', 'string', [
122+
$table->addColumn('amq_affecteduser', Types::STRING, [
123123
'notnull' => true,
124124
'length' => 64,
125125
]);
126-
$table->addColumn('amq_appid', 'string', [
126+
$table->addColumn('amq_appid', Types::STRING, [
127127
'notnull' => true,
128128
'length' => 255,
129129
]);
130-
$table->addColumn('amq_subject', 'string', [
130+
$table->addColumn('amq_subject', Types::STRING, [
131131
'notnull' => true,
132132
'length' => 255,
133133
]);
134-
$table->addColumn('amq_subjectparams', 'text', [
134+
$table->addColumn('amq_subjectparams', Types::TEXT, [
135135
'notnull' => true,
136136
]);
137137
$table->setPrimaryKey(['mail_id']);

lib/Migration/Version2006Date20170808155040.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Version2006Date20170808155040 extends SimpleMigrationStep {
1717
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
1818
* @param array $options
1919
* @return null|ISchemaWrapper
20-
* @throws \Doctrine\DBAL\Schema\SchemaException
20+
* @throws \OCP\DB\Schema\SchemaException
2121
* @since 13.0.0
2222
*/
2323
#[\Override]

lib/Migration/Version2007Date20181107114613.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
namespace OCA\Activity\Migration;
1010

1111
use Closure;
12-
use Doctrine\DBAL\Types\Types;
1312
use OCP\DB\ISchemaWrapper;
13+
use OCP\DB\Types;
1414
use OCP\Migration\IOutput;
1515
use OCP\Migration\SimpleMigrationStep;
1616

lib/Migration/Version2008Date20181011095117.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
namespace OCA\Activity\Migration;
1010

1111
use Closure;
12-
use Doctrine\DBAL\Schema\SchemaException;
13-
use Doctrine\DBAL\Types\Types;
1412
use OCP\DB\ISchemaWrapper;
13+
use OCP\DB\Schema\SchemaException;
14+
use OCP\DB\Types;
1515
use OCP\Migration\IOutput;
1616
use OCP\Migration\SimpleMigrationStep;
1717

lib/Migration/Version2011Date20201006132544.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
namespace OCA\Activity\Migration;
1010

1111
use Closure;
12-
use Doctrine\DBAL\Types\Type;
1312
use OCP\DB\ISchemaWrapper;
13+
use OCP\DB\Types;
1414
use OCP\IDBConnection;
1515
use OCP\Migration\IOutput;
1616
use OCP\Migration\SimpleMigrationStep;
@@ -37,14 +37,14 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
3737
$table = $schema->getTable('activity_mq');
3838

3939
$column = $table->getColumn('amq_appid');
40-
$column->setType(Type::getType('string'));
40+
$column->setType(Types::STRING);
4141
$column->setNotnull(true);
4242
$column->setLength(32);
4343

4444
$column = $table->getColumn('amq_subjectparams');
4545
// Can't switch from Long to clob on Oracle, so we need an intermediate column
46-
if ($column->getType() !== Type::getType('text')) {
47-
$table->addColumn('amq_subjectparams2', 'text', [
46+
if ($column->getType()->getName() !== Types::TEXT) {
47+
$table->addColumn('amq_subjectparams2', Types::TEXT, [
4848
'notnull' => false,
4949
]);
5050
}

lib/Migration/Version2011Date20201006132545.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
namespace OCA\Activity\Migration;
1010

1111
use Closure;
12-
use Doctrine\DBAL\Types\Type;
1312
use OCP\DB\ISchemaWrapper;
13+
use OCP\DB\Types;
1414
use OCP\Migration\IOutput;
1515
use OCP\Migration\SimpleMigrationStep;
1616

@@ -28,7 +28,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
2828

2929
$table = $schema->getTable('activity_mq');
3030
$column = $table->getColumn('amq_subjectparams');
31-
if ($column->getType() !== Type::getType('text')) {
31+
if ($column->getType()->getName() !== Types::TEXT) {
3232
$table->dropColumn('amq_subjectparams');
3333
return $schema;
3434
}

lib/Migration/Version2011Date20201006132546.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Closure;
1212
use OCP\DB\ISchemaWrapper;
13+
use OCP\DB\Types;
1314
use OCP\IDBConnection;
1415
use OCP\Migration\IOutput;
1516
use OCP\Migration\SimpleMigrationStep;
@@ -35,7 +36,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
3536

3637
$table = $schema->getTable('activity_mq');
3738
if (!$table->hasColumn('amq_subjectparams')) {
38-
$table->addColumn('amq_subjectparams', 'text', [
39+
$table->addColumn('amq_subjectparams', Types::TEXT, [
3940
'notnull' => false,
4041
]);
4142
return $schema;

psalm.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@
4242
</UndefinedClass>
4343
<UndefinedDocblockClass>
4444
<errorLevel type="suppress">
45-
<referencedClass name="Doctrine\DBAL\Driver\Statement" />
46-
<referencedClass name="Doctrine\DBAL\Platforms\AbstractPlatform" />
47-
<referencedClass name="Doctrine\DBAL\Schema\Schema" />
48-
<referencedClass name="Doctrine\DBAL\Schema\SchemaException" />
49-
<referencedClass name="Doctrine\DBAL\Schema\Table" />
5045
<referencedClass name="OC\Files\View" />
5146
<referencedClass name="OC\TagManager" />
5247
<referencedClass name="OC\Hooks\Emitter" />

tests/Migration/Version8000Date20260603120000Test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
namespace OCA\Activity\Tests\Migration;
1010

11-
use Doctrine\DBAL\Schema\Table;
1211
use OCA\Activity\Migration\Version8000Date20260603120000;
1312
use OCA\Activity\Tests\TestCase;
1413
use OCP\DB\ISchemaWrapper;
14+
use OCP\DB\Schema\ITable;
1515
use OCP\Migration\IOutput;
1616
use PHPUnit\Framework\MockObject\MockObject;
1717

@@ -34,7 +34,7 @@ protected function setUp(): void {
3434
* migration adds the covering composite index and drops the now-redundant one.
3535
*/
3636
public function testAddsCompositeIndexAndDropsRedundantOne(): void {
37-
$table = $this->createMock(Table::class);
37+
$table = $this->createMock(ITable::class);
3838
$table->method('hasIndex')
3939
->willReturnMap([
4040
['amp_user_send', false],
@@ -58,7 +58,7 @@ public function testAddsCompositeIndexAndDropsRedundantOne(): void {
5858
* must be a no-op so re-runs / fresh installs are not touched.
5959
*/
6060
public function testIsIdempotentWhenAlreadyMigrated(): void {
61-
$table = $this->createMock(Table::class);
61+
$table = $this->createMock(ITable::class);
6262
$table->method('hasIndex')
6363
->willReturnMap([
6464
['amp_user_send', true],
@@ -91,7 +91,7 @@ public function testSkipsWhenTableIsMissing(): void {
9191
$this->assertNull($result);
9292
}
9393

94-
protected function getSchemaMock(Table&MockObject $table): ISchemaWrapper&MockObject {
94+
protected function getSchemaMock(ITable&MockObject $table): ISchemaWrapper&MockObject {
9595
$schema = $this->createMock(ISchemaWrapper::class);
9696
$schema->method('hasTable')
9797
->with('activity_mq')

0 commit comments

Comments
 (0)