Paket 1: eine aktive Angebotsfassung und Bestellbezeichnung
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8cd382c357
commit
7820bececb
13 files changed
+529
-25
No files matched your search
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Catalog\ArticleService;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Domain\Catalog\LicenseArticle;
|
||||
use App\Domain\Catalog\Offer;
|
||||
use App\Domain\Catalog\OfferService;
|
||||
use App\Domain\Catalog\OfferStatus;
|
||||
use App\Domain\Catalog\OfferVersion;
|
||||
use App\Domain\Catalog\RightsProfileVersion;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
class OfferActivationParallelTest extends TestCase
|
||||
{
|
||||
private ?string $databasePath = null;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->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];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user