Problem/Motivation
Yet another notch in the belt of #2052109: [meta] Expand phpunit tests for \Drupal\Component\Plugin classes.
This issue covers Drupal\Component\Plugin\Context\Context, which has zero unit test coverage.
In the process of writing this test, I found a bug: #2378297: Inconsistent use of ContextDefinitionInterface in Drupal\Component\Plugin\Context\Context::getConstraints() This means that getConstraints() is not covered by this test, and should be covered by the bug fix in that other issue.
Proposed resolution
Remaining tasks
User interface changes
API changes
Beta phase evaluation
| Unfrozen changes | Unfrozen because it only changes automated tests. |
|---|
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | interdiff_1.txt | 472 bytes | mile23 |
| #9 | 2378311_9.patch | 3.13 KB | mile23 |
Comments
Comment #1
mile23This patch covers Context::getContextValue(), which is the most complex method in this class (CRAP score: 12).
As noted in the issue summary, this patch avoids
getConstraints(), which is buggy.Comment #2
dawehnerCan't we split this up into two test methods and use two times the same provider?
Comment #3
mile23The logic follows the logic of getContextValue().
I thought about refactoring it the way you mention, but it doesn't make much sense, since there are only three data sets from the data provider.
Nevertheless: Judge for yourself. :-)
I prefer the patch in #1.
Comment #4
mile23Anyone? :-)
Comment #5
mile23Comment #6
duaelfr6/6 tests PASS
29% coverage but most of the uncovered code is made of getters and setters.
Don't we want the ::getConstraints() and ::validate() methods tested ?
Usual comments:
Unused ;)
I don't like that kind of condition but that's just my point of view...
Comment #7
mile23See the summary about
getConstraints(). It's buggy, so I didn't test it :-) #2378297: Inconsistent use of ContextDefinitionInterface in Drupal\Component\Plugin\Context\Context::getConstraints()validate()depends on a static factory. It should really allow you to inject a validator, but it doesn't.Point 2: That's what I mean about the patch in #1 being better.
Comment #8
daffie commented@Mile23: If you think that the validate() should use injection instead of a static factory, why don't you create an issue for that.
I prefer the patch from comment #1. I have added to #2378297: Inconsistent use of ContextDefinitionInterface in Drupal\Component\Plugin\Context\Context::getConstraints() that there is the need for a PHPUnit test for the ::getConstraints() method.
Fix the first comment from DuaelFr: remove the unused:
use Drupal\Component\Plugin\Context\Context;.If there is an issue created for the ::validate() method and in that issue an mention for creating a PHPUnit test for the ::validate() method, then I shall give this issue an RTBC.
Comment #9
mile23Here's the patch from comment #1, minus the
usestatement. :-)Issue about
validate()to come.Comment #10
mile23Comment #11
mile23Hello, testbot?
Comment #12
mile23Filed #2382805: Modify Drupal\Component\Plugin\Context\ContextInterface to allow for unit testing..
One or the other of these two issues will need a re-roll when the other drops.
Comment #13
daffie commentedIn this patch is the file ContextText class added with a PHPUnit test. The only function that is been tested is getContextValue(). There are also a few getters and setters functions that are not tested. The two remaining functions are getConstraints() and validate(). For the first function is #2378297: Inconsistent use of ContextDefinitionInterface in Drupal\Component\Plugin\Context\Context::getConstraints() created and for the second function #2382805: Modify Drupal\Component\Plugin\Context\ContextInterface to allow for unit testing.. The patch lloks good to me and I give it a RTBC.
Comment #15
mile23Patch applies and everything passes locally so I assume it's the testbot.
Comment #17
mile23Comment #18
daffie commentedBefore the retest failed it was RTBC. Nothing has changed and the testbot is happy again. So back to RTBC.
Comment #19
webchickNot really the most qualified to give these sign-off, but they've been sitting here long enough for someone to raise objections, and moar test coverage is never a bad thing.
Committed and pushed to 8.0.x. Thanks!