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

Allow testing with fake data Sushi::test() #33

Closed

Conversation

shadoWalker89
Copy link
Contributor

@shadoWalker89 shadoWalker89 commented Feb 4, 2020

EDIT:

This PR branch has been rebased on the master to make merging easier.
The original commit is here e6d61c1


Original message

This PR allows to use a set of fake data during tests.

SomeModel::test([
    ['name' => 'foo'],
    ['name' => 'bar']
])

It will change the sushi connection to :memory and migrate it with the test rows.

Why use fake data

Caleb already approved the idea of fetching rows via the getRows().
I'm using sushi in app that i'm currently building, and i'm using the getRows() (i implemented that locally until this PR (#31) is merged) to read data from an ini file. Since the data is not static (defined in the model) i would like to decouple my test from any ini file and use some fake data in my tests.

This can be merged now if caleb is open for adding test test() method.
Also if caleb wants to hold off until this #31 is merged, then leave it open and i will update it once #31 is merged.

@shadoWalker89 shadoWalker89 force-pushed the add_test_ability branch 2 times, most recently from e6d61c1 to 60336ce Compare February 8, 2020 14:41
@calebporzio
Copy link
Owner

Sorry for taking forever to get back to this.

This use case makes sense to me.

Only note on it:

Because it relies on a static property, if you set Something::test() in one test method and then use Something in another test method, will the model still be populated with test data? I'm fuzzy with static property persistence between tests - just looking for clarification.

@stevebauman
Copy link

stevebauman commented Mar 25, 2021

@calebporzio

Because it relies on a static property, if you set Something::test() in one test method and then use Something in another test method, will the model still be populated with test data?

Yup you're right -- it will stay populated between each test, which is a problem.

We'll likely need to hook into the Model::clearBootedModels() method to tear-down/clear the test row data automatically. This method should be called every time a Laravel Test Case is executed, since it will tear down the service providers and bring them back up (called in the Laravel DatabaseServiceProvider::register() method).

@shadoWalker89 Are you able to update to update your tests with this scenario in mind (i.e. user setting test rows doesn't affect another tests results)?

@calebporzio
Copy link
Owner

Closing because inactivity.

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