Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Bugfix/array should be valid datasource for resultset #255

Closed
wants to merge 6 commits into from
Closed

Bugfix/array should be valid datasource for resultset #255

wants to merge 6 commits into from

Conversation

bartmcleod
Copy link
Contributor

When I upgraded from an older version of Zend\Db I found that certain unit tests in the client project were failing. When a datasource provided to a ResultSet is an array, the ResultSet should work out of the box. It didn't, because current() did not account for a datasource which has entered the system as just an array, while the buffer is flagged -1, when the ResultSet was initialized with such a datasource. So that flag on the buffer can be used to early out current() in such a situation.

@bartmcleod bartmcleod changed the base branch from master to develop July 5, 2017 09:38
Copy link

@waltertamboer waltertamboer left a comment

Choose a reason for hiding this comment

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

Couple of small things, other than that I don't see any problems.

@@ -0,0 +1,13 @@
<?php


Choose a reason for hiding this comment

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

You should remove the extra new lines, they make the build fail but it's also messy

namespace ZendTest\Db\ResultSet;


class ReturnType

Choose a reason for hiding this comment

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

If I'm not mistaken you've created the ReturnType class to force a null to be returned from exchangeArray. You might want to add that in the class' docblock to make that clear to other developers.

@bartmcleod
Copy link
Contributor Author

bartmcleod commented Jul 5, 2017

Thanks @waltertamboer for the prompt review. I have updated the ReturnType test class.

* This class is just here to be able to provide the simplest possible custom return type
* for a ResultSet when calling ResultSet::setArrayObjectPrototype or using the constructor argument.
*
* Class ReturnType

Choose a reason for hiding this comment

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

This is quite obvious ;-)

@weierophinney Not sure about the package tag? Does ZF have a standard for this?


$returnType = new ReturnType();
$dataSource = [$returnType];
$this->resultSet->setArrayObjectPrototype($returnType);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it can use :

$dataSource = [new ArrayObject([], ArrayObject::ARRAY_AS_PROPS)];
$this->resultSet->setArrayObjectPrototype($dataSource);

so no need to have ReturnType.php file.

Choose a reason for hiding this comment

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

Will that return null when exchangeArray is called?

Copy link
Contributor Author

@bartmcleod bartmcleod Jul 5, 2017

Choose a reason for hiding this comment

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

Thanks for your feedback. I don't think your suggestion covers the use case, while using ArrayObject obfuscates what I'm trying to prove, as ArrayObject is used all over ResultSet and it seems to know very well how to handle it. Problems arise when you are not using an ArrayObject, so I would rather not venture into using it. Also, when I try it as you suggested, the test case testCanProvideArrayAsDataSource fails with Object must be of type ArrayObject, or at least implement exchangeArray.

Copy link
Contributor Author

@bartmcleod bartmcleod Jul 5, 2017

Choose a reason for hiding this comment

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

@waltertamboer It will return null. Why?

Copy link
Contributor

Choose a reason for hiding this comment

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

@bartmcleod the object required for it is an object that need to has exhangeArray(), while ArrayObject already has it. I tried with ArrayObject and working fine at mine:
screen shot 2017-07-05 at 8 02 14 pm

Copy link
Contributor

Choose a reason for hiding this comment

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

oops, sorry, wrong variable, will retry

Copy link
Contributor

Choose a reason for hiding this comment

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

should be ok with:

        $returnType = new ArrayObject([], ArrayObject::ARRAY_AS_PROPS);
        $dataSource = [$returnType];
        $this->resultSet->setArrayObjectPrototype($returnType);
        $this->resultSet->initialize($dataSource);

Copy link
Contributor

Choose a reason for hiding this comment

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

samsonasik and others added 3 commits July 5, 2017 20:07
@bartmcleod
Copy link
Contributor Author

@samsonasik thanks for your contribution

@ezimuel
Copy link
Contributor

ezimuel commented Nov 28, 2017

@bartmcleod if this is a bugfix why did you send to develop branch?

@bartmcleod
Copy link
Contributor Author

@ezimuel I haven't contributed in a while. Where should it go? master? Happy to change the target.

@ezimuel
Copy link
Contributor

ezimuel commented Nov 28, 2017

@bartmcleod I can do that, no problem. I was just checking if this was a bugfix. Thanks!

@bartmcleod
Copy link
Contributor Author

@ezimuel Ok, thanks. It's a bugfix.

@ezimuel
Copy link
Contributor

ezimuel commented Nov 28, 2017

@bartmcleod I tried to merge in master but it seems there are some issues. Can you try to send the PR against master? Thanks.

@bartmcleod
Copy link
Contributor Author

@ezimuel I will set a reminder for myself

@ezimuel ezimuel added this to the 2.9.0 milestone Nov 28, 2017
@ezimuel
Copy link
Contributor

ezimuel commented Nov 30, 2017

@bartmcleod I finally rebased the PR and merged in master (and develop). I'm closing the PR. Thanks again for your contribution!

@ezimuel ezimuel closed this Nov 30, 2017
ezimuel added a commit that referenced this pull request Nov 30, 2017
@bartmcleod
Copy link
Contributor Author

@ezimuel welcome, and thanks for the merge. I had the reminder set for tomorrow morning, can clear that now :-)

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