Skip to content

Fixes and improvements to tests - #1258

Draft
outdooracorn wants to merge 9 commits into
ollie-restore-database-migrationsfrom
ollie-fixes-and-improvements
Draft

outdooracorn wants to merge 9 commits into
ollie-restore-database-migrationsfrom
ollie-fixes-and-improvements

Conversation

@outdooracorn

Copy link
Copy Markdown
Member

No description provided.

@outdooracorn outdooracorn self-assigned this Sep 21, 2026
@outdooracorn
outdooracorn added this pull request to stack #1259 September 21, 2026 03:50
@outdooracorn
outdooracorn marked this pull request as draft October 8, 2026 14:56
@outdooracorn
outdooracorn force-pushed the ollie-fixes-and-improvements branch from 83ed93d to 4ea19a9 Compare October 8, 2026 14:59
* Make the `verified` attribute defualt to `true`, as that is what is used everywhere
* Remove `'verified' => true` from all references of `User::factory()`
* Add an `unverified()` method for easily setting `verified` to `false
* Add an `admin` method for easily setting `is_admin` to `1`
* Add type declarations to method parameters and return values
Use the `DatabaseTransactions` trait to keep the tests from poluting the database rather than manually removing *all* `Wiki`s and `WikiDb`s from the database in the `tearDown()` method.

`Wiki::query()->delete();` doesn't even clean the database properly as `Wiki`s are soft-deleted. The `->forceDelete()` method should have been used.
Quick fix to prevent the test from polluting the database with a soft-deleted `Wiki`. This test, and the `PlatformStatsSummaryJob` it is testing, should be improved so that wiping the whole database after each test isn't required.
Add `DatabaseTransactions` trait to `LogoUpdateTest` to prevent it from polluting the database
* Add the `DatabaseTransactions` trait to prevent it from polluting the database
* Remove the `setUp()` method as this test shouldn't be responsible for cleaning up after other tests
* Remove the `tearDown()` method as the database  isn't polluted when the `DatabaseTransactions` trait is used
* Fix tests creating `Wiki`s with invalid `user_id` of `0`
* Remove the `setUp()` method as `DeletedWikiMetricsControllerTest` shouldn't be responsible for cleaning up after other tests
* Remove the `tearDown()` method as `DeletedWikiMetricsControllerTest` doesn't pollute the database
* Simplify signature and implementation of `createAndDeleteTestWiki()` to remove functionality not used by the test
* Make use of `User::factory()` rather than reimplementing logic in the TestCase
* Replace `private function createUserWithPrivileges()` with the `UserFactory::admin()` method
* Refactor out the requests to `auth/login` by using `->actingAs()` on the requests under test
* Rely on the `Wiki::factory()` to set the `sitename` attribute
* Add type declarations to method parameters and return values
* Inline variables that are only used once
* Rename test methods for clarity
@outdooracorn
outdooracorn force-pushed the ollie-fixes-and-improvements branch from 4ea19a9 to e6f0bf4 Compare October 8, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant