-
Notifications
You must be signed in to change notification settings - Fork 188
Fix PhanUndeclaredMethod in tests directory #7241
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
Conversation
| function testAddElementSelect() | ||
| { | ||
| $this->form = $this->getMockBuilder('LorisForm') | ||
| $form = $this->getMockBuilder('LorisForm') |
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.
These need to be converted from a property to a simple variable for @phan-var to work on them. Adding the type hint isn't sufficient since phan picks up on the fact that it was assigned to a mock right before the call and uses that type instead of the phpdoc type, but you can't use @phan-var on a property..
| public function testCreateFeedbackTypeWithInvalidName() | ||
| { | ||
| $this->setExpectedException('LorisException'); | ||
| $this->expectException('LorisException'); |
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 know why this test was passing since setExpectedException was removed from phpunit, but phan picked it up here..
| $this->_instrument->addScoreColumn( | ||
| "FieldName2", | ||
| null | ||
| "Field 2", |
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.
After adding the type to $this->_instrument phan picked up on the argument type mismatch. (neither argument to addScoreColumn in NDB_Page is nullable according to the phpdocs.)
| ], | ||
| 'NoResponse' => true | ||
| ]; | ||
| $this->_instrument->form = new \Candidate(); |
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.
After adding the type hint phan picked up on this too.. a candidate isn't a LorisForm. This is clearly wrong (and unused.)
|
@kongtiaowang since this is just touching the test directory could you review? |
| */ | ||
| function testCandidate() | ||
| { | ||
| $mockdb = $this->getMockBuilder("\Database")->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.
These tests were failing in the same way as #7199 so I stole the fix from there. I'm not sure why they're failing on this branch it seems to be unrelated, but was necessary for the tests..
Changing the label changes the results..
Not sure why they're failing on this PR, seems to be unrelated.
410b8c5 to
4352d3d
Compare
This fixes all of the "PhanUndeclaredMethod" class errors in the test directory. These are mostly caused by phan not knowing that mock objects have the methods of the class being mocked, and it needs to be specifically told so with a phan type assertion. Calling methods that don't exist is a bad idea. We should unignore this error type, but first the errors need to be fixed. This PR starts with a large number of false positives caused by mock objects..
This fixes all of the "PhanUndeclaredMethod" class errors in the test directory. These are mostly caused by phan not knowing that mock objects have the methods of the class being mocked, and it needs to be specifically told so with a phan type assertion.
Calling methods that don't exist is a bad idea. We should unignore this error type, but first the errors need to be fixed. This PR starts with a large number of false positives caused by mock objects..
Testing instructions
.phan/config.php.