-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pkName::summarize to AuditTrait (#118)
* Add pkName to AuditTrait * Dummy Entity * add test * cs Co-authored-by: a.dmitryuk <[email protected]>
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DH\Auditor\Tests\Provider\Doctrine\Fixtures\Issue112; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="author") | ||
*/ | ||
#[ORM\Entity] | ||
#[ORM\Table(name: 'author')] | ||
class DummyEntity | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer", options={"unsigned": true}) | ||
* @ORM\GeneratedValue(strategy="IDENTITY") | ||
*/ | ||
#[ORM\Id] | ||
#[ORM\Column(type: 'integer', options: ['unsigned' => true])] | ||
#[ORM\GeneratedValue(strategy: 'IDENTITY')] | ||
protected int $primaryKey; | ||
|
||
public function getPrimaryKey(): int | ||
{ | ||
return $this->primaryKey; | ||
} | ||
|
||
public function setPrimaryKey(int $primaryKey): void | ||
{ | ||
$this->primaryKey = $primaryKey; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DH\Auditor\Tests\Provider\Doctrine\Issues; | ||
|
||
use DH\Auditor\Provider\Doctrine\Auditing\Transaction\AuditTrait; | ||
use DH\Auditor\Tests\Provider\Doctrine\Fixtures\Issue112\DummyEntity; | ||
use DH\Auditor\Tests\Provider\Doctrine\Traits\Schema\DefaultSchemaSetupTrait; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @small | ||
*/ | ||
final class Issue112Test extends TestCase | ||
{ | ||
use AuditTrait; | ||
use DefaultSchemaSetupTrait; | ||
|
||
/** | ||
* @throws \Doctrine\ORM\Mapping\MappingException | ||
* @throws \Doctrine\DBAL\Exception | ||
* @throws \DH\Auditor\Exception\MappingException | ||
*/ | ||
public function testSummarizeWithUnusualPK(): void | ||
{ | ||
$entityManager = $this->createEntityManager(); | ||
$entity = new DummyEntity(); | ||
$entity->setPrimaryKey(2); | ||
$data = $this->summarize($entityManager, $entity); | ||
self::assertSame('primaryKey', $data['pkName']); | ||
} | ||
} |