orchestral / testbench-core

Testing Helper for Laravel Development
https://github.com/orchestral/testbench
MIT License
259 stars 41 forks source link

[9.x] Reset refresh database state between tests #198

Closed crynobone closed 7 months ago

coveralls commented 7 months ago

Coverage Status

coverage: 92.414% (+0.01%) from 92.402% when pulling 3a575f75b4cf97f957974df3e18f9bc122af1af5 on 9/reset-refresh-database-state-between-tests into c86b66e16b3313b12c13575ed3b4cfedcb57e950 on 9.x.

brunogaspar commented 7 months ago

@crynobone Hello 👋

Sadly, this has caused a regression, at least on my end. I'm also aware this logic was moved to the InteractsWithTestCase trait.

I've been using the RefreshDatabase trait for quite some time, even after Laravel 11 upgrade, but after this change, the trait still works, but the migrations are executed before each test, which seems unwanted (at least from my point of view), which in turn makes the tests slow as the more migrations you have, the slow it will be 😞

Do i need to change something on my end?

Thank you!!

crynobone commented 7 months ago

This PR only available for Testbench Core 6 and was done for forward compatibility up until 9.

crynobone commented 7 months ago

See https://github.com/orchestral/testbench-core/commit/89305293c60c0f828fc4f396c16d9d65184b590c

crynobone commented 7 months ago

Oh yeah, my mistake. There are two RefreshDatabase usages in Testbench.

  1. Consistent migrations per test case.
  2. Ad-hoc migrations between tests in test cases.

While Laravel application mostly uses structure 1, Package developers have been known to use structure 2, which led to the above changes. We will need to rethink this

brunogaspar commented 7 months ago

No problem.

I'm pretty much on structure 1 but on a package, testing against a MySQL database not a in memory one (i know it's a bit unconventional).

I have for now implemented a workaround so it does not use the RefreshDatabaseState::$migrated

Let me know if there's anything i can help to address it.

crynobone commented 7 months ago

I'm pretty much on structure 1 but on a package, testing against a MySQL database not a in memory one (i know it's a bit unconventional).

RefreshDatabase in Laravel 11 for :in-memory: was changed to work similarly to a persistent database which prompted these changes (tests will break with structure 2).

crynobone commented 7 months ago

@brunogaspar can you test the latest patch release and see if that fixed your issue.

brunogaspar commented 7 months ago

@crynobone Yes, that seemed to have fixed it.

Thank you!!