|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Jobs; |
| 4 | + |
| 5 | +use App\Jobs\ProvisionWikiDbJob; |
| 6 | +use App\WikiDb; |
| 7 | +use Illuminate\Foundation\Testing\DatabaseTransactions; |
| 8 | +use Tests\TestCase; |
| 9 | + |
| 10 | +class ProvisionWikiDbJobTest extends TestCase { |
| 11 | + use DatabaseTransactions; |
| 12 | + |
| 13 | + private function createWikiDb($name, $version, $wikiId) { |
| 14 | + return WikiDb::create([ |
| 15 | + 'name' => $name, |
| 16 | + 'version' => $version, |
| 17 | + 'wiki_id' => $wikiId, |
| 18 | + ]); |
| 19 | + } |
| 20 | + |
| 21 | + public static function amountProvider() { |
| 22 | + yield 'run 1 time, max 0' => [ |
| 23 | + 0, |
| 24 | + 0, |
| 25 | + ]; |
| 26 | + |
| 27 | + yield 'run 1 time, max 1' => [ |
| 28 | + 1, |
| 29 | + 1, |
| 30 | + ]; |
| 31 | + |
| 32 | + yield 'run 2 time, max 1' => [ |
| 33 | + 2, |
| 34 | + 1, |
| 35 | + ]; |
| 36 | + |
| 37 | + yield 'run 2 time, max 2' => [ |
| 38 | + 2, |
| 39 | + 2, |
| 40 | + ]; |
| 41 | + |
| 42 | + yield 'run 10 time, max 10' => [ |
| 43 | + 10, |
| 44 | + 10, |
| 45 | + ]; |
| 46 | + |
| 47 | + yield 'run 10 time, max 1' => [ |
| 48 | + 10, |
| 49 | + 1, |
| 50 | + ]; |
| 51 | + |
| 52 | + yield 'run 20 time, max 10' => [ |
| 53 | + 20, |
| 54 | + 10, |
| 55 | + ]; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @dataProvider amountProvider |
| 60 | + */ |
| 61 | + public function testRun($times, $max) { |
| 62 | + $this->assertSame( |
| 63 | + 0, |
| 64 | + WikiDb::where('wiki_id', null)->count(), |
| 65 | + ); |
| 66 | + |
| 67 | + $manager = $this->app->make('db'); |
| 68 | + |
| 69 | + for ($i = 0; $i < $times; $i++) { |
| 70 | + $job = new ProvisionWikiDbJob(null, null, $max); |
| 71 | + $job->handle($manager); |
| 72 | + } |
| 73 | + |
| 74 | + $this->assertSame( |
| 75 | + $max, |
| 76 | + WikiDb::where('wiki_id', null)->count(), |
| 77 | + ); |
| 78 | + } |
| 79 | +} |
0 commit comments