Skip to content

Commit

Permalink
test: Add test whether ambiguous columns are mapped correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Oct 20, 2023
1 parent ed6d937 commit 2dca11b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/Audit.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ public function getColumns()
return [
'user_id',
'activity',
'subsystem_id'
];
}

public function createRelations(Relations $relations)
{
$relations->hasOne('user', User::class);
$relations->belongsToOne('subsystem', Subsystem::class);
}
}
25 changes: 25 additions & 0 deletions tests/HydratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace ipl\Tests\Orm;

use ipl\Tests\Sql\TestCase;

class HydratorTest extends TestCase
{
public function testWhetherAmbiguousColumnsAreCorrectlyMapped(): void
{
$query = Subsystem::on(new TestConnection())
->with(['audit', 'audit.user']);

$hydrator = $query->createHydrator();

$subject = new Subsystem();
$hydrator->hydrate(['subsystem_audit_user_id' => 2], $subject);

$this->assertTrue(isset($subject->audit->user_id), 'Ambiguous columns are not mapped correctly');
$this->assertSame($subject->audit->user_id, 2, 'Ambiguous columns are not mapped correctly');

$this->assertTrue(isset($subject->audit->user->id), 'Ambiguous columns are not mapped correctly');
$this->assertSame($subject->audit->user->id, 2, 'Ambiguous columns are not mapped correctly');
}
}
29 changes: 29 additions & 0 deletions tests/Subsystem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace ipl\Tests\Orm;

use ipl\Orm\Model;
use ipl\Orm\Relations;

class Subsystem extends Model
{
public function getTableName()
{
return 'subsystem';
}

public function getKeyName()
{
return 'id';
}

public function getColumns()
{
return ['name'];
}

public function createRelations(Relations $relations)
{
$relations->hasMany('audit', Audit::class);
}
}

0 comments on commit 2dca11b

Please sign in to comment.