Skip to content

[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

Merged
merged 7 commits into from
Feb 17, 2025

Conversation

oliverklee
Copy link
Collaborator

@oliverklee oliverklee commented Feb 16, 2025

Note: The new PHPStan warnings will go away once we add
native type declarations for OutputFormatter.

Part of #757

@oliverklee oliverklee self-assigned this Feb 16, 2025
@oliverklee oliverklee marked this pull request as draft February 16, 2025 13:58
@coveralls
Copy link

coveralls commented Feb 16, 2025

Coverage Status

coverage: 51.335% (+0.5%) from 50.801%
when pulling 2d617c6 on task/tests/output-formatter
into 1a385cd on main.

@oliverklee oliverklee changed the title [TASK] Add some tests for OutputFormatter [TASK] Add some tests for OutputFormatter (part 1) Feb 16, 2025
@oliverklee oliverklee force-pushed the task/tests/output-formatter branch from d06d72b to 98fe7b4 Compare February 16, 2025 15:05
@oliverklee oliverklee marked this pull request as ready for review February 16, 2025 15:05
@oliverklee oliverklee requested a review from JakeQZ February 16, 2025 15:05
@oliverklee oliverklee force-pushed the task/tests/output-formatter branch 2 times, most recently from 05beffb to 33db0fa Compare February 16, 2025 21:20
Copy link
Collaborator

@JakeQZ JakeQZ left a 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.

$renderedRenderable1 = 'tea';
$renderable1->method('render')->with($this->outputFormat)->willReturn($renderedRenderable1);
$renderable2 = $this->createMock(Renderable::class);
$renderedRenderable2 = 'tea';
Copy link
Collaborator

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? ;)

Comment on lines +286 to +299
/**
* @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);
}
Copy link
Collaborator

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?

Copy link
Collaborator Author

@oliverklee oliverklee Feb 17, 2025

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, Comments 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.

Copy link
Collaborator

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 👍

@oliverklee oliverklee force-pushed the task/tests/output-formatter branch from 33db0fa to e3a387c Compare February 17, 2025 18:19
@oliverklee
Copy link
Collaborator Author

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.

Thanks! (Yes, I had a hard time coming up with good names for these cases, too …)

@oliverklee oliverklee requested a review from JakeQZ February 17, 2025 18:29
@oliverklee oliverklee force-pushed the task/tests/output-formatter branch from dfadbaf to 2d617c6 Compare February 17, 2025 18:34
Copy link
Collaborator

@JakeQZ JakeQZ left a 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.

@JakeQZ JakeQZ merged commit 8a3cc0c into main Feb 17, 2025
21 checks passed
@JakeQZ JakeQZ deleted the task/tests/output-formatter branch February 17, 2025 18:57
@oliverklee
Copy link
Collaborator Author

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?

@JakeQZ
Copy link
Collaborator

JakeQZ commented Feb 17, 2025

I also found this quite amusing:

have-a-coffee

@JakeQZ
Copy link
Collaborator

JakeQZ commented Feb 17, 2025

I prefer coffee

Seems I misunderstood since you preferred tea in the tests.

So, what's your preference?

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.

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants