-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable PHPStan in tests #3203
Enable PHPStan in tests #3203
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carusogabriel as for the remaining
------ ----------------------------------------------------------------------
Line tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php
------ ----------------------------------------------------------------------
72 Call to an undefined method
Doctrine\DBAL\Driver\Connection::getAttribute().
------ ----------------------------------------------------------------------
You can add a type hint like @var \PDO $connection
.
@@ -138,9 +138,11 @@ public function testGetEventManager() | |||
|
|||
public function testConnectDispatchEvent() | |||
{ | |||
/** @var \PHPUnit_Framework_MockObject_MockObject $listenerMock */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a problem detecting the type here? The code looks straightforward. AFAIK, PHPUnit will use namespaced class names if future versions, so it makes sense to use \PHPUnit\Framework\...
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it still PHPUnit_...
https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/MockObject/MockObject.php#L21
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -26,6 +26,7 @@ protected function setUp() | |||
|
|||
public function testExecutionErrorsAreNotSuppressed() | |||
{ | |||
/** @var \Doctrine\DBAL\Statement $stmt */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks redundant. The @return
annotation on the method declares the type.
@@ -34,7 +34,7 @@ | |||
class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTestCase | |||
{ | |||
/** | |||
* @var \Doctrine\DBAL\Schema\AbstractSchemaManager | |||
* @var mixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it supposed to be anything else than a schema manager?
@@ -342,10 +342,12 @@ public function testListTableColumnsDispatchEvent() | |||
|
|||
$this->_sm->dropAndCreateTable($table); | |||
|
|||
/** @var \PHPUnit_Framework_MockObject_MockObject $listenerMock */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to remove, but, no success 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still doesn't look right. PhpStorm unambiguously detects the $listenerMockType
as PHPUnit\Framework\MockObject\MockObject
based on the @return
annotation of PHPUnit\Framework\MockObject\MockBuilder::getMock()
. So should do PHPStan. Instead of annotating every call like this, we need to find what the underlying problem is and fix it.
@@ -370,10 +372,12 @@ public function testListTableIndexesDispatchEvent() | |||
|
|||
$this->_sm->dropAndCreateTable($table); | |||
|
|||
/** @var \PHPUnit_Framework_MockObject_MockObject $listenerMock */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be needed.
@@ -44,6 +44,7 @@ public function testReturnsBindingType() | |||
|
|||
public function testConvertsDateTimeImmutableInstanceToDatabaseValue() | |||
{ | |||
/** @var \DateTimeImmutable|\Prophecy\Prophecy\ObjectProphecy $date */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does phpstan/phpstan-phpunit
handle prophecy mocks? Or there's a separate extension for them? In any event, it's better to have this type detection automated rather than manually entered every time.
@@ -16,7 +16,7 @@ | |||
private $platform; | |||
|
|||
/** | |||
* @var \Doctrine\DBAL\Types\DateIntervalType | |||
* @var \Doctrine\DBAL\Types\Type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert.
@@ -17,7 +17,7 @@ class DateTimeImmutableTypeTest extends \PHPUnit\Framework\TestCase | |||
private $platform; | |||
|
|||
/** | |||
* @var DateTimeImmutableType | |||
* @var Type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this parent/child issue be reported to upstream?
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
Line tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
26 Property Doctrine\Tests\DBAL\Types\DateTimeImmutableTypeTest::$type (Doctrine\DBAL\Types\DateTimeImmutableType) does not accept Doctrine\DBAL\Types\Type.
------ -----------------------------------------------------------------------------------------------------------------------------------------------------------
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Please try using new DateTimeImmutableType()
instead of the factory.
*/ | ||
private static $_sharedConn; | ||
|
||
/** | ||
* @var \Doctrine\DBAL\Connection | ||
* @var mixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It breaks a lot of places:
------ ------------------------------------------------------------------------------------
Line tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php
------ ------------------------------------------------------------------------------------
32 Call to an undefined method Doctrine\DBAL\Driver\Statement::getWrappedStatement().
------ ------------------------------------------------------------------------------------
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
29 Property Doctrine\Tests\DBAL\Functional\Driver\OCI8\OCI8ConnectionTest::$driverConnection (Doctrine\DBAL\Driver\OCI8\OCI8Connection) does not accept Doctrine\DBAL\Driver\Connection.
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
27 Property Doctrine\Tests\DBAL\Functional\Driver\PDOConnectionTest::$driverConnection (Doctrine\DBAL\Driver\PDOConnection) does not accept Doctrine\DBAL\Driver\Connection.
------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------
Line tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php
------ ------------------------------------------------------------------------------
41 Call to an undefined method Doctrine\DBAL\Driver\Connection::setAttribute().
75 Call to an undefined method Doctrine\DBAL\Driver\Connection::setAttribute().
99 Call to an undefined method Doctrine\DBAL\Driver\Connection::setAttribute().
123 Call to an undefined method Doctrine\DBAL\Driver\Connection::setAttribute().
------ ------------------------------------------------------------------------------
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those breakages look valid though, looks PDO related. Explicitly mixed
only disables some checks (so better to avoid mixed
).
use Doctrine\DBAL\Schema\AbstractSchemaManager; | ||
|
||
class DriverMock implements \Doctrine\DBAL\Driver | ||
{ | ||
/** | ||
* @var DatabasePlatformMock | ||
* @var AbstractPlatform|DatabasePlatformMock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DatabasePlatformMock
extends AbstractPlatform
. The former is enough.
|
@morozov Some comments that now are folded but I'd like your reply to continue to fix: |
@carusogabriel Hi, any progress? |
Closing as I won't be able to finish it. Anyone is encouraged to finish it 😊 |
Great job. |
Summary
Enable PHPStan on test at level 3.