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

Migrate BrowserKit tests to HTTP tests #984

Merged
merged 18 commits into from
Mar 12, 2024

Conversation

fabiorodriguesroque
Copy link
Contributor

@fabiorodriguesroque fabiorodriguesroque commented Dec 28, 2023

Tests to migrate

  • AdminTest
  • ArticleTest
  • AuthTest
  • BlockUsersTest
  • CanonicalUrlTest
  • ForumTest
  • HomeTest
  • ModeratorTest
  • NavigationTest
  • NotificationsTest
  • ProfileTest
  • ReplyTest
  • SettingsTest
  • SubscriptionsTest

@fabiorodriguesroque fabiorodriguesroque marked this pull request as draft December 28, 2023 23:36
@fabiorodriguesroque fabiorodriguesroque changed the title draft: Migrate BrowserKit tests to HTTP tests Migrate BrowserKit tests to HTTP tests Dec 28, 2023
@fabiorodriguesroque
Copy link
Contributor Author

@joedixon could you make a quick review on the AdminTest migration before I start migrate all other test cases?

Basically I've updated

  1. assertRedirectedTo() to ->assertRedirectToRoute($name, $parameters = []);
  2. seeInDatabase to assertDatabaseHas
  3. notSeeInDatabase to assertDatabaseMissing
  4. see to assertSee
  5. dontSee to assertDontSee

About the first point would you prefer use assertRedirectTo($uri) instead of assertRedirectToRoute?

Thanks.

@joedixon
Copy link
Contributor

Great work @fabiorodriguesroque, thank you!

All looks good to me. I don't think I'm particularly bothered if you use assertRedirectTo vs assertRedirectToRoute. In an ideal world, we'd probably use the route name since we have them configured in the routes file, but in reality, I don't think they have ever changed and it's actually nice, in my opinion, if the tests catch when they do.

@driesvints
Copy link
Member

@fabiorodriguesroque thanks a bunch for this! I agree with @joedixon and think assertRedirectTo is probably preferred.

@fabiorodriguesroque
Copy link
Contributor Author

Yes! I got your point, the AdminTest was already updated with the AssertRedirect() and I'll follow this for the next ones.

@fabiorodriguesroque
Copy link
Contributor Author

fabiorodriguesroque commented Jan 8, 2024

@driesvints @joedixon

I've updated almost all tests with exception of AuthTest, ForumTest and SettingsTest, where I think I need to use Laravel Dusk.

for example

test('users can register', function () {
    Notification::fake();

    session(['githubData' => ['id' => 123, 'username' => 'johndoe']]);

    $this->visit('/register')
        ->type('John Doe', 'name')
        ->type('john.doe@example.com', 'email')
        ->type('johndoe', 'username')
        ->check('rules')
        ->check('terms')
        ->press('Register')
        ->seePageIs('/user/johndoe')
        ->see('John Doe');

    assertLoggedIn();

    $this->assertSessionMissing('githubData');

    Notification::assertSentTo(Auth::user(), VerifyEmail::class);
});

Should I add the laravel/dusk dependency?? otherwise we can't migrate all use cases.

@driesvints
Copy link
Member

Wonder if we can migrate this one to just a HTTP test. I think we only need to migrate this part, yes?

        ->seePageIs('/user/johndoe')
        ->see('John Doe');

Skip the last part and migrate seePageIs to assertRedirectedTo or something?

@joedixon
Copy link
Contributor

joedixon commented Jan 9, 2024

Yes, I think an HTTP test is fine here too 👍

@fabiorodriguesroque
Copy link
Contributor Author

fabiorodriguesroque commented Jan 13, 2024

Wonder if we can migrate this one to just a HTTP test. I think we only need to migrate this part, yes?

        ->seePageIs('/user/johndoe')
        ->see('John Doe');

Skip the last part and migrate seePageIs to assertRedirectedTo or something?

yes, the only thing here is the functions like type() check() but I can use actingAs() and send a normal post or put request.

I've migrated the SettingsTest with actingAs($user) and updated the submitForms() to put() or post().

@joedixon
Copy link
Contributor

yes, the only thing here is the functions like type() check() but I can use actingAs() and send a normal post or put request.

I've migrated the SettingsTest with actingAs($user) and updated the submitForms() to put() or post().

This is exactly what I had in mind, thank you!

@driesvints
Copy link
Member

Hey @fabiorodriguesroque. Anything we can do to help get this PR over the finish line? We really appreciate this one! :)

@fabiorodriguesroque
Copy link
Contributor Author

fabiorodriguesroque commented Feb 14, 2024

Hey @fabiorodriguesroque. Anything we can do to help get this PR over the finish line? We really appreciate this one! :)

Yes @driesvints first of all sorry for not giving any news for a long time, but I'v been a little busy!
I'm with some difficulties with the ForumTest in two tests!

I will commit and open a review!
Thanks

@fabiorodriguesroque fabiorodriguesroque marked this pull request as ready for review March 6, 2024 21:39
Copy link
Contributor Author

@fabiorodriguesroque fabiorodriguesroque left a comment

Choose a reason for hiding this comment

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

resolved ✅

tests/Feature/ForumTest.php Outdated Show resolved Hide resolved
Copy link
Contributor

@joedixon joedixon left a comment

Choose a reason for hiding this comment

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

This is totally awesome @fabiorodriguesroque, thank you 🙌

@driesvints driesvints merged commit 012b6d6 into laravelio:main Mar 12, 2024
1 check passed
@driesvints
Copy link
Member

Amazing work @fabiorodriguesroque. Really appreciate this. Thanks!

@driesvints
Copy link
Member

Seems for some reason we did miss the SubscriptionsTest here. Not sure what went wrong and how tests could pass 🤔

@fabiorodriguesroque
Copy link
Contributor Author

Seems for some reason we did miss the SubscriptionsTest here. Not sure what went wrong and how tests could pass 🤔

Weird! I was to take a look on this, but noticed you already migrate that one and deleted the BrowserKitTestCase, my bad. Thanks.

@driesvints
Copy link
Member

Yeah just pushed it. No worries. The test suite should have caught this so no idea why it didn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants