Files
myep/tests/Form/Model/OfferAcceptDtoTest.php
T

55 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Form\Model;
use App\Form\Model\OfferAcceptDto;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Validator\ValidatorInterface;
class OfferAcceptDtoTest extends TestCase
{
public function testAcceptedTermsWithoutRemarksIsValid(): void
{
$violations = $this->validator()->validate(new OfferAcceptDto(termsAccepted: true));
self::assertCount(0, $violations);
}
public function testUncheckedTermsAreRejected(): void
{
$violations = $this->validator()->validate(new OfferAcceptDto(remarks: 'Bitte Zimmer im EG'));
self::assertCount(1, $violations);
self::assertSame('termsAccepted', $violations[0]->getPropertyPath());
self::assertSame('Bitte akzeptiere die AGB, um die Buchung abzuschließen.', $violations[0]->getMessage());
}
public function testRemarksAreCappedAt2000Characters(): void
{
$dto = new OfferAcceptDto(termsAccepted: true, remarks: str_repeat('a', 2001));
$violations = $this->validator()->validate($dto);
self::assertCount(1, $violations);
self::assertSame('remarks', $violations[0]->getPropertyPath());
self::assertSame('Die Anmerkungen dürfen maximal 2000 Zeichen lang sein.', $violations[0]->getMessage());
}
public function testRemarksAtTheLimitAreAccepted(): void
{
$dto = new OfferAcceptDto(termsAccepted: true, remarks: str_repeat('a', 2000));
self::assertCount(0, $this->validator()->validate($dto));
}
private function validator(): ValidatorInterface
{
return Validation::createValidatorBuilder()
->enableAttributeMapping()
->getValidator();
}
}