Skip to content

[TASK] Add tests for the model property validations#2127

Open
hermannatz wants to merge 2 commits into
TYPO3BestPractices:mainfrom
hermannatz:feature/458-add-length-validation-model-fields
Open

[TASK] Add tests for the model property validations#2127
hermannatz wants to merge 2 commits into
TYPO3BestPractices:mainfrom
hermannatz:feature/458-add-length-validation-model-fields

Conversation

@hermannatz
Copy link
Copy Markdown

@hermannatz hermannatz commented May 14, 2026

Add functional tests for title and description validation to verify the configured Extbase validators.

Resolves: #458

@oliverklee oliverklee added the enhancement New feature or request label May 14, 2026
@oliverklee oliverklee added this to the 4.1.0 milestone May 14, 2026
@oliverklee oliverklee force-pushed the feature/458-add-length-validation-model-fields branch from ba35c8c to f8bb3da Compare May 19, 2026 07:34
Copy link
Copy Markdown
Contributor

@oliverklee oliverklee left a comment

Choose a reason for hiding this comment

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

Looks already quite good - thank your for this!

I've added some remarks.

Also, the PR title should read:

[TASK] Add tests for the model property validations

Comment thread Tests/Functional/Domain/Model/TeaTest.php Outdated
Comment thread Tests/Functional/Domain/Model/TeaTest.php Outdated
Comment thread Tests/Functional/Domain/Model/TeaTest.php
Comment thread Tests/Functional/Domain/Model/TeaTest.php Outdated
Comment thread Tests/Functional/Domain/Model/TeaTest.php Outdated
Comment thread Tests/Functional/Domain/Model/TeaTest.php Outdated
$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.

@hermannatz hermannatz changed the title [TASK] Add length validation for the model fields [TASK] Add tests for the model property validations Jun 1, 2026
@hermannatz hermannatz force-pushed the feature/458-add-length-validation-model-fields branch from d2ad8ed to e11b850 Compare June 1, 2026 11:18
Hermann Azong added 2 commits June 1, 2026 13:19
Add functional tests for title and description validation
to verify the configured Extbase validators.

Resolves: TYPO3BestPractices#458
Releases: main"
@hermannatz hermannatz force-pushed the feature/458-add-length-validation-model-fields branch from e11b850 to f159a00 Compare June 1, 2026 11:19
@oliverklee oliverklee moved this from In Progress to In Review in Best Practices code sprint Jun 1, 2026
@oliverklee oliverklee self-requested a review June 1, 2026 11:26
{
parent::setUp();
$this->subject = new Tea();
$validatorResolver = $this->getContainer()->get(ValidatorResolver::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'll most probably be able to skip getContainer() here:

Suggested change
$validatorResolver = $this->getContainer()->get(ValidatorResolver::class);
$validatorResolver = $this->get(ValidatorResolver::class);

protected function setUp(): void
{
parent::setUp();
$this->subject = new Tea();
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.

In general, creating the subject should be the last line in setUp() (if possible).


protected function setUp(): void
{
parent::setUp();
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.

Generally, we should have a blank line after parent::setUp();.

protected array $testExtensionsToLoad = ['ttn/tea'];

private Tea $subject;
private ConjunctionValidator $validator;
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 autoformat - there should be an empty line between the properties.

{
$this->subject->setDescription(str_repeat('d', 2000));
$result = $this->validator->validate($this->subject);
self::assertFalse($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.

In all tests, please add blank lines between the different test phases:

  • test-specific setup (set the data)
  • execution (validate call)
  • validation (assert* call)

I've visualized this on a slide in one of my presentations on testing.

@github-project-automation github-project-automation Bot moved this from In Review to In Progress in Best Practices code sprint Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Add length validation for the model fields

2 participants