mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-16 08:21:36 +00:00
Added additional tests
This commit is contained in:
parent
cb669ad4ec
commit
65a6f46369
12 changed files with 2392 additions and 1441 deletions
67
tests/Services/Cache/ElementCacheTagGeneratorTest.php
Normal file
67
tests/Services/Cache/ElementCacheTagGeneratorTest.php
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 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/>.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Services\Cache;
|
||||
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Services\Cache\ElementCacheTagGenerator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ElementCacheTagGeneratorTest extends TestCase
|
||||
{
|
||||
private ElementCacheTagGenerator $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->service = new ElementCacheTagGenerator();
|
||||
}
|
||||
|
||||
public function testClassNameIsConvertedToTag(): void
|
||||
{
|
||||
$tag = $this->service->getElementTypeCacheTag(Part::class);
|
||||
// Backslashes must be replaced by underscores
|
||||
$this->assertStringNotContainsString('\\', $tag);
|
||||
$this->assertSame(str_replace('\\', '_', Part::class), $tag);
|
||||
}
|
||||
|
||||
public function testObjectInputGivesSameResultAsClassName(): void
|
||||
{
|
||||
$part = new Part();
|
||||
$tagFromObject = $this->service->getElementTypeCacheTag($part);
|
||||
$tagFromClass = $this->service->getElementTypeCacheTag(Part::class);
|
||||
$this->assertSame($tagFromClass, $tagFromObject);
|
||||
}
|
||||
|
||||
public function testResultIsCached(): void
|
||||
{
|
||||
$tag1 = $this->service->getElementTypeCacheTag(Part::class);
|
||||
$tag2 = $this->service->getElementTypeCacheTag(Part::class);
|
||||
$this->assertSame($tag1, $tag2);
|
||||
}
|
||||
|
||||
public function testNonExistentClassThrowsException(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->service->getElementTypeCacheTag('App\\NonExistent\\Foo');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue