forked from DamienHarper/auditor
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write test for column of type
blob
. (DamienHarper#99)
* Wrote a test for DamienHarper#98 * Fixed phpcs issues * Handle the BLOB in the same way as BINARY
- Loading branch information
1 parent
0aebff7
commit 600f64f
Showing
3 changed files
with
136 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,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DH\Auditor\Tests\Provider\Doctrine\Fixtures\Issue98; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="issue_98") | ||
*/ | ||
#[ORM\Entity, ORM\Table(name: 'data_object')] | ||
class Issue98 | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer", options={"unsigned": true}) | ||
* @ORM\GeneratedValue(strategy="IDENTITY") | ||
*/ | ||
#[ORM\Id, ORM\GeneratedValue(strategy: 'IDENTITY'), ORM\Column(type: 'integer', options: ['unsigned' => true])] | ||
protected $id; | ||
|
||
/** | ||
* @ORM\Column(type="blob") | ||
*/ | ||
#[ORM\Column(type: 'blob')] | ||
protected $data; | ||
|
||
/** | ||
* Get the value of id. | ||
* | ||
* @return mixed | ||
*/ | ||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Set the value of id. | ||
* | ||
* @return DataObject | ||
*/ | ||
public function setId(int $id): self | ||
{ | ||
$this->id = $id; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the value of data. | ||
*/ | ||
public function getData() | ||
{ | ||
return $this->data; | ||
} | ||
|
||
/** | ||
* Set the value of data. | ||
* | ||
* @param mixed $data | ||
* | ||
* @return DataObject | ||
*/ | ||
public function setData($data): self | ||
{ | ||
$this->data = $data; | ||
|
||
return $this; | ||
} | ||
} |
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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DH\Auditor\Tests\Provider\Doctrine\Issues; | ||
|
||
use DH\Auditor\Model\Transaction; | ||
use DH\Auditor\Provider\Doctrine\DoctrineProvider; | ||
use DH\Auditor\Provider\Doctrine\Service\AuditingService; | ||
use DH\Auditor\Provider\Doctrine\Service\StorageService; | ||
use DH\Auditor\Tests\Provider\Doctrine\Fixtures\Issue98\Issue98; | ||
use DH\Auditor\Tests\Provider\Doctrine\Traits\ReaderTrait; | ||
use DH\Auditor\Tests\Provider\Doctrine\Traits\Schema\SchemaSetupTrait; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @small | ||
*/ | ||
final class Issue98Test extends TestCase | ||
{ | ||
use ReaderTrait; | ||
use SchemaSetupTrait; | ||
|
||
public function testIssue98(): void | ||
{ | ||
$reader = $this->createReader(); | ||
|
||
$em = $this->provider->getStorageServiceForEntity(Issue98::class)->getEntityManager(); | ||
$entity = new Issue98(); | ||
$entity->setData(fopen('data://text/plain,true', 'r')); | ||
$em->persist($entity); | ||
$em->flush(); | ||
|
||
$audits = $reader->createQuery(Issue98::class)->execute(); | ||
self::assertCount(1, $audits, 'results count ok.'); | ||
self::assertSame(Transaction::INSERT, $audits[0]->getType(), 'Reader::INSERT operation.'); | ||
} | ||
|
||
private function createAndInitDoctrineProvider(): void | ||
{ | ||
$auditor = $this->createAuditor(); | ||
$this->provider = new DoctrineProvider($this->createProviderConfiguration()); | ||
|
||
$entityManager = $this->createEntityManager([ | ||
__DIR__.'/../../../../src/Provider/Doctrine/Auditing/Annotation', | ||
__DIR__.'/../Fixtures/Issue98', | ||
]); | ||
$this->provider->registerStorageService(new StorageService('default', $entityManager)); | ||
$this->provider->registerAuditingService(new AuditingService('default', $entityManager)); | ||
|
||
$auditor->registerProvider($this->provider); | ||
} | ||
|
||
private function configureEntities(): void | ||
{ | ||
$this->provider->getConfiguration()->setEntities([ | ||
Issue98::class => ['enabled' => true], | ||
]); | ||
} | ||
} |