From 47355e3ba760cd1d62025a77876a7934a8bae589 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Wed, 30 Sep 2020 10:32:01 +0100 Subject: [PATCH] Issue #3135027 by mondrake, Spokje, ayushmishra206, rajandro, nitesh624: Replace usages of assertArrayEquals, deprecate it --- .../tests/src/Unit/MailHandlerTest.php | 2 +- .../Exception/RequirementsExceptionTest.php | 2 +- .../tests/src/Unit/MigrateTestCase.php | 2 +- .../migrate/tests/src/Unit/MigrationTest.php | 2 +- .../migrate/tests/src/Unit/RowTest.php | 2 +- .../tests/src/Unit/process/SubProcessTest.php | 2 +- .../Unit/Entity/RestResourceConfigTest.php | 2 +- .../tests/src/Unit/Plugin/area/ViewTest.php | 4 +-- .../workflows/tests/src/Unit/WorkflowTest.php | 34 +++++++++---------- .../Tests/Core/Batch/BatchBuilderTest.php | 2 +- .../Tests/Core/Config/NullStorageTest.php | 2 +- .../Core/Config/StorageCopyTraitTest.php | 8 ++--- .../Drupal/Tests/Core/Datetime/DateTest.php | 2 +- .../Core/Entity/ContentEntityBaseUnitTest.php | 2 +- .../EntityConstraintViolationListTest.php | 8 ++--- .../Tests/Core/Field/FieldItemListTest.php | 2 +- .../DerivativeDiscoveryDecoratorTest.php | 4 +-- .../Tests/Core/Template/AttributeTest.php | 14 ++++---- .../Tests/Core/Test/JUnitConverterTest.php | 6 ++-- .../Core/Test/RunTests/TestFileParserTest.php | 4 +-- .../Drupal/Tests/Core/Theme/RegistryTest.php | 2 +- core/tests/Drupal/Tests/UnitTestCase.php | 6 ++++ core/tests/Drupal/Tests/UnitTestCaseTest.php | 22 ++++++++++++ 23 files changed, 82 insertions(+), 54 deletions(-) create mode 100644 core/tests/Drupal/Tests/UnitTestCaseTest.php diff --git a/core/modules/contact/tests/src/Unit/MailHandlerTest.php b/core/modules/contact/tests/src/Unit/MailHandlerTest.php index 09e67a3caf5c..439e5077bfe1 100644 --- a/core/modules/contact/tests/src/Unit/MailHandlerTest.php +++ b/core/modules/contact/tests/src/Unit/MailHandlerTest.php @@ -144,7 +144,7 @@ function ($module, $key, $to, $langcode, $params, $from) use (&$results) { $this->assertEquals($key, $result['key']); $this->assertEquals($to, $result['to']); $this->assertEquals($langcode, $result['langcode']); - $this->assertArrayEquals($params, $result['params']); + $this->assertEquals($params, $result['params']); $this->assertEquals($from, $result['from']); }); $this->userStorage->expects($this->any()) diff --git a/core/modules/migrate/tests/src/Unit/Exception/RequirementsExceptionTest.php b/core/modules/migrate/tests/src/Unit/Exception/RequirementsExceptionTest.php index 38e1b98c4e1c..54307f3a0cc3 100644 --- a/core/modules/migrate/tests/src/Unit/Exception/RequirementsExceptionTest.php +++ b/core/modules/migrate/tests/src/Unit/Exception/RequirementsExceptionTest.php @@ -18,7 +18,7 @@ class RequirementsExceptionTest extends UnitTestCase { */ public function testGetRequirements() { $exception = new RequirementsException('Missing requirements ', ['requirements' => $this->missingRequirements]); - $this->assertArrayEquals(['requirements' => $this->missingRequirements], $exception->getRequirements()); + $this->assertEquals(['requirements' => $this->missingRequirements], $exception->getRequirements()); } /** diff --git a/core/modules/migrate/tests/src/Unit/MigrateTestCase.php b/core/modules/migrate/tests/src/Unit/MigrateTestCase.php index 4cb14415bb25..6425ff539267 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateTestCase.php +++ b/core/modules/migrate/tests/src/Unit/MigrateTestCase.php @@ -200,7 +200,7 @@ protected function retrievalAssertHelper($expected_value, $actual_value, $messag if (empty($expected_value && $actual_value)) { return; } - $this->assertArrayEquals($expected_value, $actual_value, $message); + $this->assertEquals($expected_value, $actual_value, $message); } else { $this->assertSame((string) $expected_value, (string) $actual_value, $message); diff --git a/core/modules/migrate/tests/src/Unit/MigrationTest.php b/core/modules/migrate/tests/src/Unit/MigrationTest.php index 8aa87c73249d..b4fb8a96de35 100644 --- a/core/modules/migrate/tests/src/Unit/MigrationTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrationTest.php @@ -123,7 +123,7 @@ public function testGetMigrations() { $requirements = ['test_a', 'test_b', 'test_c', 'test_d']; $migration->setRequirements($requirements); - $this->assertArrayEquals($requirements, $migration->getRequirements()); + $this->assertEquals($requirements, $migration->getRequirements()); } /** diff --git a/core/modules/migrate/tests/src/Unit/RowTest.php b/core/modules/migrate/tests/src/Unit/RowTest.php index 308550c85123..cc16e8a215d0 100644 --- a/core/modules/migrate/tests/src/Unit/RowTest.php +++ b/core/modules/migrate/tests/src/Unit/RowTest.php @@ -366,7 +366,7 @@ public function getDataProvider() { */ public function testGetMultiple(array $keys, array $expected_values) { $row = $this->createRowWithDestinationProperties($this->testGetSourceProperties, $this->testGetSourceIds, $this->testGetDestinationProperties); - $this->assertArrayEquals(array_combine($keys, $expected_values), $row->getMultiple($keys)); + $this->assertEquals(array_combine($keys, $expected_values), $row->getMultiple($keys)); } /** diff --git a/core/modules/migrate/tests/src/Unit/process/SubProcessTest.php b/core/modules/migrate/tests/src/Unit/process/SubProcessTest.php index c7edcbecfb23..7501c4e430c3 100644 --- a/core/modules/migrate/tests/src/Unit/process/SubProcessTest.php +++ b/core/modules/migrate/tests/src/Unit/process/SubProcessTest.php @@ -166,7 +166,7 @@ public function testNotFoundSubProcess($process_configuration, $source_values = // values ended up in the proper destinations, and that the value of the // key (@id) is the same as the destination ID (42). $new_value = $plugin->transform($current_value, $migrate_executable, $row, 'test'); - $this->assertArrayEquals([], $new_value); + $this->assertSame([], $new_value); } /** diff --git a/core/modules/rest/tests/src/Unit/Entity/RestResourceConfigTest.php b/core/modules/rest/tests/src/Unit/Entity/RestResourceConfigTest.php index f60225e5eae2..bf9a989c5fbc 100644 --- a/core/modules/rest/tests/src/Unit/Entity/RestResourceConfigTest.php +++ b/core/modules/rest/tests/src/Unit/Entity/RestResourceConfigTest.php @@ -36,7 +36,7 @@ public function testNormalizeRestMethod() { 'configuration' => $configuration, ], 'rest_resource_config'); - $this->assertArrayEquals($expected, $entity->getMethods()); + $this->assertEquals($expected, $entity->getMethods()); } } diff --git a/core/modules/views/tests/src/Unit/Plugin/area/ViewTest.php b/core/modules/views/tests/src/Unit/Plugin/area/ViewTest.php index be84c8da16ef..ae2f4a919c37 100644 --- a/core/modules/views/tests/src/Unit/Plugin/area/ViewTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/area/ViewTest.php @@ -59,10 +59,10 @@ public function testCalculateDependencies() { $this->viewHandler->view->storage = $view_this; $this->viewHandler->options['view_to_insert'] = 'other:default'; - $this->assertArrayEquals(['config' => ['view.other']], $this->viewHandler->calculateDependencies()); + $this->assertEquals(['config' => ['view.other']], $this->viewHandler->calculateDependencies()); $this->viewHandler->options['view_to_insert'] = 'this:default'; - $this->assertArrayEquals([], $this->viewHandler->calculateDependencies()); + $this->assertSame([], $this->viewHandler->calculateDependencies()); } } diff --git a/core/modules/workflows/tests/src/Unit/WorkflowTest.php b/core/modules/workflows/tests/src/Unit/WorkflowTest.php index 3d242a10227d..63bf2f08ed78 100644 --- a/core/modules/workflows/tests/src/Unit/WorkflowTest.php +++ b/core/modules/workflows/tests/src/Unit/WorkflowTest.php @@ -82,8 +82,8 @@ public function testGetStates() { $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); // Getting states works when there are none. - $this->assertArrayEquals([], array_keys($workflow->getTypePlugin()->getStates())); - $this->assertArrayEquals([], array_keys($workflow->getTypePlugin()->getStates([]))); + $this->assertSame([], $workflow->getTypePlugin()->getStates()); + $this->assertSame([], $workflow->getTypePlugin()->getStates([])); $workflow ->getTypePlugin() @@ -92,7 +92,7 @@ public function testGetStates() { ->addState('archived', 'Archived'); // States are stored in alphabetical key order. - $this->assertArrayEquals([ + $this->assertEquals([ 'archived', 'draft', 'published', @@ -102,21 +102,21 @@ public function testGetStates() { $this->assertInstanceOf(State::class, $workflow->getTypePlugin()->getStates()['draft']); // Passing in no IDs returns all states. - $this->assertArrayEquals(['draft', 'published', 'archived'], array_keys($workflow->getTypePlugin()->getStates())); + $this->assertEquals(['draft', 'published', 'archived'], array_keys($workflow->getTypePlugin()->getStates())); // The order of states is by weight. $workflow->getTypePlugin()->setStateWeight('published', -1); - $this->assertArrayEquals(['published', 'draft', 'archived'], array_keys($workflow->getTypePlugin()->getStates())); + $this->assertEquals(['published', 'draft', 'archived'], array_keys($workflow->getTypePlugin()->getStates())); // The label is also used for sorting if weights are equal. $workflow->getTypePlugin()->setStateWeight('archived', 0); - $this->assertArrayEquals(['published', 'archived', 'draft'], array_keys($workflow->getTypePlugin()->getStates())); + $this->assertEquals(['published', 'archived', 'draft'], array_keys($workflow->getTypePlugin()->getStates())); // You can limit the states returned by passing in states IDs. - $this->assertArrayEquals(['archived', 'draft'], array_keys($workflow->getTypePlugin()->getStates(['draft', 'archived']))); + $this->assertEquals(['archived', 'draft'], array_keys($workflow->getTypePlugin()->getStates(['draft', 'archived']))); // An empty array does not load all states. - $this->assertArrayEquals([], array_keys($workflow->getTypePlugin()->getStates([]))); + $this->assertSame([], $workflow->getTypePlugin()->getStates([])); } /** @@ -394,8 +394,8 @@ public function testGetTransitions() { $workflow = new Workflow(['id' => 'test', 'type' => 'test_type'], 'workflow'); // Getting transitions works when there are none. - $this->assertArrayEquals([], array_keys($workflow->getTypePlugin()->getTransitions())); - $this->assertArrayEquals([], array_keys($workflow->getTypePlugin()->getTransitions([]))); + $this->assertSame([], $workflow->getTypePlugin()->getTransitions()); + $this->assertSame([], $workflow->getTypePlugin()->getTransitions([])); // By default states are ordered in the order added. $workflow @@ -406,29 +406,29 @@ public function testGetTransitions() { ->addTransition('a_a', 'A to A', ['a'], 'a'); // Transitions are stored in alphabetical key order in configuration. - $this->assertArrayEquals(['a_a', 'a_b'], array_keys($workflow->getTypePlugin()->getConfiguration()['transitions'])); + $this->assertEquals(['a_a', 'a_b'], array_keys($workflow->getTypePlugin()->getConfiguration()['transitions'])); // Ensure we're returning transition objects. $this->assertInstanceOf(Transition::class, $workflow->getTypePlugin()->getTransitions()['a_a']); // Passing in no IDs returns all transitions. - $this->assertArrayEquals(['a_b', 'a_a'], array_keys($workflow->getTypePlugin()->getTransitions())); + $this->assertEquals(['a_b', 'a_a'], array_keys($workflow->getTypePlugin()->getTransitions())); // The order of states is by weight. $workflow->getTypePlugin()->setTransitionWeight('a_a', -1); - $this->assertArrayEquals(['a_a', 'a_b'], array_keys($workflow->getTypePlugin()->getTransitions())); + $this->assertEquals(['a_a', 'a_b'], array_keys($workflow->getTypePlugin()->getTransitions())); // If all weights are equal it will fallback to labels. $workflow->getTypePlugin()->setTransitionWeight('a_a', 0); - $this->assertArrayEquals(['a_a', 'a_b'], array_keys($workflow->getTypePlugin()->getTransitions())); + $this->assertEquals(['a_a', 'a_b'], array_keys($workflow->getTypePlugin()->getTransitions())); $workflow->getTypePlugin()->setTransitionLabel('a_b', 'A B'); - $this->assertArrayEquals(['a_b', 'a_a'], array_keys($workflow->getTypePlugin()->getTransitions())); + $this->assertEquals(['a_b', 'a_a'], array_keys($workflow->getTypePlugin()->getTransitions())); // You can limit the states returned by passing in states IDs. - $this->assertArrayEquals(['a_a'], array_keys($workflow->getTypePlugin()->getTransitions(['a_a']))); + $this->assertEquals(['a_a'], array_keys($workflow->getTypePlugin()->getTransitions(['a_a']))); // An empty array does not load all states. - $this->assertArrayEquals([], array_keys($workflow->getTypePlugin()->getTransitions([]))); + $this->assertSame([], $workflow->getTypePlugin()->getTransitions([])); } /** diff --git a/core/tests/Drupal/Tests/Core/Batch/BatchBuilderTest.php b/core/tests/Drupal/Tests/Core/Batch/BatchBuilderTest.php index e0ac9089c5f2..64c0963004c2 100644 --- a/core/tests/Drupal/Tests/Core/Batch/BatchBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Batch/BatchBuilderTest.php @@ -172,7 +172,7 @@ public function testSetQueue() { ->setQueue('BatchName', '\Drupal\Core\Queue\Batch') ->toArray(); - $this->assertArrayEquals([ + $this->assertEquals([ 'name' => 'BatchName', 'class' => '\Drupal\Core\Queue\Batch', ], $batch['queue'], 'Batch queue has been set.'); diff --git a/core/tests/Drupal/Tests/Core/Config/NullStorageTest.php b/core/tests/Drupal/Tests/Core/Config/NullStorageTest.php index 6ffacdd78545..c281ebf4816e 100644 --- a/core/tests/Drupal/Tests/Core/Config/NullStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Config/NullStorageTest.php @@ -22,7 +22,7 @@ public function testCollection() { $this->assertInstanceOf(StorageInterface::class, $collection); $this->assertEquals(StorageInterface::DEFAULT_COLLECTION, $nullStorage->getCollectionName()); $this->assertEquals('test', $collection->getCollectionName()); - $this->assertArrayEquals([], $collection->getAllCollectionNames()); + $this->assertSame([], $collection->getAllCollectionNames()); } } diff --git a/core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php b/core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php index 0d140527297f..3b0f78077960 100644 --- a/core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/StorageCopyTraitTest.php @@ -28,7 +28,7 @@ public function testReplaceStorageContents($source_collections, $target_collecti $source = new MemoryStorage(); $target = new MemoryStorage(); // Empty the storage should be the same. - $this->assertArrayEquals(self::toArray($source), self::toArray($target)); + $this->assertEquals(self::toArray($source), self::toArray($target)); // When the source is populated, they are not the same any more. $this->generateRandomData($source, $source_collections); @@ -54,9 +54,9 @@ public function testReplaceStorageContents($source_collections, $target_collecti // After copying they are the same, this asserts that items not present // in the source get removed from the target. self::replaceStorageContents($source, $target); - $this->assertArrayEquals($source_data, self::toArray($target)); + $this->assertEquals($source_data, self::toArray($target)); // Assert that the copy method did indeed not change the source. - $this->assertArrayEquals($source_data, self::toArray($source)); + $this->assertEquals($source_data, self::toArray($source)); // Assert that the active collection is the same as the original source. $this->assertEquals($source_name, $source->getCollectionName()); @@ -154,7 +154,7 @@ public function testWithInvalidConfiguration() { $this->assertFalse($target->exists($name)); } else { - $this->assertArrayEquals($source->read($name), $target->read($name)); + $this->assertEquals($source->read($name), $target->read($name)); } } diff --git a/core/tests/Drupal/Tests/Core/Datetime/DateTest.php b/core/tests/Drupal/Tests/Core/Datetime/DateTest.php index 04f5eb1cb471..09c938f3b1ff 100644 --- a/core/tests/Drupal/Tests/Core/Datetime/DateTest.php +++ b/core/tests/Drupal/Tests/Core/Datetime/DateTest.php @@ -412,7 +412,7 @@ public function testFormattedDateDiff() { 'max-age' => $max_age, ], ]; - $this->assertArrayEquals($expected, $object->toRenderable()); + $this->assertEquals($expected, $object->toRenderable()); // Test retrieving the formatted time difference string. $this->assertEquals($string, $object->getString()); diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php index 74a9129c6dd4..3e1efe049e72 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php @@ -598,7 +598,7 @@ public function testGetFields($expected, $include_computed, $is_computed, $field ->willReturnArgument(0); // Exercise getFields(). - $this->assertArrayEquals( + $this->assertEquals( $expected, $mock_base->getFields($include_computed) ); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityConstraintViolationListTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityConstraintViolationListTest.php index 4afbfe18b6e6..cb427f6a20a6 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityConstraintViolationListTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityConstraintViolationListTest.php @@ -27,7 +27,7 @@ public function testFilterByFields() { $this->assertSame($constraint_list->filterByFields(['name']), $constraint_list); $this->assertCount(4, $constraint_list); - $this->assertArrayEquals(array_values(iterator_to_array($constraint_list)), [$violations[2], $violations[3], $violations[4], $violations[5]]); + $this->assertEquals(array_values(iterator_to_array($constraint_list)), [$violations[2], $violations[3], $violations[4], $violations[5]]); } /** @@ -42,7 +42,7 @@ public function testFilterByFieldsWithCompositeConstraints() { $this->assertSame($constraint_list->filterByFields(['name']), $constraint_list); $this->assertCount(4, $constraint_list); - $this->assertArrayEquals(array_values(iterator_to_array($constraint_list)), [$violations[2], $violations[3], $violations[4], $violations[5]]); + $this->assertEquals(array_values(iterator_to_array($constraint_list)), [$violations[2], $violations[3], $violations[4], $violations[5]]); } /** @@ -57,7 +57,7 @@ public function testFilterByFieldAccess() { $this->assertSame($constraint_list->filterByFieldAccess($account), $constraint_list); $this->assertCount(4, $constraint_list); - $this->assertArrayEquals(array_values(iterator_to_array($constraint_list)), [$violations[2], $violations[3], $violations[4], $violations[5]]); + $this->assertEquals(array_values(iterator_to_array($constraint_list)), [$violations[2], $violations[3], $violations[4], $violations[5]]); } /** @@ -72,7 +72,7 @@ public function testFilterByFieldAccessWithCompositeConstraint() { $this->assertSame($constraint_list->filterByFieldAccess($account), $constraint_list); $this->assertCount(4, $constraint_list); - $this->assertArrayEquals(array_values(iterator_to_array($constraint_list)), [$violations[2], $violations[3], $violations[4], $violations[5]]); + $this->assertEquals(array_values(iterator_to_array($constraint_list)), [$violations[2], $violations[3], $violations[4], $violations[5]]); } /** diff --git a/core/tests/Drupal/Tests/Core/Field/FieldItemListTest.php b/core/tests/Drupal/Tests/Core/Field/FieldItemListTest.php index fbd522230316..0fc8e36b993f 100644 --- a/core/tests/Drupal/Tests/Core/Field/FieldItemListTest.php +++ b/core/tests/Drupal/Tests/Core/Field/FieldItemListTest.php @@ -349,7 +349,7 @@ public function testDefaultValuesFormSubmit() { $field_list->expects($this->never()) ->method('getValue'); - $this->assertArrayEquals([], $field_list->defaultValuesFormSubmit([], $form, $form_state)); + $this->assertSame([], $field_list->defaultValuesFormSubmit([], $form, $form_state)); } } diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php index 975e3e4ece95..a8f61b45b096 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php @@ -212,7 +212,7 @@ public function testExistingDerivative() { $expected = $definitions['non_container_aware_discovery']; $expected['id'] = 'non_container_aware_discovery:test_discovery_1'; - $this->assertArrayEquals($expected, $returned_definitions['non_container_aware_discovery:test_discovery_1']); + $this->assertEquals($expected, $returned_definitions['non_container_aware_discovery:test_discovery_1']); } /** @@ -252,7 +252,7 @@ public function testSingleExistingDerivative() { $expected = $base_definition; $expected['id'] = 'non_container_aware_discovery:test_discovery_1'; - $this->assertArrayEquals($expected, $discovery->getDefinition('non_container_aware_discovery:test_discovery_1')); + $this->assertEquals($expected, $discovery->getDefinition('non_container_aware_discovery:test_discovery_1')); } } diff --git a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php index 81a1312198c0..9107cb90727a 100644 --- a/core/tests/Drupal/Tests/Core/Template/AttributeTest.php +++ b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php @@ -94,7 +94,7 @@ public function testSetAttribute() { // Test adding array to class. $attribute = new Attribute(); $attribute->setAttribute('class', ['kitten', 'cat']); - $this->assertArrayEquals(['kitten', 'cat'], $attribute['class']->value()); + $this->assertEquals(['kitten', 'cat'], $attribute['class']->value()); // Test adding boolean attributes. $attribute = new Attribute(); @@ -174,19 +174,19 @@ public function testAddClasses() { // Add one class on empty attribute. $attribute->addClass('banana'); - $this->assertArrayEquals(['banana'], $attribute['class']->value()); + $this->assertEquals(['banana'], $attribute['class']->value()); // Add one class. $attribute->addClass('aa'); - $this->assertArrayEquals(['banana', 'aa'], $attribute['class']->value()); + $this->assertEquals(['banana', 'aa'], $attribute['class']->value()); // Add multiple classes. $attribute->addClass('xx', 'yy'); - $this->assertArrayEquals(['banana', 'aa', 'xx', 'yy'], $attribute['class']->value()); + $this->assertEquals(['banana', 'aa', 'xx', 'yy'], $attribute['class']->value()); // Add an array of classes. $attribute->addClass(['red', 'green', 'blue']); - $this->assertArrayEquals(['banana', 'aa', 'xx', 'yy', 'red', 'green', 'blue'], $attribute['class']->value()); + $this->assertEquals(['banana', 'aa', 'xx', 'yy', 'red', 'green', 'blue'], $attribute['class']->value()); // Add an array of duplicate classes. $attribute->addClass(['red', 'green', 'blue'], ['aa', 'aa', 'banana'], 'yy'); @@ -218,7 +218,7 @@ public function testRemoveClasses() { $attribute->removeClass('gg'); $this->assertNotContains(['gg'], $attribute['class']->value()); // Test that the array index remains sequential. - $this->assertArrayEquals(['aa'], $attribute['class']->value()); + $this->assertEquals(['aa'], $attribute['class']->value()); $attribute->removeClass('aa'); $this->assertEmpty((string) $attribute); @@ -254,7 +254,7 @@ public function testChainAddRemoveClasses() { ->addClass(['apple', 'lime', 'grapefruit']) ->addClass(['banana']); $expected = ['example-class', 'blue', 'apple', 'lime', 'grapefruit', 'banana']; - $this->assertArrayEquals($expected, $attribute['class']->value(), 'Attributes chained'); + $this->assertEquals($expected, $attribute['class']->value(), 'Attributes chained'); } /** diff --git a/core/tests/Drupal/Tests/Core/Test/JUnitConverterTest.php b/core/tests/Drupal/Tests/Core/Test/JUnitConverterTest.php index ccb00ff82c9b..7ae45e2fe8f8 100644 --- a/core/tests/Drupal/Tests/Core/Test/JUnitConverterTest.php +++ b/core/tests/Drupal/Tests/Core/Test/JUnitConverterTest.php @@ -49,7 +49,7 @@ public function testXmlToRowsWithErrors() { public function testXmlToRowsEmptyFile() { // File system with an empty XML file. vfsStream::setup('junit_test', NULL, ['empty.xml' => '']); - $this->assertArrayEquals([], JUnitConverter::xmlToRows(23, vfsStream::url('junit_test/empty.xml'))); + $this->assertSame([], JUnitConverter::xmlToRows(23, vfsStream::url('junit_test/empty.xml'))); } /** @@ -76,7 +76,7 @@ public function testXmlElementToRows() { 'file' => '/Users/paul/projects/drupal/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php', ], ]; - $this->assertArrayEquals($simpletest, JUnitConverter::xmlElementToRows(23, new \SimpleXMLElement($junit))); + $this->assertEquals($simpletest, JUnitConverter::xmlElementToRows(23, new \SimpleXMLElement($junit))); } /** @@ -96,7 +96,7 @@ public function testConvertTestCaseToSimpletestRow() { 'line' => 108, 'file' => '/Users/paul/projects/drupal/core/modules/simpletest/tests/src/Unit/TestDiscoveryTest.php', ]; - $this->assertArrayEquals($simpletest, JUnitConverter::convertTestCaseToSimpletestRow(23, new \SimpleXMLElement($junit))); + $this->assertEquals($simpletest, JUnitConverter::convertTestCaseToSimpletestRow(23, new \SimpleXMLElement($junit))); } } diff --git a/core/tests/Drupal/Tests/Core/Test/RunTests/TestFileParserTest.php b/core/tests/Drupal/Tests/Core/Test/RunTests/TestFileParserTest.php index 4086368f276d..21a38e9e11d1 100644 --- a/core/tests/Drupal/Tests/Core/Test/RunTests/TestFileParserTest.php +++ b/core/tests/Drupal/Tests/Core/Test/RunTests/TestFileParserTest.php @@ -81,11 +81,11 @@ public function testParseContents($expected, $contents) { */ public function testGetTestListFromFile() { $parser = new TestFileParser(); - $this->assertArrayEquals( + $this->assertEquals( ['Drupal\Tests\Core\Test\RunTests\TestFileParserTest'], $parser->getTestListFromFile(__FILE__) ); - $this->assertArrayEquals( + $this->assertEquals( ['Drupal\KernelTests\Core\Datetime\Element\TimezoneTest'], $parser->getTestListFromFile(__DIR__ . '/../../../../KernelTests/Core/Datetime/Element/TimezoneTest.php') ); diff --git a/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php b/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php index c10c484647f9..41e95e428347 100644 --- a/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php +++ b/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php @@ -190,7 +190,7 @@ public function testPostProcessExtension($defined_functions, $hooks, $expected) $reflection_method->setAccessible(TRUE); $reflection_method->invokeArgs($this->registry, [&$hooks, $theme->reveal()]); - $this->assertArrayEquals($expected, $hooks); + $this->assertEquals($expected, $hooks); } /** diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index 55978ba413c8..3a4e035ce060 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -87,8 +87,14 @@ protected function getRandomGenerator() { * @param array $expected * @param array $actual * @param string $message + * + * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use + * ::assertEquals, ::assertEqualsCanonicalizing, or ::assertSame instead. + * + * @see https://www.drupal.org/node/3136304 */ protected function assertArrayEquals(array $expected, array $actual, $message = NULL) { + @trigger_error(__METHOD__ . "() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use ::assertEquals(), ::assertEqualsCanonicalizing(), or ::assertSame() instead. See https://www.drupal.org/node/3136304", E_USER_DEPRECATED); ksort($expected); ksort($actual); $this->assertEquals($expected, $actual, !empty($message) ? $message : ''); diff --git a/core/tests/Drupal/Tests/UnitTestCaseTest.php b/core/tests/Drupal/Tests/UnitTestCaseTest.php new file mode 100644 index 000000000000..d01264de6616 --- /dev/null +++ b/core/tests/Drupal/Tests/UnitTestCaseTest.php @@ -0,0 +1,22 @@ +<?php + +namespace Drupal\Tests; + +/** + * Tests for the UnitTestCase class. + * + * @group Tests + */ +class UnitTestCaseTest extends UnitTestCase { + + /** + * Tests deprecation of the ::assertArrayEquals method. + * + * @group legacy + * @expectedDeprecation Drupal\Tests\UnitTestCase::assertArrayEquals() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use ::assertEquals(), ::assertEqualsCanonicalizing(), or ::assertSame() instead. See https://www.drupal.org/node/3136304 + */ + public function testAssertArrayEquals() { + $this->assertArrayEquals([], []); + } + +} -- GitLab