Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

42948 reduce response contraints verbosity#17848

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

Nicals
Copy link

Link the issue#49184, andPR.

Update signature of HTTP response constraints.

@NicalsNicals changed the base branch from6.2 to6.3February 1, 2023 11:57
@OskarStarkOskarStark added the Waiting Code MergeDocs for features pending to be merged labelFeb 1, 2023
@carsonbotcarsonbot added this to thenext milestoneFeb 1, 2023
fabpot added a commit to symfony/symfony that referenced this pull requestMar 17, 2024
…traints verbosity (Nicolas Appriou, Nicals)This PR was squashed before being merged into the 7.1 branch.Discussion----------[FrameworkBundle][HttpFoundation] reduce response constraints verbosity| Q             | A| ------------- | ---| Branch?       | 6.3| Bug fix?      | no| New feature?  | yes| Deprecations? | no| Tickets       |Fix#42948| License       | MIT| Doc PR        |symfony/symfony-docs#17848Adds a `verbose` argument to HttpFoundation response test constraints.If set to false, only the HTTP response command and headers will be displayed in case of test failure.This argument is `true` by default to keep backward compatibility, but I think it would make more sense to be `false`.<details>  <summary>Before</summary>```php$this->assertResponseIsSuccessful();``````-- PHPUnit output:Testing App\Controller\AppControllerTestF                                                                   1 / 1 (100%)Time: 00:00.299, Memory: 42.50 MBThere was 1 failure:1) App\Controller\AppControllerTest::testSuccessfulResponseFailed asserting that the Response is successful.HTTP/1.1 404 Not FoundCache-Control:          max-age=0, must-revalidate, privateContent-Type:           text/html; charset=UTF-8Date:                   Fri, 03 Feb 2023 10:54:05 GMTExpires:                Fri, 03 Feb 2023 10:54:05 GMTX-Debug-Exception:X-Debug-Exception-File: ...X-Robots-Tag:           noindex<!--  (404 Not Found) --><!DOCTYPE html><html lang="en">    <head>        <meta charset="UTF-8" />        <meta name="robots" content="noindex,nofollow" />    <!-- undred of lines later -->        Sfjs.createToggles();        Sfjs.createFilters();    });}/*]]>*/        </script>    </body></html><!--  (404 Not Found) -->/home/user/project/vendor/symfony/framework-bundle/Test/BrowserKitAssertionsTrait.php:142/home/user/project/vendor/symfony/framework-bundle/Test/BrowserKitAssertionsTrait.php:33/home/user/project/tests/Controller/AppControllerTest.php:35```</details><details>  <summary>After</summary>```php$this->assertResponseIsSuccessful(verbose: false);``````-- PHPUnit output:Testing App\Controller\AppControllerTestF                                                                   1 / 1 (100%)Time: 00:00.300, Memory: 42.50 MBThere was 1 failure:1) App\Controller\AppControllerTest::testSuccessfulResponseFailed asserting that the Response is successful.HTTP/1.1 404 Not FoundCache-Control:          max-age=0, must-revalidate, privateContent-Type:           text/html; charset=UTF-8Date:                   Fri, 03 Feb 2023 10:53:03 GMTExpires:                Fri, 03 Feb 2023 10:53:03 GMTX-Debug-Exception:X-Debug-Exception-File: ...X-Robots-Tag:           noindex/home/user/project/vendor/symfony/framework-bundle/Test/BrowserKitAssertionsTrait.php:142/home/user/project/vendor/symfony/framework-bundle/Test/BrowserKitAssertionsTrait.php:33/home/user/project/tests/Controller/AppControllerTest.php:35```</details>I added a method `Symfony\Component\HttpFoundation\Response::getCommandString()` that builds the first line of an HTTP response to avoid code duplication in constraints classes.I thought of other solutions:  +  Build the HTTP command line in each `Constraint`. This seems that too much code duplication.  + Add an `AbstractResponseConstraint` with a utility method to build a less verbose response string. I wasn't sure we needed to add an extend layer here.  + Add a `ResponseConstraintTrait` with an exposed method to build the less verbose response string. This did not *feel* right.Overall, I think the `Response` class is the more appropriate to build this string.I also had some issue with psalm complaining about the documented $response argument type of `additionalFailureDescription`:```ERROR: MoreSpecificImplementedParamType - src/Symfony/Component/HttpFoundation/Test/Constraint/ResponseStatusCodeSame.php:50:53 - Argument 1 of Symfony\Component\HttpFoundation\Test\Constraint\ResponseStatusCodeSame::additionalFailureDescription has the more specific type 'Symfony\Component\HttpFoundation\Response', expecting 'mixed' as defined by PHPUnit\Framework\Constraint\Constraint::additionalFailureDescription (seehttps://psalm.dev/140)    protected function additionalFailureDescription($other): string```I needed to delete the phpdoc comment to comply with this. I only changed the lines were Psalm was giving me errors, but there are still some mismatch between HttpFoundation constraints signatures and PHPUnit ones.Commits-------cabb2dc [FrameworkBundle][HttpFoundation] reduce response constraints verbosity
@wouterjwouterj removed the Waiting Code MergeDocs for features pending to be merged labelDec 7, 2024
@wouterjwouterj modified the milestones:next,7.1Dec 7, 2024
@wouterjwouterj changed the base branch from6.3 to7.1December 7, 2024 13:13
@wouterjwouterjforce-pushed the42948_reduce_response_contraints_verbosity branch from90fe916 tod159a4aCompareDecember 7, 2024 13:13
@wouterj
Copy link
Member

Thank you very much for updating the documentation along with your code changes, Nicolas! As your code PR has been merged in 7.1, I've merged this documentation as well.

@wouterjwouterj merged commitb1c97e7 intosymfony:7.1Dec 7, 2024
2 of 3 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@xabbuhxabbuhAwaiting requested review from xabbuh

Assignees
No one assigned
Projects
None yet
Milestone
7.1
Development

Successfully merging this pull request may close these issues.

4 participants
@Nicals@wouterj@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp