Skip to content

Commit

Permalink
Avoid mocking inexistent classes
Browse files Browse the repository at this point in the history
It confuses both Psalm and PHPStan, and involves complicated mocking.
  • Loading branch information
greg0ire committed May 27, 2020
1 parent b00a2e3 commit 9f9629c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 27 deletions.
9 changes: 6 additions & 3 deletions tests/Doctrine/Tests/DBAL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ public function testGetEventManager() : void

public function testConnectDispatchEvent() : void
{
$listenerMock = $this->getMockBuilder($this->getMockClass('ConnectDispatchEventListener'))
->addMethods(['postConnect'])
->getMock();
$listenerMock = $this->createMock(ConnectDispatchEventListener::class);
$listenerMock->expects($this->once())->method('postConnect');

$eventManager = new EventManager();
Expand Down Expand Up @@ -948,3 +946,8 @@ public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGen
$connection->executeCacheQuery($query, [], [], $queryCacheProfile);
}
}

interface ConnectDispatchEventListener
{
public function postConnect() : void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,7 @@ public function testListTableColumnsDispatchEvent() : void

$this->schemaManager->dropAndCreateTable($table);

$listenerMock = $this->getMockBuilder($this->getMockClass('ListTableColumnsDispatchEventListener'))
->addMethods(['onSchemaColumnDefinition'])
->getMock();

$listenerMock = $this->createMock(ListTableColumnsDispatchEventListener::class);
$listenerMock
->expects($this->exactly(7))
->method('onSchemaColumnDefinition');
Expand All @@ -397,9 +394,7 @@ public function testListTableIndexesDispatchEvent() : void

$this->schemaManager->dropAndCreateTable($table);

$listenerMock = $this->getMockBuilder($this->getMockClass('ListTableIndexesDispatchEventListener'))
->addMethods(['onSchemaIndexDefinition'])
->getMock();
$listenerMock = $this->createMock(ListTableIndexesDispatchEventListener::class);
$listenerMock
->expects($this->exactly(3))
->method('onSchemaIndexDefinition');
Expand Down Expand Up @@ -1653,3 +1648,13 @@ public function testSchemaDiffForeignKeys() : void
}
}
}

interface ListTableColumnsDispatchEventListener
{
public function onSchemaColumnDefinition() : void;
}

interface ListTableIndexesDispatchEventListener
{
public function onSchemaIndexDefinition() : void;
}
45 changes: 28 additions & 17 deletions tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,7 @@ public function testGetCustomColumnDeclarationSql() : void

public function testGetCreateTableSqlDispatchEvent() : void
{
$listenerMock = $this->getMockBuilder($this->getMockClass('GetCreateTableSqlDispatchEvenListener'))
->addMethods(['onSchemaCreateTable', 'onSchemaCreateTableColumn'])
->getMock();
$listenerMock = $this->createMock(GetCreateTableSqlDispatchEventListener::class);
$listenerMock
->expects($this->once())
->method('onSchemaCreateTable');
Expand All @@ -396,9 +394,7 @@ public function testGetCreateTableSqlDispatchEvent() : void

public function testGetDropTableSqlDispatchEvent() : void
{
$listenerMock = $this->getMockBuilder($this->getMockClass('GetDropTableSqlDispatchEventListener'))
->addMethods(['onSchemaDropTable'])
->getMock();
$listenerMock = $this->createMock(GetDropTableSqlDispatchEventListener::class);
$listenerMock
->expects($this->once())
->method('onSchemaDropTable');
Expand All @@ -413,17 +409,7 @@ public function testGetDropTableSqlDispatchEvent() : void

public function testGetAlterTableSqlDispatchEvent() : void
{
$events = [
'onSchemaAlterTable',
'onSchemaAlterTableAddColumn',
'onSchemaAlterTableRemoveColumn',
'onSchemaAlterTableChangeColumn',
'onSchemaAlterTableRenameColumn',
];

$listenerMock = $this->getMockBuilder($this->getMockClass('GetAlterTableSqlDispatchEvenListener'))
->addMethods($events)
->getMock();
$listenerMock = $this->createMock(GetAlterTableSqlDispatchEventListener::class);
$listenerMock
->expects($this->once())
->method('onSchemaAlterTable');
Expand Down Expand Up @@ -1532,3 +1518,28 @@ public function testZeroOffsetWithoutLimitIsIgnored() : void
);
}
}

interface GetCreateTableSqlDispatchEventListener
{
public function onSchemaCreateTable() : void;

public function onSchemaCreateTableColumn() : void;
}

interface GetAlterTableSqlDispatchEventListener
{
public function onSchemaAlterTable() : void;

public function onSchemaAlterTableAddColumn() : void;

public function onSchemaAlterTableRemoveColumn() : void;

public function onSchemaAlterTableChangeColumn() : void;

public function onSchemaAlterTableRenameColumn() : void;
}

interface GetDropTableSqlDispatchEventListener
{
public function onSchemaDropTable() : void;
}

0 comments on commit 9f9629c

Please sign in to comment.