Skip to content
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

API Add AbsoluteLink method to RequestHandler #10749

Conversation

GuySartorelli
Copy link
Member

@GuySartorelli GuySartorelli commented Apr 5, 2023

This is a method that is commonly implemented on controllers, but it really doesn't need to be.

Issue

Copy link
Member

@emteknetnz emteknetnz left a comment

Choose a reason for hiding this comment

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

Should add some basic unit test. You'll probably end up just replicating the method logic in your unit test, though that's fine

This is a method that is commonly implemented on controllers, but
it really doesn't need to be.
@GuySartorelli GuySartorelli force-pushed the pulls/5/absolutelink-on-requesthandler branch from b4ac201 to 567484f Compare April 19, 2023 22:07
@GuySartorelli
Copy link
Member Author

Unit test added - good call. Also made the method correctly handle the scenario when Link() returns null.

Comment on lines +51 to +52
$this->expectWarning();
$this->expectWarningMessage('Request handler SilverStripe\Control\RequestHandler does not have a url_segment defined. Relying on this link may be an application error');
Copy link
Member Author

@GuySartorelli GuySartorelli Apr 19, 2023

Choose a reason for hiding this comment

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

These are deprecated and will be removed in PHPUnit 10 - but I think it's worth having them here while they work. We've got this sort of thing in a few places and eventually we'll have to think about what to do with it, but PHPUnit has a history of long support for not-current major releases so I suspect we won't be worrying about that until CMS 6.
This is the only way currently to test that the warning is being emitted, and we can't just change the warning to an exception here without breaking changes.

Copy link
Member

Choose a reason for hiding this comment

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

They're showing up as deprecation warnings as CI. https://github.com/silverstripe/silverstripe-framework/actions/runs/4748341443/jobs/8434430162?pr=10749#step:12:135 We shouldn't be adding tech debt in new PRs. At some point we'll remove the other warnings that are currently there

There is no migration path sebastianbergmann/phpunit#5062 (comment)

Can you please remove these assertions

Copy link
Member Author

Choose a reason for hiding this comment

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

For the reasons I've expressed above, I think it's worth keeping these here - we probably need another opinion at this stage.
@silverstripe/core-team any thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

Note: If I remove the assertions I also can't keep the test scenario where the returned value should be null, because phpunit converts the warning into an exception and the test fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe create a card to reach some consensus on how to handle warnings going forward. Those new PHPUnit warning are annoying enough that I think we should aim to address them now rather than wait for PHPUnit 10.

On the narrow point of what we should do with this PR, I think it makes sense to use the "old" way and expect a warning ... just in case we decide that we really like those "expect warning" clause in the follow up card and hack them back in somehow.

Copy link
Member Author

Choose a reason for hiding this comment

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

Issue created: silverstripe/.github#40

* Tests for RequestHandler and HTTPRequest.
* Tests for functionality related to handling requests - not unit tests for RequestHandler.
Copy link
Member Author

Choose a reason for hiding this comment

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

Modified this note because I was originally going to add the link tests in here, but then I noticed nothing in here is actually directly testing RequestHandler despite its name kiiinda suggesting that's what this class would be.

Comment on lines +51 to +52
$this->expectWarning();
$this->expectWarningMessage('Request handler SilverStripe\Control\RequestHandler does not have a url_segment defined. Relying on this link may be an application error');
Copy link
Member

Choose a reason for hiding this comment

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

They're showing up as deprecation warnings as CI. https://github.com/silverstripe/silverstripe-framework/actions/runs/4748341443/jobs/8434430162?pr=10749#step:12:135 We shouldn't be adding tech debt in new PRs. At some point we'll remove the other warnings that are currently there

There is no migration path sebastianbergmann/phpunit#5062 (comment)

Can you please remove these assertions

tests/php/Control/RequestHandlerTest.php Show resolved Hide resolved
@emteknetnz emteknetnz merged commit 73ef035 into silverstripe:5 Apr 26, 2023
@emteknetnz emteknetnz deleted the pulls/5/absolutelink-on-requesthandler branch April 26, 2023 06:25
blueo pushed a commit to blueo/silverstripe-framework that referenced this pull request May 24, 2023
This is a method that is commonly implemented on controllers, but
it really doesn't need to be.
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