class SchemaCompatibilityCheckerTest
Same name in this branch
- 11.x core/tests/Drupal/Tests/Core/Theme/Component/SchemaCompatibilityCheckerTest.php \Drupal\Tests\Core\Theme\Component\SchemaCompatibilityCheckerTest
Same name in other branches
- 10 core/modules/sdc/tests/src/Unit/SchemaCompatibilityCheckerTest.php \Drupal\Tests\sdc\Unit\SchemaCompatibilityCheckerTest
- 10 core/tests/Drupal/Tests/Core/Theme/Component/SchemaCompatibilityCheckerTest.php \Drupal\Tests\Core\Theme\Component\SchemaCompatibilityCheckerTest
@coversDefaultClass \Drupal\sdc\Component\SchemaCompatibilityChecker @group sdc
@internal
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\sdc\Unit\SchemaCompatibilityCheckerTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of SchemaCompatibilityCheckerTest
File
-
core/
modules/ sdc/ tests/ src/ Unit/ SchemaCompatibilityCheckerTest.php, line 17
Namespace
Drupal\Tests\sdc\UnitView source
final class SchemaCompatibilityCheckerTest extends UnitTestCase {
/**
* The system under test.
*/
protected SchemaCompatibilityChecker $checker;
/**
* {@inheritdoc}
*/
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.
*/
public static function dataProviderIsCompatible() : array {
$schema = [
'type' => 'object',
'required' => [
'text',
],
'properties' => [
'text' => [
'type' => 'string',
'title' => 'Title',
'description' => 'The title for the button',
'minLength' => 2,
'examples' => [
'Press',
'Submit now',
],
],
'iconType' => [
'type' => 'string',
'title' => 'Icon Type',
'enum' => [
'power',
'like',
'external',
],
],
],
];
$schema_different_required = [
$schema,
'required' => [
'foo',
],
];
$schema_missing_icon_type = $schema;
unset($schema_missing_icon_type['properties']['iconType']);
$schema_missing_text = $schema;
unset($schema_missing_text['properties']['text']);
$schema_icon_with_number = $schema;
$schema_icon_with_number['properties']['iconType']['type'] = [
'string',
'number',
];
$schema_additional_enum = $schema;
$schema_additional_enum['properties']['iconType']['enum'][] = 'wow';
$schema_with_sub_schema = $schema;
$schema_with_sub_schema['properties']['parent'] = $schema;
$schema_with_sub_schema_enum = $schema;
$schema_with_sub_schema_enum['properties']['parent'] = $schema_additional_enum;
return [
[
$schema,
$schema,
TRUE,
],
[
$schema,
$schema_different_required,
FALSE,
],
[
$schema_different_required,
$schema,
FALSE,
],
[
$schema_missing_icon_type,
$schema,
TRUE,
],
[
$schema,
$schema_missing_icon_type,
TRUE,
],
[
$schema_missing_text,
$schema,
TRUE,
],
[
$schema,
$schema_missing_text,
TRUE,
],
[
$schema_icon_with_number,
$schema,
FALSE,
],
[
$schema,
$schema_icon_with_number,
TRUE,
],
[
$schema,
$schema_additional_enum,
TRUE,
],
[
$schema_additional_enum,
$schema,
FALSE,
],
[
$schema_with_sub_schema,
$schema_with_sub_schema,
TRUE,
],
[
$schema_with_sub_schema,
$schema_with_sub_schema_enum,
TRUE,
],
[
$schema_with_sub_schema_enum,
$schema_with_sub_schema,
FALSE,
],
];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
SchemaCompatibilityCheckerTest::$checker | protected | property | The system under test. | |
SchemaCompatibilityCheckerTest::dataProviderIsCompatible | public static | function | Data provider for the test testIsCompatible. | |
SchemaCompatibilityCheckerTest::setUp | protected | function | Overrides UnitTestCase::setUp | |
SchemaCompatibilityCheckerTest::testIsCompatible | public | function | @covers ::isCompatible @dataProvider dataProviderIsCompatible |
|
UnitTestCase::$root | protected | property | The app root. | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.