Skip to content
Snippets Groups Projects

Add test with broken property type.

Closed Nikita Malyshev requested to merge issue/drupal-3462156:3462156-unhelpful-php-error into 11.x
1 unresolved thread

Closes #3462156

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • added 1 commit

    Compare with previous version

  • Nikita Malyshev resolved all threads

    resolved all threads

  • added 1 commit

    • f2bf9201 - It's not a possibility, it is a fact :)

    Compare with previous version

  • 78 78 $valid_cta,
    79 79 ['extension_type' => 'invalid'],
    80 80 );
    81 $cta_with_null_prop_type = $valid_cta;
    82 $cta_with_null_prop_type['props']['properties']['text']['type'] = NULL;
    83 $cta_with_null_prop_type_list = $valid_cta;
    84 $cta_with_null_prop_type_list['props']['properties']['text']['type'] = ['string', NULL];
    • Comment on lines +81 to +84

      :pray: This is testing twice with null as the non-string type. Why not add one example that is an array too?

    • I think it would be nice to test all possible non-string types here as a direct type and as part of the array with types. I suggest testing: int, float, array, boolean types. But for that, I have to refactor the data provider to \Generator, to make it more readable and easy to understand. Is that possible as part of this issue?

        public static function dataProviderValidateDefinitionInvalid(): \Generator {
          $valid_cta = static::loadComponentDefinitionFromFs('my-cta');
      
          $cta_with_missing_required = $valid_cta;
          unset($cta_with_missing_required['path']);
          yield 'missing required' => [$cta_with_missing_required];
      
          $cta_with_invalid_class = $valid_cta;
          $cta_with_invalid_class['props']['properties']['attributes']['type'] = 'Drupal\Foo\Invalid';
          yield 'invalid class' => [$cta_with_invalid_class];
      
          $cta_with_invalid_enum = array_merge(
            $valid_cta,
            ['extension_type' => 'invalid'],
          );
          yield 'invalid enum' => [$cta_with_invalid_enum];
      
          // A list of property types that are not strings, but can be provided via
          // YAML.
          $non_string_types = [NULL, 123, 123.45, TRUE];
          foreach ($non_string_types as $non_string_type) {
            $cta_with_non_string_prop_type = $valid_cta;
            $cta_with_non_string_prop_type['props']['properties']['text']['type'] = $non_string_type;
            yield "non string type ($non_string_type)" => [$cta_with_non_string_prop_type];
      
            // Same, but as a part of the list of allowed types.
            $cta_with_non_string_prop_type['props']['properties']['text']['type'] = ['string', $non_string_type];
            yield "non string type ($non_string_type) in a list of types" => [$cta_with_non_string_prop_type];
          }
      
          // The array is a valid value for the 'type' parameter, but it is not
          // allowed as the allowed type.
          $cta_with_non_string_prop_type['props']['properties']['text']['type'] = ['string', []];
          yield 'non string type (Array)' => [$cta_with_non_string_prop_type];
        }
    • I personally don't see why not!

    • Nikita Malyshev changed this line in version 8 of the diff

      changed this line in version 8 of the diff

    • Please register or sign in to reply
  • Nikita Malyshev added 175 commits

    added 175 commits

    Compare with previous version

  • added 1 commit

    • c10e9703 - Improve data provider and cover more cases

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Nikita Malyshev added 114 commits

    added 114 commits

    Compare with previous version

  • added 1 commit

    • 5f7ad929 - Change the return comment of ::dataProviderValidateDefinitionInvalid().

    Compare with previous version

  • closed

  • Please register or sign in to reply
    Loading