programmieren:testing:unittest:table_tests
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| programmieren:testing:unittest:table_tests [2026/08/26 15:54] – Explanation to Data Validation Tests admin | programmieren:testing:unittest:table_tests [2026/08/27 10:07] (current) – [Problem with DataValidationTestTrait] Explaination admin | ||
|---|---|---|---|
| Line 61: | Line 61: | ||
| - Keep the logic but implement it so that if the error you're looking for is contained within the list of errors it still runs through. I'm not sure how well this will work since it causes a different kind of error than validation errors. | - Keep the logic but implement it so that if the error you're looking for is contained within the list of errors it still runs through. I'm not sure how well this will work since it causes a different kind of error than validation errors. | ||
| - | **REMEMBER TO LOOK AT THIS WITH Fabian** | + | So it ended up being a much simpler mistake. We forgot to disable validation on BOTH the times it was saved. The existing logic actually allows there being multiple different errors since it searches for a specific one in the list of errors it gets. We corrected it now in the trait itsself and it works properly now. The issue that you have to give it all the required fields still exists tho since it is not a data validation error. So an implementation would now look like this: |
| + | |||
| + | <code php> | ||
| + | $this-> | ||
| + | $subscriptions, | ||
| + | ' | ||
| + | ' | ||
| + | [ | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ] | ||
| + | ); | ||
| + | </ | ||
| + | |||
| + | And the trait now looks like this: | ||
| + | |||
| + | <code php> | ||
| + | protected function testDataValidationIsUnique( | ||
| + | Table $table, | ||
| + | string $fieldName, | ||
| + | mixed $fieldValue, | ||
| + | array $additionalProperties = [], | ||
| + | ?array $expected = null, | ||
| + | ): void { | ||
| + | $prevEntity = $table-> | ||
| + | $table-> | ||
| + | $prevEntity, | ||
| + | array_merge($additionalProperties, | ||
| + | [' | ||
| + | ); | ||
| + | $table-> | ||
| + | |||
| + | $entity = $table-> | ||
| + | $table-> | ||
| + | $entity, | ||
| + | array_merge($additionalProperties, | ||
| + | [' | ||
| + | ); | ||
| + | |||
| + | $result = $table-> | ||
| + | static:: | ||
| + | |||
| + | $expected ??= [' | ||
| + | |||
| + | $this-> | ||
| + | } | ||
| + | </ | ||
programmieren/testing/unittest/table_tests.1787752443.txt.gz · Last modified: by admin
