8c70255d2b
Закрывает 4 Important issues из code-review Task 3 (6d6181b):
- config/database.php: inline 11-key duplication заменён на single-source
pattern через локальную переменную $pgsqlConnection (config() внутри
config-файла не работает — Repository ещё не bootstrap'нут); 'pgsql' и
'pgsql_supplier' теперь оба ссылаются на $pgsqlConnection; PDO options
block с string-key _role_purpose удалён (PDO ждёт integer ATTR_* keys)
- tests/Concerns/SharesSupplierPdo.php (новый): trait для cross-connection
PDO visibility в DatabaseTransactions; setUp override из TestCase.php
удалён (был global на 562 теста, forced eager PDO connect);
trait применён к 5 supplier-flow тестам: SupplierConnectionTest,
LeadRouterTest, RouteSupplierLeadJobTest, ResetDeliveredTodayCommandTest,
SupplierLeadFlowTest (все нуждаются в cross-connection видимости)
- phpstan-baseline.neon: entry для Pest TestCall->artisan() в
SupplierConnectionTest заменён на inline @phpstan-ignore-next-line
— local + self-documenting; добавлен baseline-entry для
SharesSupplierPdo trait.unused (PHPStan не видит Pest uses() как trait usage)
Plus 3 Minor:
- typos 'dafault'/'corretly' (удалились с setUp override из TestCase.php)
- RouteSupplierLeadJob.php PHPDoc: \$connection → DB_CONNECTION консистентность
Pest: 562 tests, 560 passed + 2 skipped (без regression). PHPStan: 0 errors. Pint: clean.
46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\Project;
|
|
use App\Models\Tenant;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Tests\Concerns\SharesSupplierPdo;
|
|
|
|
uses(DatabaseTransactions::class);
|
|
uses(SharesSupplierPdo::class);
|
|
|
|
beforeEach(function () {
|
|
DB::statement("SELECT set_config('app.current_tenant_id', '0', true)");
|
|
});
|
|
|
|
test('resets delivered_today to 0 across all tenants', function () {
|
|
$t1 = Tenant::factory()->create();
|
|
$t2 = Tenant::factory()->create();
|
|
|
|
Project::factory()->create(['tenant_id' => $t1->id, 'delivered_today' => 5]);
|
|
Project::factory()->create(['tenant_id' => $t1->id, 'delivered_today' => 3]);
|
|
Project::factory()->create(['tenant_id' => $t2->id, 'delivered_today' => 10]);
|
|
|
|
$this->artisan('projects:reset-delivered-today')->assertSuccessful();
|
|
|
|
$row = DB::selectOne('SELECT COUNT(*) FILTER (WHERE delivered_today = 0) AS c, COUNT(*) AS total FROM projects');
|
|
expect($row->c)->toBe($row->total);
|
|
});
|
|
|
|
test('does not touch delivered_in_month', function () {
|
|
$t = Tenant::factory()->create();
|
|
Project::factory()->create([
|
|
'tenant_id' => $t->id,
|
|
'delivered_today' => 5,
|
|
'delivered_in_month' => 50,
|
|
]);
|
|
|
|
$this->artisan('projects:reset-delivered-today')->assertSuccessful();
|
|
|
|
$row = DB::selectOne('SELECT delivered_today, delivered_in_month FROM projects ORDER BY id DESC LIMIT 1');
|
|
expect((int) $row->delivered_today)->toBe(0);
|
|
expect((int) $row->delivered_in_month)->toBe(50);
|
|
});
|