Skip to content

[TASK] Add accessor tests for OutputFormat (part 1) #847

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 3 commits into from
Jan 31, 2025

Conversation

oliverklee
Copy link
Collaborator

@oliverklee oliverklee commented Jan 28, 2025

Currently, this class uses magic getters and setters. These
should be proper methods instead.

But first, we should have tests for the accessors. This is
part 1.

@coveralls
Copy link

coveralls commented Jan 28, 2025

Coverage Status

coverage: 45.068%. remained the same
when pulling 19261f0 on feature/output-format-accessors
into 116ab69 on main.

@oliverklee oliverklee force-pushed the feature/output-format-accessors branch from 0063965 to 99fb6e4 Compare January 30, 2025 21:40
@oliverklee oliverklee changed the title [TASK] Add proper getters and setters for OutputFormat [TASK] Add accessor tests for OutputFormat (part 1) Jan 30, 2025
@oliverklee oliverklee marked this pull request as ready for review January 30, 2025 21:40
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.

Brilliant.

I tried experimentally ramping up PHPStan to level 2 and got loads of warnings re using the magic __call(). If we can resolve this and increase the PHPStan checking level, it will give us more confidence about future changes.

However, I think some of the test cases could be made more realistic.

*/
public function setStringQuotingTypeSetsStringQuotingType(): void
{
$value = 'x';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a more realistic example here. Given the default is likely to be either " or ', how about `?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe have a dataProvider to provide more than one quote type.

*/
public function setStringQuotingTypeProvidesFluentInterface(): void
{
self::assertSame($this->subject, $this->subject->setStringQuotingType('x'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps also here.

*/
public function setSpaceAfterRuleNameSetsSpaceAfterRuleName(): void
{
$value = ' ';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a newline would be a more realistic example.

*/
public function setSpaceAfterRuleNameProvidesFluentInterface(): void
{
self::assertSame($this->subject, $this->subject->setSpaceAfterRuleName(' '));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

@oliverklee
Copy link
Collaborator Author

Or maybe have a dataProvider to provide more than one quote type.

The accessor tests are basically for two things:

  1. which default value the getter returns
  2. that setting (and then getting) a value using the setter works (for this to be checkable, we need to set value that is different to the default value); for the benefit of the human reader, the used value should vaguely make sense for this property

Checking that different quote types work is out of scope - I see it more in scope of the tests for the CSS elements that use this particular property.

@oliverklee oliverklee force-pushed the feature/output-format-accessors branch from 99fb6e4 to 1867996 Compare January 31, 2025 12:11
@oliverklee oliverklee requested a review from JakeQZ January 31, 2025 12:11
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.

setStringQuotingTypeSetsStringQuotingType() appears to now be setting the same as the default value.

Currently, this class uses magic getters and setters. These
should be proper methods instead.

But first, we should have tests for the accessors. This is
part 1.
@oliverklee oliverklee force-pushed the feature/output-format-accessors branch from 1867996 to f0b778f Compare January 31, 2025 21:06
@oliverklee oliverklee requested a review from JakeQZ January 31, 2025 22:05
@JakeQZ JakeQZ merged commit 6cbd495 into main Jan 31, 2025
21 checks passed
@JakeQZ JakeQZ deleted the feature/output-format-accessors branch January 31, 2025 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants