-
Notifications
You must be signed in to change notification settings - Fork 34
[TASK] Add tests for the model property validations #2127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,70 @@ | ||||||
| <?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\Validator\ConjunctionValidator; | ||||||
| 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; | ||||||
| private ConjunctionValidator $validator; | ||||||
|
|
||||||
| protected function setUp(): void | ||||||
| { | ||||||
| parent::setUp(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally, we should have a blank line after |
||||||
| $this->subject = new Tea(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, creating the subject should be the last line in |
||||||
| $validatorResolver = $this->getContainer()->get(ValidatorResolver::class); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll most probably be able to skip
Suggested change
|
||||||
| $this->validator = $validatorResolver->getBaseValidatorConjunction(Tea::class); | ||||||
| } | ||||||
|
|
||||||
| #[Test] | ||||||
| public function titleWithMaximumLengthPassesValidation(): void | ||||||
| { | ||||||
| $this->subject->setTitle(str_repeat('p', 255)); | ||||||
|
oliverklee marked this conversation as resolved.
|
||||||
| $result = $this->validator->validate($this->subject); | ||||||
| self::assertFalse($result->forProperty('title')->hasErrors()); | ||||||
| } | ||||||
|
|
||||||
| #[Test] | ||||||
| public function titleLongerThanMaximumLengthDoesNotPassValidation(): void | ||||||
| { | ||||||
| $this->subject->setTitle(str_repeat('p', 256)); | ||||||
| $result = $this->validator->validate($this->subject); | ||||||
| self::assertTrue($result->forProperty('title')->hasErrors()); | ||||||
| } | ||||||
|
|
||||||
| #[Test] | ||||||
| public function emptyTitleDoesNotPassValidation(): void | ||||||
| { | ||||||
| $this->subject->setTitle(''); | ||||||
| $result = $this->validator->validate($this->subject); | ||||||
| self::assertTrue($result->forProperty('title')->hasErrors()); | ||||||
| } | ||||||
|
|
||||||
| #[Test] | ||||||
| public function descriptionWithMaximumLengthPassesValidation(): void | ||||||
| { | ||||||
| $this->subject->setDescription(str_repeat('d', 2000)); | ||||||
| $result = $this->validator->validate($this->subject); | ||||||
| self::assertFalse($result->forProperty('description')->hasErrors()); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In all tests, please add blank lines between the different test phases:
I've visualized this on a slide in one of my presentations on testing. |
||||||
| } | ||||||
|
|
||||||
| #[Test] | ||||||
| public function descriptionLongerThanMaximumLengthDoesNotPassValidation(): void | ||||||
| { | ||||||
| $this->subject->setDescription(str_repeat('d', 2001)); | ||||||
| $result = $this->validator->validate($this->subject); | ||||||
| self::assertTrue($result->forProperty('description')->hasErrors()); | ||||||
| } | ||||||
|
|
||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this blank line. |
||||||
| } | ||||||
There was a problem hiding this comment.
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.