Closed SychO9 closed 2 months ago
Do we need / want to "simplify" the existing sample data in tests?
We don't need to, though it would be nice, will either do that incrementally or in a swoop in one PR. I'll merge this for now though since I need it for the database drivers branch (sqlite + pgsql)
Please ignore the failing PHPStan and Frontend tests, those have been fixed in other PRs that are still open
Changes proposed in this pull request: This PR introduces some eloquent factories for some models. The primary reason for introducing this is the following use case within tests:
We have a very large number of tests, in most tests we declare the data we need in the database like so:
We set `comment_count' to 1 almost always rather than not, so that we are certain the discussions are visible. The problem is that when you introduce a new column that requires you to similarly always give it a value, you have to go through all the data in all the tests and make changes accordingly.. Which is very inconvenient.
By introducing factories, each model has a default template of fake data that can be edited, and the data specified in the tests is passed to the model factory to generate the final data.
So with this PR, it becomes as follows:
To implement a factory class, the model must use the
HasFactory
trait, and the factory class which extendsIlluminate\Database\Eloquent\Factories\Factory
can exist in the same namespace as the model class. Otherwise the model may specify the class of the factory through the staticnewFactory
method.More on factories here: https://laravel.com/docs/10.x/eloquent-factories.
Additionally, factories are useful for other features the ecosystem may build (an example can involve a previewing feature of sorts).
Reviewers should focus on:
Screenshot
QA
Necessity
Confirmed
composer test
).Required changes: