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

Replaced ArrayIterator with StatementIterator in Portability\Connection #3115

Merged
merged 1 commit into from
Apr 29, 2018

Conversation

morozov
Copy link
Member

@morozov morozov commented Apr 22, 2018

Fixes #3114

@morozov morozov requested a review from Majkl578 April 22, 2018 01:21
@morozov morozov added this to the 2.7.2 milestone Apr 22, 2018
@morozov morozov force-pushed the issues/3114 branch 2 times, most recently from 8216edf to 577f6ab Compare April 22, 2018 01:48

public static function statementProvider()
{
if (extension_loaded('ibm_db2')) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike MysqliStatement and SQLAnywhereStatement, DB2Statement and other driver statement class declarations depend on corresponding extension symbols, so they only can be loaded if extensions are loaded.


class StatementIteratorTest extends \Doctrine\Tests\DbalTestCase
{
public function testGettingIteratorDoesNotCallFetch()
/**
* @dataProvider statementProvider()

This comment was marked as resolved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've been always using them. A function name without parentheses looks awkward.

$stmt->getIterator();
}

public function testIteratorIterationCallsFetchOncePerStep()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can haz void?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to require a non-empty return type on test methods? It's void in 99% of cases, but if a test returns a dependency, it's in most cases of a known type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the "non-empty return type" part. You mean making all tests return something specific, instead of void?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean that the return type must be always explicitly specified and in most cases be void.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course. We just have it disabled currently in DBAL because of BC:

<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint"/>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it could be a requirement project-wide. For instance, fetch() could return either a row (array) or one field (string|null) or false (end of set). You'll have to have a very strict API to enable this, can't see it happening in the near future.

/**
* @dataProvider statementProvider()
*/
public function testStatementIterationCallsFetchOncePerStep(string $class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can haz void?

$this->assertIterationCallsFetchOncePerStep($stmt, $calls);
}

private function configureStatement(MockObject $stmt, &$calls) : void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can haz int typehint?
I am pretty sure @Ocramius will hate the reference here. 😆

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been through that a couple of times. Sometimes they just make sense.


$stmtIterator = new StatementIterator($stmt);
foreach ($stmtIterator as $i => $_) {
private function assertIterationCallsFetchOncePerStep(Traversable $iterator, &$calls) : void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can haz int typehint?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was lazy to initialize the variable :)

$this->assertEquals($i + 1, $calls);
}
}

public static function statementProvider()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can haz iterable return type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, again, was lazy to add the element type hint which the CS forces.

@Majkl578
Copy link
Contributor

This also fixes #2705 imho.

@morozov morozov merged commit e51e73e into doctrine:master Apr 29, 2018
@morozov morozov deleted the issues/3114 branch April 29, 2018 20:28
morozov added a commit that referenced this pull request Apr 29, 2018
@morozov
Copy link
Member Author

morozov commented Apr 29, 2018

Back-ported to 2.7 via 5003847.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 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.

2 participants