Skip to content

Conversation

@oliverklee
Copy link
Collaborator

Part of #757

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.

I like the running theme of amusing and bizarre messages used in the tests. (Some hosts give me tea in the morning when coffee is expected; YMMV.)

I think one of the test methods (repeated 4 times) is conflated, and that there should be two separate test methods: one for the message, and one for the line number.

I'm also wondering about the duplication. I think it's right to also test that the extended classes' behaviour match the base (where that is expected). But I wonder if it's possible to have a base class or trait for the TestCase to provide the common tests - if that would work with PHPUnit which I know relies on @test in the DocBlock.

/**
* @test
*/
public function getMessageForLineNumberProvidedIncludesMessage(): void
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto (re two separate tests and naming).

/**
* @test
*/
public function getMessageForLineNumberProvidedIncludesMessage(): void
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto.

/**
* @test
*/
public function getMessageForLineNumberProvidedIncludesMessage(): void
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto.

/**
* @test
*/
public function getMessageForLineNumberProvidedIncludesMessage(): void
Copy link
Collaborator

Choose a reason for hiding this comment

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

GitHub lost my comment here. The various 'dittos' refer to this.

I think this is conflating two tests, one that the line number is included, and one that the message is included when a line number is provided. Also the name is confusing. I'd suggest

  • getMessageWithLineNumberProvidedIncludesMessage and
  • getMessageWithLineNumberProvidedIncludesLineNumber.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, I mixed up the tests names indeed. Fixed.

As far as the message provided to the constructor is concerned, we already have the getMessageReturnsMessageProvidedToConstructor tests for cases where the exception actually uses the message provided to the constructor.

Copy link
Collaborator

Choose a reason for hiding this comment

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

True, but we don't have a test to confirm the message when a line number argument is passed.

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.

I added back (roughly) a key comment that GitHub lost.

@coveralls
Copy link

coveralls commented Feb 13, 2025

Coverage Status

coverage: 50.527% (+1.4%) from 49.156%
when pulling d1b22cb on task/exception-tests
into 537f5e8 on main.

@oliverklee
Copy link
Collaborator Author

I like the running theme of amusing and bizarre messages used in the tests. (Some hosts give me tea in the morning when coffee is expected; YMMV.)

❤️

@oliverklee
Copy link
Collaborator Author

I'm also wondering about the duplication. I think it's right to also test that the extended classes' behaviour match the base (where that is expected). But I wonder if it's possible to have a base class or trait for the TestCase to provide the common tests - if that would work with PHPUnit which I know relies on @test in the DocBlock.

For class testing hierarchies, we could add an assertInstanceOf that tests that the subclass extends the base class, and rely on the tests of the base class.

I'll add tests for the instanceOf. As far as the behavior is concerned, I'd prefer to have the tests duplicated. This makes the test easier to understand, and it will allow us to refactor more easily.

@oliverklee oliverklee requested review from JakeQZ and removed request for sabberworm February 13, 2025 09:22
@JakeQZ
Copy link
Collaborator

JakeQZ commented Feb 14, 2025

As far as the behavior is concerned, I'd prefer to have the tests duplicated. This makes the test easier to understand, and it will allow us to refactor more easily.

Duplicated code shrieks at me. It's much less maintainable, It's fine for now, but I would like to come up with a way of avoiding it.

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.

Added #919 to cover possible clean-up.

@JakeQZ JakeQZ merged commit 7121bc3 into main Feb 14, 2025
21 checks passed
@JakeQZ JakeQZ deleted the task/exception-tests branch February 14, 2025 02:02
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.

4 participants