Started adding basic tests for LogEntryRepository

This commit is contained in:
Jan Böhmer 2024-06-23 15:41:57 +02:00
parent 8fdf37261d
commit 204178740c
4 changed files with 213 additions and 0 deletions

View file

@ -74,30 +74,37 @@ class DataStructureFixtures extends Fixture implements DependentFixtureInterface
/** @var AbstractStructuralDBElement $node1 */
$node1 = new $class();
$node1->setName('Node 1');
$this->addReference($class . '_1', $node1);
/** @var AbstractStructuralDBElement $node2 */
$node2 = new $class();
$node2->setName('Node 2');
$this->addReference($class . '_2', $node2);
/** @var AbstractStructuralDBElement $node3 */
$node3 = new $class();
$node3->setName('Node 3');
$this->addReference($class . '_3', $node3);
$node1_1 = new $class();
$node1_1->setName('Node 1.1');
$node1_1->setParent($node1);
$this->addReference($class . '_4', $node1_1);
$node1_2 = new $class();
$node1_2->setName('Node 1.2');
$node1_2->setParent($node1);
$this->addReference($class . '_5', $node1_2);
$node2_1 = new $class();
$node2_1->setName('Node 2.1');
$node2_1->setParent($node2);
$this->addReference($class . '_6', $node2_1);
$node1_1_1 = new $class();
$node1_1_1->setName('Node 1.1.1');
$node1_1_1->setParent($node1_1);
$this->addReference($class . '_7', $node1_1_1);
$manager->persist($node1);
$manager->persist($node2);

View file

@ -0,0 +1,71 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\DataFixtures;
use App\Entity\LogSystem\ElementCreatedLogEntry;
use App\Entity\LogSystem\ElementEditedLogEntry;
use App\Entity\Parts\Category;
use App\Entity\UserSystem\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
class LogEntryFixtures extends Fixture implements DependentFixtureInterface
{
public function load(ObjectManager $manager)
{
$this->createCategoryEntries($manager);
}
public function createCategoryEntries(ObjectManager $manager): void
{
$category = $this->getReference(Category::class . '_1', Category::class);
$logEntry = new ElementCreatedLogEntry($category);
$logEntry->setUser($this->getReference(UserFixtures::ADMIN, User::class));
$logEntry->setComment('Test');
$manager->persist($logEntry);
$logEntry = new ElementEditedLogEntry($category);
$logEntry->setUser($this->getReference(UserFixtures::ADMIN, User::class));
$logEntry->setComment('Test');
$logEntry->setOldData(['name' => 'Test']);
$logEntry->setNewData(['name' => 'Node 1.1']);
$manager->persist($logEntry);
$manager->flush();
}
public function getDependencies(): array
{
return [
UserFixtures::class,
DataStructureFixtures::class
];
}
}

View file

@ -73,6 +73,7 @@ class PartFixtures extends Fixture implements DependentFixtureInterface
$part = new Part();
$part->setName('Part 1');
$part->setCategory($manager->find(Category::class, 1));
$this->addReference(Part::class . '_1', $part);
$manager->persist($part);
/** More complex part */
@ -86,6 +87,7 @@ class PartFixtures extends Fixture implements DependentFixtureInterface
$part->setIpn('IPN123');
$part->setNeedsReview(true);
$part->setManufacturingStatus(ManufacturingStatus::ACTIVE);
$this->addReference(Part::class . '_2', $part);
$manager->persist($part);
/** Part with orderdetails, storelocations and Attachments */
@ -98,6 +100,7 @@ class PartFixtures extends Fixture implements DependentFixtureInterface
$partLot1->setStorageLocation($manager->find(StorageLocation::class, 1));
$part->addPartLot($partLot1);
$partLot2 = new PartLot();
$partLot2->setExpirationDate(new \DateTimeImmutable());
$partLot2->setComment('Test');
@ -133,6 +136,8 @@ class PartFixtures extends Fixture implements DependentFixtureInterface
$attachment->setAttachmentType($manager->find(AttachmentType::class, 1));
$part->addAttachment($attachment);
$this->addReference(Part::class . '_3', $part);
$manager->persist($part);
$manager->flush();
}