Page MenuHomePhabricator

Add a reflection-based unit test for subclasses increasing method visibility
ClosedPublic

Authored by joshuaspence on Dec 29 2014, 5:17 PM.
Tags
None
Referenced Files
F14475792: D11052.id27416.diff
Fri, Dec 27, 8:59 PM
Unknown Object (File)
Wed, Dec 11, 8:15 PM
Unknown Object (File)
Wed, Dec 11, 6:28 PM
Unknown Object (File)
Mon, Dec 9, 12:09 PM
Unknown Object (File)
Sat, Dec 7, 12:27 PM
Unknown Object (File)
Thu, Dec 5, 12:38 PM
Unknown Object (File)
Thu, Dec 5, 3:27 AM
Unknown Object (File)
Thu, Dec 5, 3:23 AM

Details

Summary

Ref T6822. We can't actually commit this until we fix all the violations mentioned in that task. Depends on D11231.

Test Plan
  • Used code to identify violations.
  • Hit exception under arc unit --everything.

Diff Detail

Repository
rPHU libphutil
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

epriestley retitled this revision from to Add a reflection-based unit test for subclasses increasing method visibility.
epriestley updated this object.
epriestley edited the test plan for this revision. (Show Details)
epriestley added a reviewer: btrahan.

Changing this file is also not triggering the test itself, which is a bug, but I'm just going to ignore that for the moment.

This should maybe be a new method (such as PhabricatorInfrastructureTestCase::testMethodsDoNotChangeVisibility).

Also, this test won't be run in rARC or rPHU... Maybe there should be a base PhutilLibraryTestCase class to avoid copy-paste.

Seems worth writing to work for rARC and rPHU... otherwise LGTM...!

Pushing this up the tree makes sense, and we need T6822 first anyway.

joshuaspence added a reviewer: epriestley.

Sorry to comandeer, but I want to play with this a bit.

joshuaspence edited edge metadata.

Move to PhutilLibraryTestCase

Haha, no problem. This looks good once we sort out T6822.

Interesting... one issue that I noticed with this is that it fails if any of the loaded libraries violate the method visibility rule. For example, I just hit this in rP:

> arc unit -- src/
   FAIL  PhabricatorLibraryTestCase::testMethodVisibility
Assertion failed, expected values to be equal (at PhutilLibraryTestCase.php:88): Class "ArcanistPhpcsLinter" implements method "getMandatoryFlags" with the wrong visibility. The method has visibility "public", but it is defined in parent "ArcanistExternalLinter" with visibility "protected". In Phabricator, a method which overrides another must always have the same visibility.
Expected: 'protected'
  Actual: 'public'
joshuaspence edited edge metadata.

Output multiple failures rather than only the first

epriestley edited edge metadata.
This revision is now accepted and ready to land.Jan 15 2015, 8:36 PM

I think testing the depends-on libraries implicitly is fine, the testEverythingImplemented() test effectively does this too. Getting multiple test failures from one root cause isn't great in either case, but we could have the subclasses coordinate if we ever care to fix that. Doesn't seem like a big deal.

I think testing the depends-on libraries implicitly is fine, the testEverythingImplemented() test effectively does this too. Getting multiple test failures from one root cause isn't great in either case, but we could have the subclasses coordinate if we ever care to fix that. Doesn't seem like a big deal.

Oh, it's easy to fix... should I bother?

The immediate fixes I can come up (some static "this has run" flag) with would incorrectly break if something tried to run the test twice, which seems sort-of worse than just reporting the failure twice.

I guess you could clear the flag in willRunTests() and then set it in the first test to run? If that's not too much of a mess, maybe worthwhile, but I haven't looked at that code too recently. Either way seems fine to me.

This revision was automatically updated to reflect the committed changes.