|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of Packagist. |
| 5 | + * |
| 6 | + * (c) Jordi Boggiano <j.boggiano@seld.be> |
| 7 | + * Nils Adermann <naderman@naderman.de> |
| 8 | + * |
| 9 | + * For the full copyright and license information, please view the LICENSE |
| 10 | + * file that was distributed with this source code. |
| 11 | + */ |
| 12 | + |
| 13 | +namespace App\Tests\Entity; |
| 14 | + |
| 15 | +use App\Audit\AuditRecordType; |
| 16 | +use App\Entity\AuditRecord; |
| 17 | +use App\Entity\Version; |
| 18 | +use App\Entity\VersionRepository; |
| 19 | +use App\Tests\IntegrationTestCase; |
| 20 | + |
| 21 | +class VersionRepositoryTest extends IntegrationTestCase |
| 22 | +{ |
| 23 | + private VersionRepository $versionRepository; |
| 24 | + |
| 25 | + protected function setUp(): void |
| 26 | + { |
| 27 | + parent::setUp(); |
| 28 | + |
| 29 | + $this->versionRepository = self::getEM()->getRepository(Version::class); |
| 30 | + } |
| 31 | + |
| 32 | + public function testRemoveVersionMarksForRemovalAndCreatesAuditRecord(): void |
| 33 | + { |
| 34 | + $em = self::getEM(); |
| 35 | + |
| 36 | + $package = self::createPackage('vendor/package', 'https://github.com/vendor/package'); |
| 37 | + |
| 38 | + $version = new Version(); |
| 39 | + $version->setPackage($package); |
| 40 | + $version->setName($package->getName()); |
| 41 | + $version->setVersion('1.0.0'); |
| 42 | + $version->setNormalizedVersion('1.0.0.0'); |
| 43 | + $version->setDevelopment(false); |
| 44 | + $version->setLicense([]); |
| 45 | + $version->setAutoload([]); |
| 46 | + $package->getVersions()->add($version); |
| 47 | + |
| 48 | + $this->store($package, $version); |
| 49 | + |
| 50 | + $versionId = $version->getId(); |
| 51 | + $this->versionRepository->remove($version); |
| 52 | + |
| 53 | + $em->flush(); |
| 54 | + $em->clear(); |
| 55 | + |
| 56 | + $this->assertNull($this->versionRepository->find($versionId), 'Version was not deleted'); |
| 57 | + |
| 58 | + $auditRecord = $em->getRepository(AuditRecord::class)->findOneBy([ |
| 59 | + 'type' => AuditRecordType::VersionDeleted->value, |
| 60 | + 'packageId' => $package->getId(), |
| 61 | + 'actorId' => null, |
| 62 | + ]); |
| 63 | + $this->assertNotNull($auditRecord, 'No audit record for version deletion created'); |
| 64 | + } |
| 65 | +} |
0 commit comments