Repository navigation
feat(upgrade): give each model a factory, written from its migrations - #60
Merged
Merged
Conversation
Flarum 2.0 tests fill the columns a test leaves out from a model's factory, when prepareDatabase() is given the model class rather than its table. - A new upgrade step writes a factory next to each of the extension's models, from what its migrations say about the model's table, and gives the model HasFactory. A factory the extension already has is kept. - The PHPUnit step names the extension's own tables, and api_keys, by their models in prepareDatabase(). - fl make backend model generates the factory with the model.
The PHPUnit 12 rewrite in #58 wrote attributes in the order the annotations were written, so a test with @dataProvider above @test got #[DataProvider] above #[Test]. The original rewriter put #[Test] first, as Flarum's own tests have it. Found by running both versions over the 1.x tests of 36 FoF extensions and core.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: no issue.
Changes proposed in this pull request:
Flarum 2.0 tests fill the columns a test leaves out from a model's factory, when
prepareDatabase()is given the model class rather than its table. Until now the upgrade only linked to the docs. A new step, "Model factories for tests" (run before the PHPUnit step), writes a factory next to each of the extension's models and gives the modelHasFactory. A factory the extension already has is kept.Each factory is written from what the extension's migrations say about the model's table, replayed in the order Flarum runs them. It follows core's factories:
created_atisCarbon::now(), a required foreign key isModel::factory(), nullable columns arenull, and strings get a faker value. A column it can't fill gets a@TODO.The PHPUnit step now names the extension's own tables, and
api_keys, by their models inprepareDatabase().fl make backend modelgenerates the factory alongside the model.It also fixes a regression from #58: converted tests got
#[DataProvider]above#[Test]when@dataProviderwas written first.#[Test]comes first again, as in the original rewriter and Flarum's own tests. I found it by running the original and current rewriters over 364 real test files (the 1.x tests of 36 FoF extensions and core); the other differences are intended: stray empty*doc lines go, andapi_keysbecomesApiKey::class.Reviewers should focus on:
change()is read as Laravel 11+ does: it replaces the column, so a column not restated as nullable gets a value. Flags' 1.xreason_detailis the real case; 2.x restated->nullable()there.1.xmigrations, the built CLI wrote factories with the same columns as the hand-written 2.xFlagFactoryandTagFactory, plus Tags' three 1.x-only columns. On Tags' 1.x tests, every model table becameModel::class; only pivot tables without a model stayed as table names. The reader ran without error over 68 extensions' migrations (bundled 1.x and installed third-party).$tabletakes the table Eloquent names after it (pluralSnakeCaseModel). Subclasses of core models, such as post types, share core's table and factory, so they are skipped.Screenshot
N/A
Necessity
Confirmed
fl make backend modelon a fixture extension.)yarn testinjs/). (yarn test: 267 tests, plus Prettier, ESLint andtsc.)composer test). (N/A)Required changes:
None.