|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the Doctrine Behavioral Extensions package. |
| 7 | + * (c) Gediminas Morkevicius <gediminas.morkevicius@gmail.com> http://www.gediminasm.org |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Gedmo\Blameable; |
| 13 | + |
| 14 | +use Doctrine\Common\EventManager; |
| 15 | +use Gedmo\Tests\Blameable\Fixture\Entity\CompanyInteger; |
| 16 | +use Gedmo\Tests\Tool\BaseTestCaseORM; |
| 17 | + |
| 18 | +final class BlameableIntegerTest extends BaseTestCaseORM |
| 19 | +{ |
| 20 | + private int $userId; |
| 21 | + |
| 22 | + protected function setUp(): void |
| 23 | + { |
| 24 | + parent::setUp(); |
| 25 | + |
| 26 | + $this->userId = 42; |
| 27 | + |
| 28 | + $listener = new BlameableListener(); |
| 29 | + $listener->setUserValue($this->userId); |
| 30 | + |
| 31 | + $evm = new EventManager(); |
| 32 | + $evm->addEventSubscriber($listener); |
| 33 | + |
| 34 | + $this->getDefaultMockSqliteEntityManager($evm); |
| 35 | + } |
| 36 | + |
| 37 | + public function testBlameableInteger(): void |
| 38 | + { |
| 39 | + $company = new CompanyInteger(); |
| 40 | + $company->setName('My Name'); |
| 41 | + |
| 42 | + $this->em->persist($company); |
| 43 | + $this->em->flush(); |
| 44 | + $this->em->clear(); |
| 45 | + |
| 46 | + /** |
| 47 | + * @var CompanyInteger $foundCompany |
| 48 | + */ |
| 49 | + $foundCompany = $this->em->getRepository(CompanyInteger::class)->findOneBy(['name' => 'My Name']); |
| 50 | + $creator = $foundCompany->getCreator(); |
| 51 | + |
| 52 | + static::assertSame($this->userId, $creator); |
| 53 | + } |
| 54 | + |
| 55 | + protected function getUsedEntityFixtures(): array |
| 56 | + { |
| 57 | + return [ |
| 58 | + CompanyInteger::class, |
| 59 | + ]; |
| 60 | + } |
| 61 | +} |
0 commit comments