Skip to content

Conversation

@driusan
Copy link
Collaborator

@driusan driusan commented Dec 17, 2020

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

  1. Remove "PhanUndeclaredMethod" from .phan/config.php.
  2. Verify that there are no errors from the test directory (there are other errors from our code)
  3. Check that the tests still pass. (The behaviour of them shouldn't have changed.)

function testAddElementSelect()
{
$this->form = $this->getMockBuilder('LorisForm')
$form = $this->getMockBuilder('LorisForm')
Copy link
Collaborator Author

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');
Copy link
Collaborator Author

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",
Copy link
Collaborator Author

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();
Copy link
Collaborator Author

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.)

@driusan
Copy link
Collaborator Author

driusan commented Dec 17, 2020

@kongtiaowang since this is just touching the test directory could you review?

*/
function testCandidate()
{
$mockdb = $this->getMockBuilder("\Database")->getMock();
Copy link
Collaborator Author

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..

@driusan driusan force-pushed the PhanUndeclaredMethod branch from 410b8c5 to 4352d3d Compare December 21, 2020 16:02
@laemtl laemtl self-requested a review January 8, 2021 20:37
@laemtl laemtl added the Passed manual tests PR has been successfully tested by at least one peer label Jan 8, 2021
@driusan driusan merged commit c4b383e into aces:main Jan 18, 2021
AlexandraLivadas pushed a commit to AlexandraLivadas/Loris that referenced this pull request Jun 29, 2021
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..
@ridz1208 ridz1208 added this to the 24.0.0 milestone Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Passed manual tests PR has been successfully tested by at least one peer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants