Skip to content

Commit 85bcf35

Browse files
Merge pull request #1433 from liberu-genealogy/copilot/fix-phpunit-tests-and-docker
Fix PHPUnit test suite: schema mismatches, vendor model shadowing, factory bugs, and routing conflicts
2 parents b6fb370 + aa6b568 commit 85bcf35

22 files changed

+358
-354
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/storage/*.key
77
/storage/pail
88
/vendor
9-
/vendor-local
9+
!/vendor-local/laravel-gramps-xml
1010
.env
1111
.env.backup
1212
.env.production

app/Filament/Resources/GedcomResource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public static function exportGedcom()
1212
{
1313
$user = Auth::user();
1414
if ($user) {
15-
Queue::push(new ExportGedCom($user));
15+
$file = 'gedcom_export_' . $user->id . '_' . now()->format('YmdHis') . '.ged';
16+
Queue::push(new ExportGedCom($file, $user));
1617
}
1718
}
1819
}

app/Jobs/ExportGedCom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class ExportGedCom implements ShouldQueue
2323

2424
public function __construct(
2525
private readonly string $file,
26-
private readonly User $user,
26+
public readonly User $user,
2727
) {}
2828

2929
public function handle(): void

app/Models/Family.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,42 @@
55
use App\Traits\BelongsToTenant;
66
use Illuminate\Database\Eloquent\Factories\HasFactory;
77
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
use Illuminate\Database\Eloquent\Relations\HasOne;
89

910
class Family extends \FamilyTree365\LaravelGedcom\Models\Family
1011
{
1112
use HasFactory;
1213
use BelongsToTenant;
1314

15+
/**
16+
* Unset the parent's public property declarations that shadow Eloquent's
17+
* dynamic attribute/relationship system. Once unset on the instance,
18+
* PHP falls through to __get(), which Eloquent uses to resolve attributes
19+
* and relationships from $this->attributes / $this->relations.
20+
*/
21+
public function __construct(array $attributes = [])
22+
{
23+
// Unset inherited public properties that would shadow __get()
24+
unset($this->id, $this->husband, $this->wife);
25+
parent::__construct($attributes);
26+
}
27+
28+
/**
29+
* Override the vendor's husband relationship to use App\Models\Person (persons table).
30+
*/
31+
public function husband(): HasOne
32+
{
33+
return $this->hasOne(Person::class, 'id', 'husband_id');
34+
}
35+
36+
/**
37+
* Override the vendor's wife relationship to use App\Models\Person (persons table).
38+
*/
39+
public function wife(): HasOne
40+
{
41+
return $this->hasOne(Person::class, 'id', 'wife_id');
42+
}
43+
1444
public function user(): BelongsTo
1545
{
1646
return $this->belongsTo(User::class, 'user_id', 'id');

app/Modules/Tree/Services/TreeBuilderService.php

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,20 @@ public function buildAncestorTree(Person $person, int $generations): array
5151
$family = $person->childInFamily;
5252

5353
if ($family) {
54-
if ($family->husband) {
54+
$husband = $family->husband()->first();
55+
$wife = $family->wife()->first();
56+
57+
if ($husband) {
5558
$ancestors['father'] = [
56-
'person' => $this->formatPersonNode($family->husband),
57-
'ancestors' => $this->buildAncestorTree($family->husband, $generations - 1),
59+
'person' => $this->formatPersonNode($husband),
60+
'ancestors' => $this->buildAncestorTree($husband, $generations - 1),
5861
];
5962
}
6063

61-
if ($family->wife) {
64+
if ($wife) {
6265
$ancestors['mother'] = [
63-
'person' => $this->formatPersonNode($family->wife),
64-
'ancestors' => $this->buildAncestorTree($family->wife, $generations - 1),
66+
'person' => $this->formatPersonNode($wife),
67+
'ancestors' => $this->buildAncestorTree($wife, $generations - 1),
6568
];
6669
}
6770
}
@@ -93,10 +96,12 @@ public function buildDescendantTree(Person $person, int $generations): array
9396
];
9497

9598
// Add spouse information
96-
if ($person->sex === 'M' && $family->wife) {
97-
$familyNode['spouse'] = $this->formatPersonNode($family->wife);
98-
} elseif ($person->sex === 'F' && $family->husband) {
99-
$familyNode['spouse'] = $this->formatPersonNode($family->husband);
99+
$wife = $family->wife()->first();
100+
$husband = $family->husband()->first();
101+
if ($person->sex === 'M' && $wife) {
102+
$familyNode['spouse'] = $this->formatPersonNode($wife);
103+
} elseif ($person->sex === 'F' && $husband) {
104+
$familyNode['spouse'] = $this->formatPersonNode($husband);
100105
}
101106

102107
// Add children
@@ -145,18 +150,20 @@ protected function buildPedigreeData(Person $person, int $maxGenerations, int $c
145150
$family = $person->childInFamily;
146151
if ($family) {
147152
$data['parents'] = [];
153+
$husband = $family->husband()->first();
154+
$wife = $family->wife()->first();
148155

149-
if ($family->husband) {
156+
if ($husband) {
150157
$data['parents']['father'] = $this->buildPedigreeData(
151-
$family->husband,
158+
$husband,
152159
$maxGenerations,
153160
$currentGeneration + 1
154161
);
155162
}
156163

157-
if ($family->wife) {
164+
if ($wife) {
158165
$data['parents']['mother'] = $this->buildPedigreeData(
159-
$family->wife,
166+
$wife,
160167
$maxGenerations,
161168
$currentGeneration + 1
162169
);
@@ -206,10 +213,12 @@ protected function buildDescendantData(Person $person, int $maxGenerations, int
206213
];
207214

208215
// Add spouse
209-
if ($person->sex === 'M' && $family->wife) {
210-
$familyData['spouse'] = $this->formatPersonNode($family->wife);
211-
} elseif ($person->sex === 'F' && $family->husband) {
212-
$familyData['spouse'] = $this->formatPersonNode($family->husband);
216+
$wife = $family->wife()->first();
217+
$husband = $family->husband()->first();
218+
if ($person->sex === 'M' && $wife) {
219+
$familyData['spouse'] = $this->formatPersonNode($wife);
220+
} elseif ($person->sex === 'F' && $husband) {
221+
$familyData['spouse'] = $this->formatPersonNode($husband);
213222
}
214223

215224
// Add children
@@ -332,14 +341,17 @@ protected function collectAncestors(Person $person, Collection $ancestors, int $
332341

333342
$family = $person->childInFamily;
334343
if ($family) {
335-
if ($family->husband && !$ancestors->contains('id', $family->husband->id)) {
336-
$ancestors->push($family->husband);
337-
$this->collectAncestors($family->husband, $ancestors, $remainingGenerations - 1);
344+
$husband = $family->husband()->first();
345+
$wife = $family->wife()->first();
346+
347+
if ($husband && !$ancestors->contains('id', $husband->id)) {
348+
$ancestors->push($husband);
349+
$this->collectAncestors($husband, $ancestors, $remainingGenerations - 1);
338350
}
339351

340-
if ($family->wife && !$ancestors->contains('id', $family->wife->id)) {
341-
$ancestors->push($family->wife);
342-
$this->collectAncestors($family->wife, $ancestors, $remainingGenerations - 1);
352+
if ($wife && !$ancestors->contains('id', $wife->id)) {
353+
$ancestors->push($wife);
354+
$this->collectAncestors($wife, $ancestors, $remainingGenerations - 1);
343355
}
344356
}
345357
}

composer.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"license": "MIT",
1111
"require": {
12-
"php": "^8.5",
12+
"php": "^8.3",
1313
"bezhansalleh/filament-shield": "^4.0",
1414
"filament/filament": "^5.1",
1515
"filament/spatie-laravel-settings-plugin": "^5.0",
@@ -27,16 +27,12 @@
2727
"spatie/laravel-permission": "*"
2828
},
2929
"require-dev": {
30-
"driftingly/rector-laravel": "^2.0",
3130
"fakerphp/faker": "^1.23",
32-
"filament/upgrade": "~5.1",
33-
"laravel/pail": "^1.2.2",
3431
"laravel/pint": "^1.13",
3532
"laravel/sail": "^1.41",
3633
"mockery/mockery": "^1.6",
3734
"nunomaduro/collision": "^8.6",
38-
"phpunit/phpunit": "^12.1.5",
39-
"rector/rector": "*"
35+
"phpunit/phpunit": "^12.1.5"
4036
},
4137
"autoload": {
4238
"psr-4": {
@@ -99,4 +95,4 @@
9995
}
10096
}
10197
]
102-
}
98+
}

0 commit comments

Comments
 (0)