feature: add Authenticator
This commit is contained in:
parent
b102519154
commit
2380c13c37
15 changed files with 1370 additions and 17 deletions
|
@ -2,17 +2,82 @@
|
|||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\Entity\Printer;
|
||||
use App\Service\PrinterService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PrinterService;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\MakerBundle\Docker\DockerDatabaseServices;
|
||||
use Symfony\Component\Serializer\SerializerInterface;
|
||||
use function PHPUnit\Framework\once;
|
||||
|
||||
class PrinterServiceTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
public function EditPrinterShouldEditPrinter(){
|
||||
$printerService = new PrinterService();
|
||||
private readonly EntityManagerInterface&MockObject $entityManager;
|
||||
private readonly SerializerInterface&MockObject $serializer;
|
||||
private readonly PrinterService $printerService;
|
||||
|
||||
$printerService->editPrinter(Printer $printer, )
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->entityManager = self::createMock(EntityManagerInterface::class);
|
||||
$this->serializer = self::createMock(SerializerInterface::class);
|
||||
$this->printerService = new PrinterService($this->entityManager, $this->serializer);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function removeShouldInvokeRemoveOnPrinterAndFlush()
|
||||
{
|
||||
$printer = new Printer();
|
||||
|
||||
$this->entityManager->expects(self::once())->method('remove')->with($printer);
|
||||
$this->entityManager->expects(self::once())->method('flush');
|
||||
|
||||
$this->printerService->deletePrinter($printer);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function validateJsonShouldReturnFalseOnInputIncompleteJson()
|
||||
{
|
||||
$invalidJson = '{
|
||||
"name": "Bambu A1"
|
||||
}';
|
||||
|
||||
self::assertFalse($this->printerService->validateJson($invalidJson));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function validateJsonShouldReturnTrueOnInputCompleteJson()
|
||||
{
|
||||
$validJson = '{
|
||||
"name": "Bambu A1 Mini",
|
||||
"price": 10.50,
|
||||
"build_volume": "180x180x180",
|
||||
"max_speed": 1000
|
||||
}';
|
||||
|
||||
self::assertTrue($this->printerService->validateJson($validJson));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function createPrinterShouldInvokePersistAndFlushOnCreatedPrinterObject(){
|
||||
$json = '{
|
||||
"name": "Bambu A1 Mini",
|
||||
"price": 10.50,
|
||||
"build_volume": "180x180x180",
|
||||
"max_speed": 1000
|
||||
}';
|
||||
|
||||
$printer = new Printer();
|
||||
$printer
|
||||
->setName('Bambu A1 Mini')
|
||||
->setPrice(10.50)
|
||||
->setBuildVolume('180x180x180')
|
||||
->setMaxSpeed(1000);
|
||||
|
||||
$this->serializer->expects(self::once())->method('deserialize')->with($json)->willReturn($printer);
|
||||
$this->entityManager->expects(self::once())->method('persist')->with($printer);
|
||||
$this->entityManager->expects(self::once())->method('flush');
|
||||
|
||||
$this->printerService->createPrinter($json);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue