-
Notifications
You must be signed in to change notification settings - Fork 144
[TASK] Add some tests for OutputFormatter
(part 1)
#943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
OutputFormatter
OutputFormatter
(part 1)
d06d72b
to
98fe7b4
Compare
05beffb
to
33db0fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent demonstration of how to use mock objects (which I have not yet tried).
Some test method names I found difficult to understand. But then disocovered trying to come up with better alternatives was equally difficult. I finally worked out some suggested renames.
A variable set up in one test should be used in that test.
The level increment test doesn't appear to be testing the level increment.
tests/Unit/OutputFormatterTest.php
Outdated
$renderedRenderable1 = 'tea'; | ||
$renderable1->method('render')->with($this->outputFormat)->willReturn($renderedRenderable1); | ||
$renderable2 = $this->createMock(Renderable::class); | ||
$renderedRenderable2 = 'tea'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I have coffee please? ;)
/** | ||
* @test | ||
*/ | ||
public function implodeWithIncreaseLevelTrueIncreasesIndentationLevelForRendering(): void | ||
{ | ||
$renderable = $this->createMock(Renderable::class); | ||
$renderedRenderable = 'tea'; | ||
$renderable->method('render')->with($this->outputFormat->nextLevel())->willReturn($renderedRenderable); | ||
$values = [$renderable]; | ||
|
||
$result = $this->subject->implode(', ', $values, true); | ||
|
||
self::assertSame($renderedRenderable, $result); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the level increment being asserted here. Shouldn't we be getting tea after some space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that's up to the Rederable
instance how it uses the indentation level. (For example, Comment
s do not care about the indentation level at all.)
What we're testing here in this unit tests is that render()
will get the next level output format passed in: The with()
call asserts that the expected call has the corresponding argument (compared using ==
, not ===
, or like assertEquals()
instead of assertSame()
), and will fail the test otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed the change to the argument passed to with()
compared with the previous test. I think I see and understand what's going on now. Reviewing this has been an educative process 👍
33db0fa
to
e3a387c
Compare
Thanks! (Yes, I had a hard time coming up with good names for these cases, too …) |
Note: The new PHPStan warnings will go away once we add native type declarations for `OutputFormatter`. Part of #757
Co-authored-by: JakeQZ <[email protected]>
Co-authored-by: JakeQZ <[email protected]>
Co-authored-by: JakeQZ <[email protected]>
Co-authored-by: JakeQZ <[email protected]>
Co-authored-by: JakeQZ <[email protected]>
dfadbaf
to
2d617c6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been an educative PR, including perhaps also learning that we have different preferences for caffeinated hot drinks.
I think we need to clear this up. 😉 I prefer coffee (one cup in the morning, one after lunch), and black Darjeeling (between and after that). And when I need the extra bit of energy, I occasionally enjoy some Club-Mate (or something similar from a different brand). So, what's your preference? |
Seems I misunderstood since you preferred tea in the tests.
Coffee with/after breakfast and lunch, and after evening dinner. Usually from a cafatiere. When I smoked, I would have half a cup with each cigarette too. :) |
Note: The new PHPStan warnings will go away once we add
native type declarations for
OutputFormatter
.Part of #757