Skip to content
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

Psalm 6 #3977

Merged
merged 33 commits into from
May 27, 2020
Merged

Psalm 6 #3977

merged 33 commits into from
May 27, 2020

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Apr 25, 2020

Q A
Type improvement
BC Break no
Fixed issues n/a

Summary

Pushing although there are still 9 errors left, because they are either blocked, or I need help.
See:

I will of course squash many of the commits together in the end.

composer.json Outdated Show resolved Hide resolved
@greg0ire
Copy link
Member Author

In the remaining issues, there's one I don't know what to do about:

ERROR: NullArgument - tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php:30:68 - Argument 1 of Doctrine\DBAL\Driver\Connection::prepare cannot be null, null value provided to parameter with type string (see https://psalm.dev/057)
        $stmt = $this->connection->getWrappedConnection()->prepare(null);

class StatementTest extends DbalFunctionalTestCase
{
protected function setUp() : void
{
if (! extension_loaded('sqlsrv')) {
self::markTestSkipped('sqlsrv is not installed.');
}
parent::setUp();
if ($this->connection->getDriver() instanceof Driver) {
return;
}
self::markTestSkipped('sqlsrv only test');
}
public function testFailureToPrepareResultsInException() : void
{
// use the driver connection directly to avoid having exception wrapped
$stmt = $this->connection->getWrappedConnection()->prepare(null);
// it's impossible to prepare the statement without bound variables for SQL Server,
// so the preparation happens before the first execution when variables are already in place
$this->expectException(SQLSrvException::class);
$stmt->execute();
}
}

Please help.

@greg0ire greg0ire requested a review from morozov April 25, 2020 10:28
lib/Doctrine/DBAL/Connection.php Show resolved Hide resolved
lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php Outdated Show resolved Hide resolved
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php Outdated Show resolved Hide resolved
tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php Outdated Show resolved Hide resolved
tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php Outdated Show resolved Hide resolved
tests/Doctrine/Tests/DBAL/Types/TypeTest.php Outdated Show resolved Hide resolved
@greg0ire greg0ire force-pushed the psalm-6 branch 2 times, most recently from 69e87fc to f9b9f9b Compare April 29, 2020 07:29
@greg0ire
Copy link
Member Author

greg0ire commented Apr 29, 2020

@morozov the failure in Travis is caused by a warning about using an array of interfaces in calls to createMock. It is fixed on 2.11 because VersionAwarePlatformDriver extends Driver on that branch. Should I create a short-lived test interface that extends both and use it in the test? I would remove it when merging up. Tell me if you have another idea (maybe I should target 2.11, for instance).

@morozov
Copy link
Member

morozov commented Apr 29, 2020

Should I create a short-lived test interface that extends both and use it in the test?

That should be fine.

@greg0ire
Copy link
Member Author

greg0ire commented May 1, 2020

@morozov phpcs fails unless I use @psalm-param instead of @param when using array shapes. An alternative is to get slevomat/coding-standard to 6.3.3, which can be done by upgrading phpstan/phpdoc-parser, doctrine/coding-standard and squizlabs/php_codesniffer. Should I go ahead and create another PR that upgrades these packages? It might make other things easier. I'm asking because 2.10.x is for bugfixes, and this will probably imply changing code in src, although not in a significant way.

@morozov
Copy link
Member

morozov commented May 1, 2020

@greg0ire let's make the needed upgrades and see if we can simplify the annotations. The ones in the driver manager are really concerning.

@greg0ire
Copy link
Member Author

greg0ire commented May 3, 2020

Down to 4 errors.

@greg0ire
Copy link
Member Author

greg0ire commented May 3, 2020

Down to 2 errors, with which I need help please @morozov 🙏 see the todo list in the original post for details.

@morozov
Copy link
Member

morozov commented May 3, 2020

// use the driver connection directly to avoid having exception wrapped
$stmt = $this->connection->getWrappedConnection()->prepare(null);

IIRC, it just needs to be an invalid SQL that will cause failure being prepared. An empty string instead of null should work.

UPD: look at 8adf7f9#diff-c47062aaec500b4bf4ab79095668542cR30.

@greg0ire greg0ire force-pushed the psalm-6 branch 3 times, most recently from b131345 to b36d497 Compare May 11, 2020 16:40
@greg0ire greg0ire force-pushed the psalm-6 branch 2 times, most recently from c2bc7cc to 82c218d Compare May 24, 2020 09:03
greg0ire added 14 commits May 27, 2020 22:29
This is what is expected with FETCH_COLUMN
This is precisely what we are testing here.
This hack is temporary and should be removed on 3.0.x
This return type is conditional to $params['wrapperClass']. Luckily,
recent versions of Psalm allow documenting it properly.
See vimeo/psalm#3277

Note that phpstan is not able to understand this yet, but still attempts
to, hence the extra ignore rules.
It confuses both Psalm and PHPStan, and involves complicated mocking.
The php docs are not very clear about that one.
@greg0ire greg0ire merged commit 9f2e25c into doctrine:2.10.x May 27, 2020
@greg0ire greg0ire deleted the psalm-6 branch May 27, 2020 21:11
@greg0ire
Copy link
Member Author

Finally!

@pkruithof
Copy link
Contributor

Sorry to comment on an older PR, but this commit causes phpstan to report an error: https://phpstan.org/r/e462e0f9-abc4-44bc-8a9a-80aca2717980

I've asked a support question there, and the author suggested a solution here: phpstan/phpstan#3849 (comment)

Would you accept a PR with the second solution? I don't think a third-party library should trigger phpstan errors in a project.

@morozov
Copy link
Member

morozov commented Sep 9, 2020

@pkruithof please go ahead and submit a PR. @greg0ire could you work with PHPStan on finding the root cause as suggested in the first option?

@pkruithof
Copy link
Contributor

I just tried the suggestion but it did not help unfortunately, and I'm kind of out of my depth here. 😞

@morozov
Copy link
Member

morozov commented Sep 9, 2020

@pkruithof let's start with filing a new issue that would reproduce the problem.

@pkruithof
Copy link
Contributor

Done 👉 #4264

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants