databasePath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'luf_parallel_'.Str::uuid()->toString().'.sqlite'; touch($this->databasePath); config(['database.connections.sqlite.database' => $this->databasePath]); DB::purge('sqlite'); DB::reconnect('sqlite'); Artisan::call('migrate', ['--force' => true]); } protected function tearDown(): void { if ($this->databasePath !== null && is_file($this->databasePath)) { @unlink($this->databasePath); } config(['database.connections.sqlite.database' => ':memory:']); DB::purge('sqlite'); parent::tearDown(); } public function test_overlapping_activations_leave_exactly_one_active_version(): void { [$article, $rights, $offer] = $this->offerWithArticle(); $baseEnv = [ 'APP_ENV' => 'testing', 'APP_KEY' => config('app.key'), 'DB_CONNECTION' => 'sqlite', 'DB_DATABASE' => $this->databasePath, 'CACHE_STORE' => 'array', 'QUEUE_CONNECTION' => 'sync', 'SESSION_DRIVER' => 'array', ]; $worker = base_path('tests/Support/offer_activate_worker.php'); $results = Process::pool(function ($pool) use ($baseEnv, $worker, $offer, $article, $rights): void { $pool->as('a') ->path(base_path()) ->env($baseEnv) ->timeout(120) ->command([PHP_BINARY, $worker, $this->databasePath, (string) $offer->id, (string) $article->id, (string) $rights->id, '1000', '80']); $pool->as('b') ->path(base_path()) ->env($baseEnv) ->timeout(120) ->command([PHP_BINARY, $worker, $this->databasePath, (string) $offer->id, (string) $article->id, (string) $rights->id, '2000', '0']); })->start()->wait(); $this->assertTrue($results['a']->successful(), $results['a']->errorOutput()); $this->assertTrue($results['b']->successful(), $results['b']->errorOutput()); $active = OfferVersion::query()->where('offer_id', $offer->id)->where('status', OfferStatus::Aktiv)->get(); $this->assertCount(1, $active); $versions = OfferVersion::query()->where('offer_id', $offer->id)->orderBy('number')->get(); $this->assertCount(2, $versions); $this->assertSame(OfferStatus::Beendet, $versions->first()->status); $this->assertContains($versions->last()->price_cents, [1000, 2000]); $this->assertNotSame($versions->first()->price_cents, $versions->last()->price_cents); } /** * @return array{0: LicenseArticle, 1: RightsProfileVersion, 2: Offer} */ private function offerWithArticle(): array { $content = app(ContentService::class); $version = $content->publishElementVersion($content->createElement('text', 'text', 'Basis'), 'Basis'); $article = app(ArticleService::class)->publishRelease( app(ArticleService::class)->create('parallel-basis'), $version, 'Paralleltest.', )->article->fresh(); $rights = app(OfferService::class)->createRightsProfile('Lesen', 'ehrenamtlich', ['text' => ['ansehen']]); $offer = app(OfferService::class)->create('Parallelangebot'); return [$article, $rights, $offer]; } }