[TASK] Add Selector\Combinator class - #1487
Conversation
|
Note that this includes the renaming from #1486, which should be reviewed and merged first. Hopefully there won't be subsequent merge conflicts, since the changes overlap, |
23ff825 to
d697d04
Compare
| } | ||
|
|
||
| /** | ||
| * @return ' '|'>'|'+'|'~' |
There was a problem hiding this comment.
Maybe we can define a custom PHPDoc type for this in the class doc: https://phpstan.org/developing-extensions/custom-phpdoc-types
There was a problem hiding this comment.
This looks quite involved. Could this perhaps be done post-PR if considered worthwhile?
There was a problem hiding this comment.
I'll do that in a minute and push. Hold on …
There was a problem hiding this comment.
Ah, and the link was incorrect. Now I understand the "quite involved" thing. :-)
I was thinking of a local type alias instead: https://phpstan.org/writing-php-code/phpdoc-types#local-type-aliases
| public function setValue(string $value): void | ||
| { | ||
| // Allow extra and other whitespace even if not publicly documented. | ||
| $trimmedValue = \trim($value); |
There was a problem hiding this comment.
Also, I'd consider it more to be the responsibility of the caller to first trim the value. This would keep our API more clean. WDYT?
There was a problem hiding this comment.
I'm fine with that and have removed the trimming. I've added a description to the @throws annotation to indicate what is allowed, since, because this is implementing an interface, it's not possible to tighten the parameter definition.
| * | ||
| * @dataProvider provideValidValue | ||
| */ | ||
| public function setsValueProvided(string $value): void |
There was a problem hiding this comment.
Let's add the name of the tested method:
| public function setsValueProvided(string $value): void | |
| public function setValueSetsValueProvided(string $value): void |
There was a problem hiding this comment.
This seems redundant to me. Also the parsing tests were written as parsesXyz(), not parseParsesXyz().
There was a problem hiding this comment.
This is what I teach developers about naming tests at my testing workshops:
https://speakerdeck.com/oliverklee/test-driven-development-with-phpunit-915a5f2c-3d37-4e41-b5bc-ef1efca9c01e?slide=39
In general, if a test is a bout a specific method, it should include (and preferable start with) the name of the tested method. When there are redundancies in the test name, this usually is a sign of the tested method having a descriptive name, i.e., it should be the case quite often.
And it the test is about the behavior of the class in general, the test name should either start with class or theClass, or this can be implicit: (theClass)implementsCaffeinated.
There are several reasons why I find this important:
- Having meaningful, complete test names allows the reader to roughly understand what the test is about even without having to read the code of the test method.
- This allows the reader to compare what the test method name states with the code of the test method, which kind of creates a "double bookkeeping" system which allows us to identify tests testing the wrong thing.
- Tests not only check for the behavior being correct, but also they serve as documentation of the behavior. So they should be meaningful particularly if the reader is not (yet) familiar with the structure of our code and with what method does what.
Concerning parsing: Yes, we might clean those tests up, and we might want to decide if the parsing is something that "the class" does or the parse method, and rename the tests accordingly.
I'd say it's the latter. WDYT?
There was a problem hiding this comment.
OK. I think I understand the reasoning. setsValueProvided() isn't testing a behaviour; it's testing the setValue() method. Whereas parsesXyz() is testing the parsing behaviour, and happens to be also testing the parse() method. So in the latter case I think I still prefer parsesXyz() to parseParsesXyz(). Another one is constructsWithValueProvided() vs constructorConstructsWithValueProvided(). This is testing the instantiation behviour while also testing the constructor, so I think there's an arguable case for either.
I'll change the test method names where they are specifically testing a class method rather than a behaviour...
| * | ||
| * @dataProvider provideValidValue | ||
| */ | ||
| public function rendersValueProvided(string $value): void |
There was a problem hiding this comment.
| public function rendersValueProvided(string $value): void | |
| public function renderRendersValueProvided(string $value): void |
There was a problem hiding this comment.
It should be clear that we're testing the 'rendering' whatever that actual method that does it is named.
There was a problem hiding this comment.
See above about redundant naming.
There was a problem hiding this comment.
It's slightly arguable that this is testing a behaviour, but I've changed this.
d697d04 to
b724647
Compare
|
I've changed |
|
I've added an additional test to confirm that |
8a07504 to
1ef6743
Compare
No description provided.