Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
plugin system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
3 Nov 2014 at 06:37 UTC
Updated:
5 Dec 2014 at 23:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
mile23ContextDefinition scores as riskiest in the Drupal\Core\Plugin namespace by CRAP number.
This patch reduces its overall CRAP score from 420 to 138.
We test the two most complex methods:
getDataDefinition()andgetConstraint().Includes
@usesdirectives in order to appease the combined--strict --coverage-textgods. We've been having this conversation over in #2364555: Add @covers annotation, fix some --strict for PHPUnitThe PHPUnit coding standards don't talk about
@uses, which is why so many tests are marked as 'risky' by PHPUnit when you generate a coverage report with--strict. #2057905: [policy, no patch] Discuss the standards for phpunit based testsComment #2
jhedstromSince these are testing, as you say, the two most complex methods, I'd like to see a few code comments just to clarify the flow of these tests. It wasn't immediately obvious to me exactly where or when the exception in
testGetDataDefinitionInvalidType()was going to be thrown.Comment #3
mile23Well this is one of the problems with maintaining complex code in the first place, but yah, it could use some inline comments. How's this?
Comment #4
jhedstromThose comments look good to me.
Does it make sense to visit
\Drupal\system\Tests\Plugin\ContextPluginTestand remove some (all?) of those tests as part of this?Comment #5
mile23I'd say the more tests the better, and the less we muck about with other tests the better.
Also, this test is more of a pure unit test, while
\Drupal\system\Tests\Plugin\ContextPluginTestis functional.So therefore: No. :-)
Comment #6
jhedstromI don't fully agree with that--some of the tests in the ContextPluginTest are identical (fake unit tests). At least those should be removed to avoid unnecessary effort in the future.
Comment #7
mile23Well as soon as you get here:
...it's not a fake unit test any more. And that's the 2nd line of the only test method.
MockBlockManagerhas a ton of already-implemented dependencies.The test in the patch mocks everything, and it's probably a good idea to have a functional test, as well.
If you have a specific idea about what to remove, I'd love to see it. https://api.drupal.org/api/drupal/core!modules!system!src!Tests!Plugin!C...
Comment #8
jhedstromWhile
ContextPluginTestis using functional items for testing (users, nodes, and blocks), most of that test still reads to me like a unit test. For instance, isn't thisor
replaced by the bad context exception tests you wrote in this patch?
On the other hand, something like this looks highly functional:
Comment #9
jhedstromThinking about this more, since the SimpleTest cannot be removed completely, there's no real reason to mess with it. The unit tests provided here add needed coverage and look good to me.
Comment #11
mile23Patch in #3 applies and makes passing unit tests for me. Not sure why the test failed... Is the testbot unhappy?
Comment #13
alexpottNot used
nonexistent
Comment #14
mile231. I like to declare a use of the class under test. It's a style thing, though. Removed.
2. Typo gone.
3. Added Beta evaluation block.
Comment #15
jhedstromI think this is back to RTBC.
Comment #16
alexpottCommitted 7acca5b and pushed to 8.0.x. Thanks!
Thanks for adding the beta evaluation for to the issue summary.