-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
UnqueryableQueryMock::all() returns Exception but 0 count is expected #41
Comments
I found the problem, it is about how prepareModels() has changed. In current ActiveDataProvider version, prepareModels() calls prepareQuery(). When there are not records, active-record/src/data/ActiveDataProvider.php Line 122 in bed8118
In previous implementation, prepareModels() returned an empty array where there are not records: active-record/src/data/ActiveDataProvider.php Line 111 in e93f97c
This is from last commit, where @GHopperMSK wanted to explicit $query content to simplify debug activities. We can solve checking emulateExecution property that it has been used to track this case, from last commit: protected function prepareModels()
{
$query = $this->prepareQuery();
return ($query->emulateExecution) ? [] : $query->all($this->db);
} |
I don't think it is a good idea to return an empty array. Now we return Maybe we should just adapt the test to new conditions? |
In previous implementation, prepareModels() did the same work that you now do with two methods, so it made sense that it returned an empty array, in that condition. |
If so, then how test |
I have explained in previous post, because prepareModels() returned an empty array: active-record/src/data/ActiveDataProvider.php Line 111 in e93f97c
and test succeded. |
This should be fixed in |
In this case it is not about UnqueryableQueryMock throw an exception independently from emulateExecution. |
Yes, and that is the problem. |
Why? In previous release it worked fine, because as class name says it has to test query not queryable. |
The purpose of this mock is to ensure that no actual query will be performed. With |
Take a look at differences from last commit (not working) and previous (working). |
@FabrizioCaldarelli I don't get your point. These changes are correct, the tests should be fixed to not throw exception when there is no need for it. It was already done in yiisoft/yii2#17073 |
I showed how keep current tests and current changes together. |
Why would you want add additional conditions to (correct) code instead of fixing (incorrect) tests? It is actually a bug that |
active-record/tests/unit/ActiveDataProviderTest.php
Line 193 in bed8118
Here we expect that count is 0. But UnqueryableQueryMock::all() returns an Exception mandatory.
https://github.com/FabrizioCaldarelli/db/blob/b1bb19a4bafbe5a84aa62388cd3f0e81b5db809f/tests/unit/UnqueryableQueryMock.php#L28
The text was updated successfully, but these errors were encountered: