-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
201 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DataDog\AuditBundle\Tests\Entity; | ||
|
||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity() | ||
* @ORM\Table() | ||
*/ | ||
#[ORM\Entity] | ||
#[ORM\Table] | ||
class Account | ||
{ | ||
/** | ||
* @ORM\Id() | ||
* @ORM\GeneratedValue() | ||
* @ORM\Column(type="integer") | ||
*/ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column(type: Types::INTEGER)] | ||
private int $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255) | ||
*/ | ||
#[ORM\Column(type: Types::STRING, length: 255)] | ||
private string $username; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255) | ||
*/ | ||
#[ORM\Column(type: Types::STRING, length: 255)] | ||
private string $password; | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setId(int $id): void | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function getUsername(): string | ||
{ | ||
return $this->username; | ||
} | ||
|
||
public function setUsername(string $username): void | ||
{ | ||
$this->username = $username; | ||
} | ||
|
||
public function getPassword(): string | ||
{ | ||
return $this->password; | ||
} | ||
|
||
public function setPassword(string $password): void | ||
{ | ||
$this->password = $password; | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
tests/EventListener/AuditListenerExtendsVersionTest.php
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,111 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DataDog\AuditBundle\Tests\EventListener; | ||
|
||
use DataDog\AuditBundle\Entity\AuditLog; | ||
use DataDog\AuditBundle\Tests\Entity\Account; | ||
use DataDog\AuditBundle\Tests\OrmTestCase; | ||
use DataDog\AuditBundle\Tests\TestKernel; | ||
|
||
final class AuditListenerExtendsVersionTest extends OrmTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
} | ||
|
||
/** | ||
* @dataProvider dataProvider | ||
*/ | ||
public function testExtendsVersion( | ||
array $dataDogAuditConfig, | ||
callable $callable, | ||
array $expectedFields | ||
): void { | ||
$this->kernel = new TestKernel([ | ||
'entities' => [ | ||
Account::class => $dataDogAuditConfig, | ||
], | ||
]); | ||
$this->kernel->boot(); | ||
|
||
$this->loadFixtures(); | ||
|
||
$em = $this->getDoctrine()->getManager(); | ||
|
||
$account = new Account(); | ||
$callable($account); | ||
|
||
$em->persist($account); | ||
$em->flush(); | ||
|
||
$auditLogs = $em->createQuery('SELECT l FROM '.AuditLog::class.' l')->getResult(); | ||
$this->assertCount(1, $auditLogs); | ||
|
||
foreach ($expectedFields as $field) { | ||
$this->assertArrayHasKey($field, $auditLogs[0]->getDiff()); | ||
} | ||
} | ||
|
||
public static function dataProvider(): array | ||
{ | ||
return [ | ||
'exclude-password-field' => [ | ||
[ | ||
'mode' => 'exclude', | ||
'fields' => [ | ||
'password', | ||
], | ||
], | ||
function (Account $account): void { | ||
$account->setUsername('username'); | ||
$account->setPassword('password'); | ||
}, | ||
[ | ||
'username', | ||
], | ||
], | ||
'exclude-all' => [ | ||
[ | ||
'mode' => 'exclude', | ||
'fields' => null, | ||
], | ||
function (Account $account): void { | ||
$account->setUsername('username'); | ||
$account->setPassword('password'); | ||
}, | ||
[], | ||
], | ||
'include-password-field' => [ | ||
[ | ||
'mode' => 'include', | ||
'fields' => [ | ||
'password', | ||
], | ||
], | ||
function (Account $account): void { | ||
$account->setUsername('username'); | ||
$account->setPassword('password'); | ||
}, | ||
[ | ||
'password', | ||
], | ||
], | ||
'include-all' => [ | ||
[ | ||
'mode' => 'include', | ||
'fields' => null, | ||
], | ||
function (Account $account): void { | ||
$account->setUsername('username'); | ||
$account->setPassword('password'); | ||
}, | ||
[ | ||
'username', | ||
'password', | ||
], | ||
] | ||
]; | ||
} | ||
} |
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