Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions Tests/Functional/Domain/Model/TeaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace TTN\Tea\Tests\Functional\Domain\Model;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use TTN\Tea\Domain\Model\Tea;
use TYPO3\CMS\Extbase\Validation\ValidatorResolver;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

#[CoversClass(Tea::class)]
final class TeaTest extends FunctionalTestCase
{
protected array $testExtensionsToLoad = ['ttn/tea'];

private Tea $subject;

protected function setUp(): void
{
parent::setUp();

$this->subject = new Tea();

}

#[Test]
public function validTitleLengthReturnsNoError(): void
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be more specific:

Suggested change
public function validTitleLengthReturnsNoError(): void
public function titleWithMaximumLengthPassesValidation(): void

{
$this->subject->setTitle(str_repeat('p', 255));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also should have a test emptyTitleDoesNotPassValidation so we also test the NotEmpty validation.


$validatorResolver = $this->getContainer()->get(ValidatorResolver::class);
$validator = $validatorResolver->getBaseValidatorConjunction(Tea::class);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move these two lines to setUp() and make $validator a property to reduce code duplication.

$result = $validator->validate($this->subject);
self::assertFalse($result->forProperty('title')->hasErrors());

}

#[Test]
public function invalidTitleLengthReturnsError(): void
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function invalidTitleLengthReturnsError(): void
public function titleLongerThanMaximumLengthDoesNotPassValidation(): void

{
$this->subject->setTitle(str_repeat('p', 256));

$validatorResolver = $this->getContainer()->get(ValidatorResolver::class);
$validator = $validatorResolver->getBaseValidatorConjunction(Tea::class);
$result = $validator->validate($this->subject);
self::assertTrue($result->forProperty('title')->hasErrors());

}

#[Test]
public function validateDescriptionLengthReturnsNoErrors(): void
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function validateDescriptionLengthReturnsNoErrors(): void
public function titleWithMaximumLengthPassesValidation(): void

{
$this->subject->setDescription(str_repeat('d', 2000));

$validatorResolver = $this->getContainer()->get(ValidatorResolver::class);
$validator = $validatorResolver->getBaseValidatorConjunction(Tea::class);
$result = $validator->validate($this->subject);
self::assertFalse($result->forProperty('description')->hasErrors());

}

#[Test]
public function invalidDescriptionLengthReturnsError(): void
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function invalidDescriptionLengthReturnsError(): void
public function descriptionLongerThanMaximumLengthDoesNotPassValidation(): void

{
$this->subject->setDescription(str_repeat('d', 2001));

$validatorResolver = $this->getContainer()->get(ValidatorResolver::class);
$validator = $validatorResolver->getBaseValidatorConjunction(Tea::class);
$result = $validator->validate($this->subject);
self::assertTrue($result->forProperty('description')->hasErrors());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this blank line.

}