mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 10:49:00 +02:00
Use an enum for target_type in log entries
This commit is contained in:
parent
2da7463edf
commit
9adfcc7aec
12 changed files with 359 additions and 210 deletions
|
@ -60,53 +60,6 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
class AbstractLogEntryTest extends TestCase
|
||||
{
|
||||
public function targetTypeDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[1, User::class],
|
||||
[2, Attachment::class],
|
||||
[3, AttachmentType::class],
|
||||
[4, Category::class],
|
||||
[5, Project::class],
|
||||
[6, ProjectBOMEntry::class],
|
||||
[7, Footprint::class],
|
||||
[8, Group::class],
|
||||
[9, Manufacturer::class],
|
||||
[10, Part::class],
|
||||
[11, Storelocation::class],
|
||||
[12, Supplier::class],
|
||||
[-1, 'blablub', true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider targetTypeDataProvider
|
||||
*/
|
||||
public function testTargetTypeIdToClass(int $int, string $expected_class, bool $expect_exception = false): void
|
||||
{
|
||||
if ($expect_exception) {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
}
|
||||
$this->assertSame($expected_class, AbstractLogEntry::targetTypeIdToClass($int));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider targetTypeDataProvider
|
||||
*/
|
||||
public function testTypeClassToID(int $expected_id, string $class, bool $expect_exception = false): void
|
||||
{
|
||||
if ($expect_exception) {
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
}
|
||||
$this->assertSame($expected_id, AbstractLogEntry::targetTypeClassToID($class));
|
||||
}
|
||||
|
||||
public function testTypeClassToIDSubclasses(): void
|
||||
{
|
||||
//Test if class mapping works for subclasses
|
||||
$this->assertSame(2, AbstractLogEntry::targetTypeClassToID(PartAttachment::class));
|
||||
}
|
||||
|
||||
public function testSetGetTarget(): void
|
||||
{
|
||||
$part = $this->createMock(Part::class);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue