[TASK] Add tests for the model property validations#2127
Conversation
ba35c8c to
f8bb3da
Compare
oliverklee
left a comment
There was a problem hiding this comment.
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
| $result = $validator->validate($this->subject); | ||
| self::assertTrue($result->forProperty('description')->hasErrors()); | ||
| } | ||
|
|
There was a problem hiding this comment.
Please remove this blank line.
d2ad8ed to
e11b850
Compare
Add functional tests for title and description validation to verify the configured Extbase validators. Resolves: TYPO3BestPractices#458 Releases: main"
e11b850 to
f159a00
Compare
| { | ||
| parent::setUp(); | ||
| $this->subject = new Tea(); | ||
| $validatorResolver = $this->getContainer()->get(ValidatorResolver::class); |
There was a problem hiding this comment.
We'll most probably be able to skip getContainer() here:
| $validatorResolver = $this->getContainer()->get(ValidatorResolver::class); | |
| $validatorResolver = $this->get(ValidatorResolver::class); |
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| $this->subject = new Tea(); |
There was a problem hiding this comment.
In general, creating the subject should be the last line in setUp() (if possible).
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); |
There was a problem hiding this comment.
Generally, we should have a blank line after parent::setUp();.
| protected array $testExtensionsToLoad = ['ttn/tea']; | ||
|
|
||
| private Tea $subject; | ||
| private ConjunctionValidator $validator; |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
In all tests, please add blank lines between the different test phases:
- test-specific setup (set the data)
- execution (
validatecall) - validation (
assert*call)
I've visualized this on a slide in one of my presentations on testing.
Add functional tests for title and description validation to verify the configured Extbase validators.
Resolves: #458