the browser-facing portion of osu!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add class based factory for Changelog

nanaya 4d9b1f2a bef55426

+24 -28
+19 -23
database/factories/ChangelogFactory.php
··· 3 3 // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4 4 // See the LICENCE file in the repository root for full licence text. 5 5 6 - /* 7 - |-------------------------------------------------------------------------- 8 - | Model Factories 9 - |-------------------------------------------------------------------------- 10 - | 11 - | Here you may define all of your model factories. Model factories give 12 - | you a convenient way to create models for testing and seeding your 13 - | database. Just tell the factory how a default model should look. 14 - | 15 - */ 6 + declare(strict_types=1); 7 + 8 + namespace Database\Factories; 16 9 10 + use App\Models\Changelog; 17 11 use App\Models\User; 18 12 19 - $factory->define(App\Models\Changelog::class, function (Faker\Generator $faker) { 20 - return [ 21 - 'user_id' => function () { 22 - $u = User::inRandomOrder()->first() ?? User::factory()->create(); 13 + class ChangelogFactory extends Factory 14 + { 15 + protected $model = Changelog::class; 23 16 24 - return $u->getKey(); 25 - }, 26 - 'prefix' => $faker->randomElement(['*', '+', '?']), 27 - 'category' => $faker->randomElement(['Web', 'Audio', 'Code', 'Editor', 'Gameplay', 'Graphics']), 28 - 'message' => $faker->catchPhrase, 29 - 'checksum' => $faker->md5, 30 - 'date' => $faker->dateTimeBetween('-6 weeks', 'now'), 31 - ]; 32 - }); 17 + public function definition(): array 18 + { 19 + return [ 20 + 'user_id' => User::factory(), 21 + 'prefix' => fn() => $this->faker->randomElement(['*', '+', '?']), 22 + 'category' => fn() => $this->faker->randomElement(['Web', 'Audio', 'Code', 'Editor', 'Gameplay', 'Graphics']), 23 + 'message' => fn() => $this->faker->catchPhrase(), 24 + 'checksum' => fn() => $this->faker->md5, 25 + 'date' => fn() => $this->faker->dateTimeBetween('-6 weeks'), 26 + ]; 27 + } 28 + }
+3 -3
database/seeders/ModelSeeders/ChangelogSeeder.php
··· 37 37 ->merge(Build::factory()->count(5)->create(['stream_id' => $fallback->stream_id])); 38 38 39 39 foreach ($builds as $build) { 40 - factory(Changelog::class, 5)->create([ 40 + Changelog::factory()->count(5)->create([ 41 41 'build' => $build->version, 42 42 'stream_id' => $build->stream_id, 43 43 ]); 44 44 } 45 45 46 46 // create some buildless changes 47 - factory(Changelog::class, 15)->create([ 47 + Changelog::factory()->count(15)->create([ 48 48 'build' => null, 49 49 'stream_id' => 5, 50 50 ]); 51 51 52 - factory(Changelog::class, 5)->create([ 52 + Changelog::factory()->count(5)->create([ 53 53 'build' => null, 54 54 'stream_id' => 1, 55 55 ]);
+1 -1
tests/Browser/SanityTest.php
··· 221 221 222 222 // factory for /home/changelog/* 223 223 self::$scaffolding['stream'] = factory(UpdateStream::class)->create(); 224 - self::$scaffolding['changelog'] = factory(Changelog::class)->create([ 224 + self::$scaffolding['changelog'] = Changelog::factory()->create([ 225 225 'stream_id' => self::$scaffolding['stream']->stream_id, 226 226 ]); 227 227 self::$scaffolding['build'] = Build::factory()->create([
+1 -1
tests/Middleware/RouteScopesTest.php
··· 45 45 'stream_id' => 1, // Changelog stream_id is tinyint, autoincrement makes test fail too soon. 46 46 ]); 47 47 48 - factory(Changelog::class)->create([ 48 + Changelog::factory()->create([ 49 49 'stream_id' => $stream->getKey(), 50 50 'user_id' => 1, // user doesn't need to exist and not having to create a user makes the test much faster 51 51 ]);