Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DomCrawler][FrameworkBundle] Add assertSelectorCount #48424

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 1 commit into from
Dec 9, 2022

Conversation

curlycarla2004
Copy link
Contributor

@curlycarla2004 curlycarla2004 commented Dec 1, 2022

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets ~
License MIT
Doc PR todo?

I was using the following test in my application:

// ...
class UserControllerTest extends WebTestCase
{
    public function testShow(): void
    {
        // ....

        $crawler = $client->request(Request::METHOD_GET, '/user/show/'.$user->getId());

        self::assertResponseStatusCodeSame(Response::HTTP_OK);
        self::assertRouteSame('app_user_show');
        self::assertPageTitleSame('User information');
        // Only the following assertion requires the crawler
        self::assertCount(3, $crawler->filter('p'), 'There should be 3 p selectors on this page');
        self::assertSelectorTextContains('p', '[email protected]');
    }
}

After this PR:

-$crawler = $client->request(Request::METHOD_GET, '/user/show/'.$user->getId());
+$client->request(Request::METHOD_GET, '/user/show/'.$user->getId());

 self::assertResponseStatusCodeSame(Response::HTTP_OK);
 self::assertRouteSame('app_user_show');
 self::assertPageTitleSame('User information');
-self::assertCount(3, $crawler->filter('p'), 'There should be 3 p selectors on this page');
+self::assertSelectorCount(3, 'p', 'There should be 3 p selectors on this page');
 self::assertSelectorTextContains('p', '[email protected]');

What do you think about this?

@carsonbot carsonbot added this to the 6.3 milestone Dec 1, 2022
@carsonbot carsonbot changed the title [DomCrawler] [FrameworkBundle] Add selector count assertion [DomCrawler][FrameworkBundle] Add selector count assertion Dec 1, 2022
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.3 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@OskarStark OskarStark changed the title [DomCrawler][FrameworkBundle] Add selector count assertion [DomCrawler][FrameworkBundle] Add assertSelectorCount Dec 1, 2022
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

thanks for proposing!

@curlycarla2004
Copy link
Contributor Author

Thank you for your reviews. I have updated my code and PR description.

@curlycarla2004
Copy link
Contributor Author

Thanks for approving! and thanks to @HeahDude for helping with my first contribution!!!

@nicolas-grekas
Copy link
Member

deps=low failure is related. FrameworkBundle should bump the minimum version of DomCrawler in its composer.json file.

@curlycarla2004 curlycarla2004 force-pushed the creating-assert-selector-count branch from 40778c4 to a257da8 Compare December 5, 2022 08:12
@curlycarla2004
Copy link
Contributor Author

curlycarla2004 commented Dec 5, 2022

ok so i have corrected the problem with low deps(and some extra white spaces).

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

Thanks for contributing this new method. It will be useful for many!

And congrats on a superb first contribution 🎉

@fabpot fabpot force-pushed the creating-assert-selector-count branch from ab7e024 to 1d56613 Compare December 9, 2022 07:28
@fabpot
Copy link
Member

fabpot commented Dec 9, 2022

Thank you @curlycarla2004.

@fabpot fabpot merged commit 9ef729e into symfony:6.3 Dec 9, 2022
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.

6 participants