isCompatible example

protected function setUp(): void {
    parent::setUp();
    $this->checker = new SchemaCompatibilityChecker();
  }

  /** * @covers ::isCompatible * @dataProvider dataProviderIsCompatible */
  public function testIsCompatible(array $first_schema, array $second_schema, bool $expected): void {
    try {
      $this->checker->isCompatible($first_schema$second_schema);
      $is_compatible = TRUE;
    }
    catch (IncompatibleComponentSchema $e) {
      $is_compatible = FALSE;
    }
    $this->assertSame($expected$is_compatible);
  }

  /** * Data provider for the test testIsCompatible. * * @return array[] * The batches of data. */
/** * @coversDefaultClass \Drupal\Component\Version\Constraint * @group Version */
class ConstraintTest extends TestCase {

  /** * @covers ::isCompatible * @dataProvider providerIsCompatible */
  public function testIsCompatible(Constraint $version_info$current_version$result) {
    $this->assertSame($result$version_info->isCompatible($current_version));
  }

  /** * Provider for testIsCompatible. */
  public function providerIsCompatible() {
    $tests = [];

    $tests['no-dependencies'] = [new Constraint('', '8.x'), '8.1.x', TRUE];

    // Both no space and multiple spaces are supported between commas and

    public function getEncoderByName($name)
    {
        $name = strtolower(trim($name));

        if (!isset($this->encoder[$name])) {
            throw new DomainException(sprintf('Encoder by name %s not found', $name));
        }

        $encoder = $this->encoder[$name];

        if (method_exists($encoder, 'isCompatible') && !$encoder->isCompatible()) {
            throw new Exception(sprintf('Encoder by name %s is not compatible with your system', $name));
        }

        return $encoder;
    }

    /** * @return array<PasswordEncoderInterface> */
    public function getCompatibleEncoders()
    {
        
$errors[] = sprintf(
            'Property "%s" does not allow some necessary enum values [%s]. These are supported in the original schema and should be supported in the new schema for compatibility.',
            $property_name,
            implode(', ', $unsupported_enums),
          );
        }
        // If the property is an object, then ensure sub-schema compatibility.         $original_subproperties = $original_properties[$property_name]['properties'] ?? [];
        $new_subproperties = $new_properties[$property_name]['properties'] ?? [];
        if (!empty($original_subproperties) && !empty($new_subproperties)) {
          try {
            $this->isCompatible(
              $original_properties[$property_name],
              $new_properties[$property_name]
            );
          }
          catch (IncompatibleComponentSchema $exception) {
            $errors[] = $exception->getMessage();
          }
        }
        return $errors;
      },
      $error_messages
    );
$tests['module_and_project_names'] = ['drupal:views', 'views', 'drupal', ''];
    $tests['module_and_constraint'] = ['views (<8.x-3.1)', 'views', '', '<8.x-3.1'];
    $tests['module_and_project_names_and_constraint'] = ['drupal:views (>8.x-1.1)', 'views', 'drupal', '>8.x-1.1'];
    return $tests;
  }

  /** * @covers ::isCompatible */
  public function testIsCompatible() {
    $dependency = new Dependency('paragraphs_demo', 'paragraphs', '>8.x-1.1');
    $this->assertFalse($dependency->isCompatible('1.1'));
    $this->assertTrue($dependency->isCompatible('1.2'));
  }

  /** * Ensures that constraint objects are not serialized. * * @covers ::__sleep */
  public function testSerialization() {
    $dependency = new Dependency('paragraphs_demo', 'paragraphs', '>8.x-1.1');
    $this->assertTrue($dependency->isCompatible('1.2'));
    
// Check if the module is compatible with the installed version of core.       if ($modules[$dependency]->info['core_incompatible']) {
        return $this->t('@module_name (<span class="admin-missing">incompatible with</span> this version of Drupal core)', [
          '@module_name' => $module_name,
        ]);
      }

      // Check if the module is incompatible with the dependency constraints.       // Remove CORE_COMPATIBILITY- only from the start of the string.       $version = preg_replace('/^(' . \Drupal::CORE_COMPATIBILITY . '\-)/', '', $modules[$dependency]->info['version'] ?? '');
      if (!$dependency_object->isCompatible($version)) {
        $constraint_string = $dependency_object->getConstraintString();
        return $this->t('@module_name (<span class="admin-missing">incompatible with</span> version @version)', [
          '@module_name' => "$module_name ($constraint_string)",
          '@version' => $modules[$dependency]->info['version'] ?? '* ? *',
        ]);
      }
    }
  }

}
$new_schemas = $new_definition['props'] ?? NULL;
      if (!$original_schemas || !$new_schemas) {
        return [
          sprintf(
            "Component \"%s\" is attempting to replace \"%s\", however component replacement requires both components to have schema definitions.",
            $new_definition['id'],
            $original_definition['id'],
          ),
        ];
      }
      try {
        $this->compatibilityChecker->isCompatible(
          $original_schemas,
          $new_schemas
        );
      }
      catch (IncompatibleComponentSchema $e) {
        $errors[] = sprintf(
          "\"%s\" is incompatible with the component is wants to replace \"%s\". Errors:\n%s",
          $new_definition['id'],
          $original_definition['id'],
          $e->getMessage()
        );
      }
/** * Determines if the provided version is compatible with this dependency. * * @param string $version * The version to check, for example '4.2'. * * @return bool * TRUE if compatible with the provided version, FALSE if not. */
  public function isCompatible($version) {
    return $this->getConstraint()->isCompatible($version);
  }

  /** * Creates a new instance of this class from a dependency string. * * @param string $dependency * A dependency string, which specifies a module or theme dependency, and * optionally the project it comes from and a constraint string that * determines the versions that are supported. Supported formats include: * - 'module' * - 'project:module' * - 'project:module (>=version, <=version)'. * * @return static */
Home | Imprint | This part of the site doesn't use cookies.