-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Unit Test improvements] Use getMockBuilder rather than getMock directly #12990
Conversation
Avoid situations that would cause `PHP Fatal error: Call to protected method PHPUnit_Framework_TestCase::getMock()` on newer versions of phpunit
I was about to say I thought some of these were changed in the 4.0 branch, but looking it up it looks like what was changed actually dealt with some of the classes becoming abstract versus concrete (so using the Looks fine to me. |
@mbabker The next big thing to fix in the unit tests after this is merged are the Assert Tags PHPUnit_Framework_Assert::assertTag is deprecated: 59x
10x in JFormFieldRadioTest::testGetInput
6x in JFormTest::testGetInput
3x in JFormFieldCheckboxesTest::testGetInputValueArrayNoChecked
3x in JFormFieldCheckboxesTest::testGetInputValueNoChecked
3x in JFormFieldCheckboxesTest::testGetInputNoValueNoChecked
3x in JFormFieldCheckboxesTest::testGetInputNoValueOneChecked
3x in JFormFieldCheckboxesTest::testGetInputValuesNoChecked
3x in JFormFieldCheckboxesTest::testGetInputValueChecked
3x in JFormFieldCheckboxesTest::testGetInputNoValueTwoChecked
2x in JFormFieldTest::testSetup
2x in JFormFieldTest::testGetLabel
2x in JHtmlBatchTest::testItem
2x in JHtmlBatchTest::testUser
2x in JHtmlBatchTest::testAccess
2x in JHtmlListTest::testUsers
2x in JHtmlBatchTest::testLanguage
1x in JFormFieldHiddenTest::testGetInput
1x in JHtmlBootstrapTest::testRenderModal
1x in JHtmlBootstrapTest::testStartAccordion
1x in JHtmlBootstrapTest::testAddTab
1x in JFormTest::testGetLabel
1x in JHtmlBootstrapTest::testStartTabSet
1x in JHtmlBootstrapTest::testaddSlide
1x in JHtmlListTest::testPositions |
Ugh, it appears there are nearly 2000 more places where we need to Use getMockBuilder rather than getMock directly |
Do it on the 4.0 branch and that should be cut in half easily 😉 |
Fixes 10 hhvm failures that have one of the following messages ```php UnexpectedValueException: No columns found for #__extensions table Expectation failed for method name is equal to <string:parseSchemaUpdates> when invoked 1 time(s). Method was expected to be called 1 times, actually called 0 times. ```
@mbabker I decided that I might as well just fix the test with hhvm failures in this PR. |
hope to find time to test it, thanks for the work on this |
@rdeutz you are welcome. I hope we can get this merged soon. |
Once this PR is merged we can also close issue #10220 |
After this PR is merged we can consider moving HHVM out of the allowed failures on Travis. |
@@ -184,7 +183,7 @@ public function testProcessElementWithEntry() | |||
public function testFetchNamespace() | |||
{ | |||
// Set a mock namespace into the namespaces for the parser object. | |||
$mock = $this->getMock('JFeedParserNamespace'); | |||
$mock = $this->getMockBuilder('JFeedParserNamespace')->getMock();; |
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.
Code style: ;;
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.
Thanks for catching that, I have fixed this.
) | ||
); | ||
JFactory::$application = $this->getMockBuilder('JApplication') | ||
->setMethods(array('get', 'getCfg', 'getRouter',)) |
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.
Code style ',)'
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'm not sure what your referencing here arrays should end with a comma
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.
For one line array I suggest to not use comma before ')'
array('get', 'getCfg', 'getRouter' =>,<= )
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.
Whey they're multiline arrays you should end it with a comma. A single line array like this one, the trailing comma can be left off.
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.
For single line array, can or should leave off the trailing comma? I generally take the stance of always including the trailing comma.
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 don't think it's set in stone anywhere, but the general convention across the board (not just here in Joomla land) is single line arrays don't have a trailing comma while multiline arrays do.
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.
If it helps speed getting this approved and merged.... I have made the changes
) | ||
); | ||
JFactory::$application = $this->getMockBuilder('JApplication') | ||
->setMethods(array('get', 'getCfg', 'getRouter',)) |
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.
Code style ',)'
$mockTableExtension = $this->getMock('JTableExtension', array('find', 'load'), array($this->getMockDatabase())); | ||
$mockTableExtension = $this->getMockBuilder('JTableExtension') | ||
->setMethods(array('find', 'load')) | ||
->setConstructorArgs(array(self::$driver)) |
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.
Which way is correct? Use self:driver
or $this->getMockDatabase()
as below?
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.
There is some issue with this specific test using $this->getMockDatabase()
on HHVM that causes 9 failures and 1 error. Using self:driver
in this one test resolves all of those issues.
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 probably is not related to current PR.
If I correctly understand $this->getMockDatabase()
simulates a connection to the database.
Then using self::$driver is correct.
It should be used too in method below testCheckExistingExtensionForExtensionThatDoesNotExist
.
Notice: Parent class TestCaseDatabase
always create a real connection to sqlite in self::$driver
. Probably we do not need to use a mock database at all.
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 agree "probably is not related to current PR"
@csthomas With the requested changes implemented, would you mark your code review successful? |
Yes. I wanted to check success it yesterday but I have tried to understand the way how does This is not directly related to this PR. |
I have tested this item ✅ successfully on b5d6a6d This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12990. |
@photodude Thanks, this was a really big PR and a lot of work. Could you make smaller parts in the future, please, then there is not so much danger that we run into conflicts :-) |
@rdeutz, you are welcome, thank you for merging. I do generally try to avoid such large PRs. Like the code style PRs I've done, I've keep those to single components. I agree the large PRs are difficult to review and cause other issues like merge conflicts across other open PRs; and that should generally be avoided. |
Pull Request for Issue getMock was used directly.
Summary of Changes
Use getMockBuilder rather than getMock directly
This is needed to avoid situations that would cause
PHP Fatal error: Call to protected method PHPUnit_Framework_TestCase::getMock()
on newer versions of phpunitAlso fixes a missing method in the application cms mock needed for phpunit 5.6 compatibility, and fixes a mockdatabase issue in the JInstallerAdapter tests on hhvm
Testing Instructions
Merge by code review, Travis tests pass
Documentation Changes Required
none