From 850fd391456df663b092e1921ab63a799f7d0ae4 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Wed, 15 Mar 2023 09:24:37 -0700 Subject: [PATCH 01/22] php 8.1.... --- .circleci/config.yml | 2 +- composer.json | 8 ++++---- .../metastore/tests/src/Unit/Reference/ReferencerTest.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 42855d5bc6..579d637f2a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -33,7 +33,7 @@ commands: which ddev ddev --version ddev config --project-name test-$CIRCLE_WORKFLOW_JOB_ID --project-type drupal9 --docroot docroot --create-docroot - ddev get https://github.com/GetDKAN/dkan-ddev-addon/archive/refs/heads/main.tar.gz + ddev get https://github.com/GetDKAN/dkan-ddev-addon/archive/refs/heads/php81.tar.gz ddev restart ddev status ddev dkan-init --force diff --git a/composer.json b/composer.json index c04f226e21..24afc9234c 100644 --- a/composer.json +++ b/composer.json @@ -14,16 +14,16 @@ "drupal/views_bulk_operations": "^4.0", "ext-json": "*", "ezyang/htmlpurifier" : "^4.11", - "fmizzell/maquina": "^1.1.0", + "fmizzell/maquina": "dev-master#e5772c08fd1e6e3de5e5b21f89de20f385ff1adb", "getdkan/contracts": "^1.0.0", - "getdkan/csv-parser": "^1.2.3", - "getdkan/file-fetcher" : "4.2.0", + "getdkan/csv-parser": "dev-support-php81", + "getdkan/file-fetcher" : "^4.2.1", "getdkan/harvest": "^1.0.0", "getdkan/json-schema-provider": "^0.1.2", "getdkan/locker": "^1.1.0", "getdkan/procrastinator": "^4.0.0", "getdkan/rooted-json-data": "^0.1", - "getdkan/sql-parser": "^2.0.0", + "getdkan/sql-parser": "dev-support-php81", "guzzlehttp/guzzle" : "^6.5.8 || ^7.4.5", "ilbee/csv-response": "^1.1.1", "m1x0n/opis-json-schema-error-presenter": "^0.5.3", diff --git a/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php b/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php index 2b4871374f..be4080e70f 100644 --- a/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php +++ b/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php @@ -23,7 +23,7 @@ use Drupal\node\Entity\Node; use Drupal\node\NodeStorage; -use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Exception\ConnectException; use MockChain\Chain; use MockChain\Options; use PHPUnit\Framework\TestCase; @@ -452,7 +452,7 @@ public function getMimeType() { return ReferencerTest::MIME_TYPE; } $this->assertEquals(self::MIME_TYPE, $container_chain->getStoredInput('resource')[0]->getMimeType(), 'Unable to fetch MIME type for remote file'); // Test Mime Type detection on a invalid remote file path. $data = $this->getData('http://invalid'); - $this->expectException(RequestException::class); + $this->expectException(ConnectException::class); $referencer->reference($data); } From 26eb168b0688299913f32186abb477ff93ec1a65 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Wed, 15 Mar 2023 13:30:53 -0700 Subject: [PATCH 02/22] ever closer --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 24afc9234c..d928f4ec31 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "drupal/views_bulk_operations": "^4.0", "ext-json": "*", "ezyang/htmlpurifier" : "^4.11", - "fmizzell/maquina": "dev-master#e5772c08fd1e6e3de5e5b21f89de20f385ff1adb", + "fmizzell/maquina": "^1.1.1", "getdkan/contracts": "^1.0.0", "getdkan/csv-parser": "dev-support-php81", "getdkan/file-fetcher" : "^4.2.1", @@ -27,7 +27,7 @@ "guzzlehttp/guzzle" : "^6.5.8 || ^7.4.5", "ilbee/csv-response": "^1.1.1", "m1x0n/opis-json-schema-error-presenter": "^0.5.3", - "neitanod/forceutf8": "~2.0", + "fylax/forceutf8": "~3.0", "npm-asset/select2": "^4.0", "oomphinc/composer-installers-extender": "^2.0", "ramsey/uuid" : "^3.8.0", From 890181701eac8437929cbcbd398edd83b25af63e Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Wed, 15 Mar 2023 15:49:27 -0700 Subject: [PATCH 03/22] csv-parser 1.3.0 and sql-parser 2.1.0 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d928f4ec31..d4aabd1497 100644 --- a/composer.json +++ b/composer.json @@ -16,14 +16,14 @@ "ezyang/htmlpurifier" : "^4.11", "fmizzell/maquina": "^1.1.1", "getdkan/contracts": "^1.0.0", - "getdkan/csv-parser": "dev-support-php81", + "getdkan/csv-parser": "^1.3.0", "getdkan/file-fetcher" : "^4.2.1", "getdkan/harvest": "^1.0.0", "getdkan/json-schema-provider": "^0.1.2", "getdkan/locker": "^1.1.0", "getdkan/procrastinator": "^4.0.0", "getdkan/rooted-json-data": "^0.1", - "getdkan/sql-parser": "dev-support-php81", + "getdkan/sql-parser": "^2.1.0", "guzzlehttp/guzzle" : "^6.5.8 || ^7.4.5", "ilbee/csv-response": "^1.1.1", "m1x0n/opis-json-schema-error-presenter": "^0.5.3", From f3673c91e39548ed8a64f418070fbd495c4a3696 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 17 Mar 2023 14:54:28 -0700 Subject: [PATCH 04/22] return type --- modules/common/src/Storage/AbstractDatabaseTable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/common/src/Storage/AbstractDatabaseTable.php b/modules/common/src/Storage/AbstractDatabaseTable.php index 9d94c88d21..b028f191b9 100644 --- a/modules/common/src/Storage/AbstractDatabaseTable.php +++ b/modules/common/src/Storage/AbstractDatabaseTable.php @@ -173,7 +173,7 @@ public function storeMultiple(array $data) { /** * Private. */ - protected function getNonSerialFields() { + protected function getNonSerialFields(): array { $fields = []; foreach ($this->schema['fields'] as $field => $info) { if ($info['type'] != 'serial') { From f5e2fd2d86001c492ef3c47f70aedd28fdc80b7b Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 17 Mar 2023 15:17:26 -0700 Subject: [PATCH 05/22] rector common/tests/ --- modules/common/src/Storage/AbstractDatabaseTable.php | 2 +- modules/common/tests/src/Functional/DkanDocsTest.php | 2 +- .../common/tests/src/Kernel/ConfigFormTestBase.php | 1 + .../tests/src/Unit/Commands/CommonCommandsTest.php | 11 ++++------- .../common/tests/src/Unit/Storage/JobStoreTest.php | 4 ++-- .../tests/src/Unit/Storage/QueryDataProvider.php | 8 ++++---- .../tests/src/Unit/Storage/SelectFactoryTest.php | 2 +- 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/modules/common/src/Storage/AbstractDatabaseTable.php b/modules/common/src/Storage/AbstractDatabaseTable.php index b028f191b9..9d94c88d21 100644 --- a/modules/common/src/Storage/AbstractDatabaseTable.php +++ b/modules/common/src/Storage/AbstractDatabaseTable.php @@ -173,7 +173,7 @@ public function storeMultiple(array $data) { /** * Private. */ - protected function getNonSerialFields(): array { + protected function getNonSerialFields() { $fields = []; foreach ($this->schema['fields'] as $field => $info) { if ($info['type'] != 'serial') { diff --git a/modules/common/tests/src/Functional/DkanDocsTest.php b/modules/common/tests/src/Functional/DkanDocsTest.php index 5b475e8cbb..3b704decf3 100644 --- a/modules/common/tests/src/Functional/DkanDocsTest.php +++ b/modules/common/tests/src/Functional/DkanDocsTest.php @@ -36,7 +36,7 @@ public function testGetCompleteYaml() { $controller = $this->getController(); $response = $controller->getComplete('yaml'); $this->assertEquals(200, $response->getStatusCode()); - $data = Yaml::decode($response->getContent(), TRUE); + $data = Yaml::decode($response->getContent()); // Basic auth is included. $this->assertTrue(isset($data["components"]["securitySchemes"]["basic_auth"])); diff --git a/modules/common/tests/src/Kernel/ConfigFormTestBase.php b/modules/common/tests/src/Kernel/ConfigFormTestBase.php index 96e18fa087..6bad2c3915 100644 --- a/modules/common/tests/src/Kernel/ConfigFormTestBase.php +++ b/modules/common/tests/src/Kernel/ConfigFormTestBase.php @@ -52,6 +52,7 @@ abstract public function provideFormData(): array; * @dataProvider provideFormData */ public function testConfigForm(array $form_values) { + $values = []; // Programmatically submit the given values. foreach ($form_values as $form_key => $data) { $values[$form_key] = $data['#value']; diff --git a/modules/common/tests/src/Unit/Commands/CommonCommandsTest.php b/modules/common/tests/src/Unit/Commands/CommonCommandsTest.php index 8bd4f4195a..b382527337 100644 --- a/modules/common/tests/src/Unit/Commands/CommonCommandsTest.php +++ b/modules/common/tests/src/Unit/Commands/CommonCommandsTest.php @@ -16,16 +16,13 @@ class CommonCommandsTest extends TestCase { * */ public function testDatasetInfo() { + $data = ['uuid' => 'foo']; + $this->expectOutputString(json_encode($data, JSON_PRETTY_PRINT)); $datasetInfo = (new Chain($this)) - ->add(DatasetInfo::class, 'gather', ['uuid' => 'foo']); - + ->add(DatasetInfo::class, 'gather', $data); $drush = new CommonCommands($datasetInfo->getMock()); - $result = $drush->datasetInfo('foo'); - - $expected = json_encode(['uuid' => 'foo'], JSON_PRETTY_PRINT); - - $this->expectOutputString($expected, $result); + $drush->datasetInfo('foo'); } } diff --git a/modules/common/tests/src/Unit/Storage/JobStoreTest.php b/modules/common/tests/src/Unit/Storage/JobStoreTest.php index 38d20e8622..180a1be707 100644 --- a/modules/common/tests/src/Unit/Storage/JobStoreTest.php +++ b/modules/common/tests/src/Unit/Storage/JobStoreTest.php @@ -60,7 +60,7 @@ public function testRetrieve() { ->add(StatementWrapper::class, 'fetchAll', $fieldInfo); $jobStore = new JobStore(FileFetcher::class, $chain->getMock()); - $this->assertEquals($job_data, $jobStore->retrieve("1", FileFetcher::class)); + $this->assertEquals($job_data, $jobStore->retrieve("1")); } /** @@ -153,7 +153,7 @@ public function testRemove() { $jobStore = new JobStore(FileFetcher::class, $connection); - $this->assertEquals("", $jobStore->remove("1", FileFetcher::class)); + $this->assertEquals("", $jobStore->remove("1")); } /** diff --git a/modules/common/tests/src/Unit/Storage/QueryDataProvider.php b/modules/common/tests/src/Unit/Storage/QueryDataProvider.php index 03e4398b6d..f2d11b452c 100644 --- a/modules/common/tests/src/Unit/Storage/QueryDataProvider.php +++ b/modules/common/tests/src/Unit/Storage/QueryDataProvider.php @@ -16,10 +16,10 @@ */ class QueryDataProvider { - const QUERY_OBJECT = 1; - const SQL = 2; - const EXCEPTION = 3; - const VALUES = 4; + public const QUERY_OBJECT = 1; + public const SQL = 2; + public const EXCEPTION = 3; + public const VALUES = 4; /** * diff --git a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php index 45b4da1392..a6f5168813 100644 --- a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php +++ b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php @@ -13,7 +13,7 @@ * */ class SelectFactoryTest extends TestCase { - private $query; + private Query $query; /** * SelectFactory object. From a74d4e6d8df45aad708ec7f70b5dc84b487f82fc Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 17 Mar 2023 15:28:52 -0700 Subject: [PATCH 06/22] rector datastore/tests/ --- modules/datastore/tests/src/Mock/Container.php | 9 +++++---- .../src/Unit/Controller/QueryControllerTest.php | 2 ++ .../Unit/Controller/QueryDownloadControllerTest.php | 2 ++ .../tests/src/Unit/Form/DashboardFormTest.php | 12 ++++++------ .../src/Unit/Plugin/QueueWorker/ImportJobTest.php | 2 +- .../tests/src/Unit/Plugin/QueueWorker/ImportTest.php | 2 +- .../datastore/tests/src/Unit/Service/ImportTest.php | 2 +- .../tests/src/Unit/Service/ResourceLocalizerTest.php | 2 +- 8 files changed, 19 insertions(+), 14 deletions(-) diff --git a/modules/datastore/tests/src/Mock/Container.php b/modules/datastore/tests/src/Mock/Container.php index 52db31c52f..f2dbb141cb 100644 --- a/modules/datastore/tests/src/Mock/Container.php +++ b/modules/datastore/tests/src/Mock/Container.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\datastore\Unit\Mock; +use Drupal\Core\Queue\QueueInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\Schema; @@ -23,11 +24,11 @@ */ class Container { - private $testCase; + private TestCase $testCase; - private $jobStoreData; + private \stdClass $jobStoreData; private $tableName; - private $noNode = FALSE; + private bool $noNode = FALSE; /** * @@ -104,7 +105,7 @@ private function getQueueFactoryMock() { * Private. */ private function getQueueMock() { - $mock = $this->testCase->getMockBuilder("\Drupal\Core\Queue\QueueInterface") + $mock = $this->testCase->getMockBuilder('\\' . QueueInterface::class) ->disableOriginalConstructor() ->setMethods(['createItem']) ->getMockForAbstractClass(); diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index 4efb90e677..f753434bc1 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -358,6 +358,7 @@ public function testDistributionIndexWrongIdentifier() { * */ public function testDistributionIndexWrongIndex() { + $info = []; $data = json_encode([ "results" => TRUE, ]); @@ -373,6 +374,7 @@ public function testDistributionIndexWrongIndex() { * */ public function testDistributionIndex() { + $info = []; $data = json_encode([ "results" => TRUE, ]); diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index 31e25604f7..c8411614b9 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -99,6 +99,7 @@ public function testStreamedQueryCsv() { } public function queryResultReformatted($data){ + $streamedCsv = null; $request = $this->mockRequest($data); $dataDictionaryFields = [ 'name' => 'date', @@ -469,6 +470,7 @@ public function mockRequest($data = '') { * A database table storage class useable for datastore queries. */ public function mockDatastoreTable($connection, $id, $csvFile, $fields) { + $createFields = []; foreach ($fields as $name => $field) { $types[] = $field['type']; $notNull = $field['not null'] ?? FALSE; diff --git a/modules/datastore/tests/src/Unit/Form/DashboardFormTest.php b/modules/datastore/tests/src/Unit/Form/DashboardFormTest.php index 4b0e30363e..882a88fe11 100644 --- a/modules/datastore/tests/src/Unit/Form/DashboardFormTest.php +++ b/modules/datastore/tests/src/Unit/Form/DashboardFormTest.php @@ -113,7 +113,7 @@ public function testBuildTableRowsWithHarvestIdFilter() { \Drupal::setContainer($container); $form = DashboardForm::create($container)->buildForm([], new FormState()); - $this->assertEquals(1, count($form['table']['#rows'])); + $this->assertCount(1, $form['table']['#rows']); $this->assertEquals('dataset-1', $form['table']['#rows'][0][0]['data']['#uuid']); $this->assertEquals('Dataset 1', $form['table']['#rows'][0][0]['data']['#title']); $this->assertEquals('NEW', $form['table']['#rows'][0][2]['data']); @@ -148,7 +148,7 @@ public function testBuildTableRowsWithUuidFilter() { \Drupal::setContainer($container); $form = DashboardForm::create($container)->buildForm([], new FormState()); - $this->assertEquals(1, count($form['table']['#rows'])); + $this->assertCount(1, $form['table']['#rows']); $this->assertEquals('test', $form['table']['#rows'][0][0]['data']['#uuid']); $this->assertEquals('Title', $form['table']['#rows'][0][0]['data']['#title']); $this->assertEquals('N/A', $form['table']['#rows'][0][2]['data']); @@ -215,7 +215,7 @@ public function testBuildTableRowsWithAllDatasets() { $form = DashboardForm::create($container->getMock())->buildForm([], new FormState()); // Assert that there are both datasets: harvested and non-harvested. - $this->assertEquals(2, count($form['table']['#rows'])); + $this->assertCount(2, $form['table']['#rows']); $this->assertEquals('dataset-1', $form['table']['#rows'][0][0]['data']['#uuid']); $this->assertEquals('Dataset 1', $form['table']['#rows'][0][0]['data']['#title']); @@ -296,12 +296,12 @@ public function testBuildTableRowsDatasetMultipleDistribution() { \Drupal::setContainer($container); $form = DashboardForm::create($container)->buildForm([], new FormState()); - $this->assertEquals(2, count($form['table']['#rows'])); + $this->assertCount(2, $form['table']['#rows']); // First row has six columns and rowspan on first two - $this->assertEquals(6, count($form['table']['#rows'][0])); + $this->assertCount(6, $form['table']['#rows'][0]); $this->assertEquals(2, $form['table']['#rows'][0][1]['rowspan']); // The second row has only three columns. - $this->assertEquals(3, count($form['table']['#rows'][1])); + $this->assertCount(3, $form['table']['#rows'][1]); $this->assertEquals('dist-1', $form['table']['#rows'][0][3]['data']['#uuid']); $this->assertEquals('dist-2', $form['table']['#rows'][1][0]['data']['#uuid']); diff --git a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php index 5073538644..6228857666 100644 --- a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php +++ b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php @@ -16,7 +16,7 @@ */ class ImportJobTest extends TestCase { - private $database; + private ?TestMemStorage $database = null; /** * This method is called before each test. diff --git a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportTest.php b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportTest.php index beaa468cac..fede1ed617 100644 --- a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportTest.php +++ b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportTest.php @@ -25,7 +25,7 @@ */ class ImportTest extends TestCase { - private $data = [ + private array $data = [ 'data' => [ 'identifier' => '12345', 'version' => '23456', diff --git a/modules/datastore/tests/src/Unit/Service/ImportTest.php b/modules/datastore/tests/src/Unit/Service/ImportTest.php index 292ec8d379..c34b546f01 100644 --- a/modules/datastore/tests/src/Unit/Service/ImportTest.php +++ b/modules/datastore/tests/src/Unit/Service/ImportTest.php @@ -35,7 +35,7 @@ class ImportTest extends TestCase { * * @var string */ - const HOST = 'http://h-o.st'; + public const HOST = 'http://h-o.st'; /** * diff --git a/modules/datastore/tests/src/Unit/Service/ResourceLocalizerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceLocalizerTest.php index ff5ad9d269..c7d2233446 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceLocalizerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceLocalizerTest.php @@ -29,7 +29,7 @@ class ResourceLocalizerTest extends TestCase { * * @var string */ - const HOST = 'http://example.com'; + public const HOST = 'http://example.com'; /** * From f3c7703b0413af288ca3dbc5a62accbb5d6d3167 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 17 Mar 2023 15:33:24 -0700 Subject: [PATCH 07/22] rector frontend/tests --- .../frontend/tests/src/Unit/Controller/ControllerPageTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/frontend/tests/src/Unit/Controller/ControllerPageTest.php b/modules/frontend/tests/src/Unit/Controller/ControllerPageTest.php index 2ff2a33349..d28a5c5b09 100644 --- a/modules/frontend/tests/src/Unit/Controller/ControllerPageTest.php +++ b/modules/frontend/tests/src/Unit/Controller/ControllerPageTest.php @@ -14,10 +14,8 @@ class ControllerPageTest extends TestCase { /** * Cache max age config value. - * - * @var int */ - private $cacheMaxAge; + private int $cacheMaxAge; protected function setUp(): void { parent::setUp(); From 825bba4f57c783eb3b124691226ba458b15bed61 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 17 Mar 2023 15:40:10 -0700 Subject: [PATCH 08/22] rector harvest/tests --- .../harvest/tests/src/Unit/ServiceTest.php | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/modules/harvest/tests/src/Unit/ServiceTest.php b/modules/harvest/tests/src/Unit/ServiceTest.php index 8ccfb868b5..5bf6de0500 100644 --- a/modules/harvest/tests/src/Unit/ServiceTest.php +++ b/modules/harvest/tests/src/Unit/ServiceTest.php @@ -29,7 +29,7 @@ class ServiceTest extends TestCase { use ServiceCheckTrait; - private $storageFactory; + private ?FactoryInterface $storageFactory = null; /** * @@ -73,7 +73,7 @@ public function test() { $result = $service->runHarvest('test_plan'); $this->assertEquals("SUCCESS", $result['status']['extract']); - $this->assertEquals(2, count($result['status']['extracted_items_ids'])); + $this->assertCount(2, $result['status']['extracted_items_ids']); $this->assertEquals(json_encode(["NEW", "NEW"]), json_encode(array_values($result['status']['load']))); $storedObject = $this->getStorageFactory()->getInstance('harvest_test_plan_items')->retrieve("cedcd327-4e5d-43f9-8eb1-c11850fa7c55"); @@ -85,7 +85,7 @@ public function test() { $result = $service->runHarvest('test_plan'); $this->assertEquals("SUCCESS", $result['status']['extract']); - $this->assertEquals(2, count($result['status']['extracted_items_ids'])); + $this->assertCount(2, $result['status']['extracted_items_ids']); $this->assertEquals(json_encode(["UNCHANGED", "UNCHANGED"]), json_encode(array_values($result['status']['load']))); // Run harvest with changes. @@ -95,7 +95,7 @@ public function test() { $result = $service->runHarvest('test_plan'); $this->assertEquals("SUCCESS", $result['status']['extract']); - $this->assertEquals(2, count($result['status']['extracted_items_ids'])); + $this->assertCount(2, $result['status']['extracted_items_ids']); $this->assertEquals(json_encode(["UPDATED", "UNCHANGED"]), json_encode(array_values($result['status']['load']))); $storedObject = $this->getStorageFactory()->getInstance('harvest_test_plan_items')->retrieve("cedcd327-4e5d-43f9-8eb1-c11850fa7c55"); @@ -112,12 +112,12 @@ public function test() { 'harvest_test_plan_runs', ]; foreach ($storageTypes as $storageId) { - $this->assertEquals(0, count($this->getStorageFactory()->getInstance($storageId)->retrieveAll())); + $this->assertCount(0, $this->getStorageFactory()->getInstance($storageId)->retrieveAll()); } // Deregister harvest. $service->deregisterHarvest('test_plan'); - $this->assertEquals(0, count($this->getStorageFactory()->getInstance('harvest_plans')->retrieveAll())); + $this->assertCount(0, $this->getStorageFactory()->getInstance('harvest_plans')->retrieveAll()); } /** @@ -166,25 +166,16 @@ public function testGetHarvestRunInfo() { private function getStorageFactory() { if (!isset($this->storageFactory)) { $this->storageFactory = new class() implements FactoryInterface { - private $stores = []; + private array $stores = []; - /** - * Getter. - */ public function getInstance(string $identifier, array $config = []) { if (!isset($this->stores[$identifier])) { $this->stores[$identifier] = new class() extends Memory { - /** - * - */ public function retrieveAll(): array { return array_keys(parent::retrieveAll()); } - /** - * - */ public function destruct() { $this->storage = []; } From da86ae686de4de7dab0af10c0057855ae7c5b20d Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 17 Mar 2023 15:46:33 -0700 Subject: [PATCH 09/22] rector json_form_wiget/tests/ --- modules/json_form_widget/tests/src/Unit/StringHelperTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/json_form_widget/tests/src/Unit/StringHelperTest.php b/modules/json_form_widget/tests/src/Unit/StringHelperTest.php index a3473e5bf0..d9dbab8534 100644 --- a/modules/json_form_widget/tests/src/Unit/StringHelperTest.php +++ b/modules/json_form_widget/tests/src/Unit/StringHelperTest.php @@ -20,6 +20,7 @@ class StringHelperTest extends TestCase { * Test. */ public function testEmailValidate() { + $element = []; $options = (new Options()) ->add('string_translation', TranslationManager::class) ->add('email.validator', EmailValidator::class) From b2a29fcd738fcc86a057d431cc15e49d0e40b063 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 17 Mar 2023 15:56:04 -0700 Subject: [PATCH 10/22] rector metastore/tests/ --- .../tests/src/Functional/Api1/DatasetItemTest.php | 4 ++-- .../tests/src/Functional/Api1/DatasetRevisionTest.php | 8 ++++---- .../tests/src/Functional/DatasetSpecificDocsTest.php | 2 +- .../metastore/tests/src/Functional/OnPreReferenceTest.php | 2 +- .../tests/src/Functional/Storage/NodeDataTest.php | 8 ++++---- modules/metastore/tests/src/Unit/DatabaseTableMock.php | 4 ++-- .../metastore/tests/src/Unit/MetastoreSubscriberTest.php | 2 +- .../metastore/tests/src/Unit/Reference/ReferencerTest.php | 8 ++++---- modules/metastore/tests/src/Unit/SchemaRetrieverTest.php | 2 +- modules/metastore/tests/src/Unit/Storage/DataTest.php | 4 ++-- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/modules/metastore/tests/src/Functional/Api1/DatasetItemTest.php b/modules/metastore/tests/src/Functional/Api1/DatasetItemTest.php index 58da82893d..44afca3752 100644 --- a/modules/metastore/tests/src/Functional/Api1/DatasetItemTest.php +++ b/modules/metastore/tests/src/Functional/Api1/DatasetItemTest.php @@ -19,7 +19,7 @@ public function testList() { ->get->responses->{"200"}->content->{"application/json"}->schema; $response = $this->http->request('GET', $this->endpoint); $responseBody = json_decode($response->getBody()); - $this->assertEquals(2, count($responseBody)); + $this->assertCount(2, $responseBody); $this->assertTrue(is_object($responseBody[1])); $this->assertJsonIsValid($responseSchema, $responseBody); } @@ -131,4 +131,4 @@ private function assertDatasetGet($dataset) { $this->assertEquals($dataset, $responseBody); } -} \ No newline at end of file +} diff --git a/modules/metastore/tests/src/Functional/Api1/DatasetRevisionTest.php b/modules/metastore/tests/src/Functional/Api1/DatasetRevisionTest.php index 49cf40a389..b9cba62cc4 100644 --- a/modules/metastore/tests/src/Functional/Api1/DatasetRevisionTest.php +++ b/modules/metastore/tests/src/Functional/Api1/DatasetRevisionTest.php @@ -28,7 +28,7 @@ public function testList() { ]); $responseBody = json_decode($response->getBody()); $this->assertEquals(200, $response->getStatusCode()); - $this->assertEquals(2, count($responseBody)); + $this->assertCount(2, $responseBody); $this->assertTrue($responseBody[0]->identifier > $responseBody[1]->identifier); $this->assertTrue($responseBody[0]->published); @@ -146,7 +146,7 @@ public function testPost() { RequestOptions::AUTH => $this->auth, ]); $responseBody = json_decode($response->getBody()); - $this->assertEquals($count, count($responseBody)); + $this->assertEquals($count, is_countable($responseBody) ? count($responseBody) : 0); // Confirm dataset visibility matches expected. $expectedCode = $public ? 200 : 404; @@ -166,7 +166,7 @@ public function testPost() { RequestOptions::AUTH => $this->auth, ]); $responseBody = json_decode($response->getBody()); - $this->assertEquals($count, count($responseBody)); + $this->assertEquals($count, is_countable($responseBody) ? count($responseBody) : 0); // Test a bad dataset ID. $newRevision = (object) [ @@ -185,7 +185,7 @@ public function testPost() { RequestOptions::AUTH => $this->auth, ]); $responseBody = json_decode($response->getBody()); - $this->assertEquals($count, count($responseBody)); + $this->assertEquals($count, is_countable($responseBody) ? count($responseBody) : 0); } diff --git a/modules/metastore/tests/src/Functional/DatasetSpecificDocsTest.php b/modules/metastore/tests/src/Functional/DatasetSpecificDocsTest.php index d8b7302f70..f2d6199646 100644 --- a/modules/metastore/tests/src/Functional/DatasetSpecificDocsTest.php +++ b/modules/metastore/tests/src/Functional/DatasetSpecificDocsTest.php @@ -11,7 +11,7 @@ class DatasetSpecificDocsTest extends ExistingSiteBase { use CleanUp; - private $downloadUrl = "https://dkan-default-content-files.s3.amazonaws.com/phpunit/district_centerpoints_small.csv"; + private string $downloadUrl = "https://dkan-default-content-files.s3.amazonaws.com/phpunit/district_centerpoints_small.csv"; /** * diff --git a/modules/metastore/tests/src/Functional/OnPreReferenceTest.php b/modules/metastore/tests/src/Functional/OnPreReferenceTest.php index 8c88db05b3..ab5b3b7eaa 100644 --- a/modules/metastore/tests/src/Functional/OnPreReferenceTest.php +++ b/modules/metastore/tests/src/Functional/OnPreReferenceTest.php @@ -11,7 +11,7 @@ class OnPreReferenceTest extends ExistingSiteBase { use CleanUp; - private $downloadUrl = "https://dkan-default-content-files.s3.amazonaws.com/phpunit/district_centerpoints_small.csv"; + private string $downloadUrl = "https://dkan-default-content-files.s3.amazonaws.com/phpunit/district_centerpoints_small.csv"; /** * diff --git a/modules/metastore/tests/src/Functional/Storage/NodeDataTest.php b/modules/metastore/tests/src/Functional/Storage/NodeDataTest.php index f52617d32b..ce5e3009b4 100644 --- a/modules/metastore/tests/src/Functional/Storage/NodeDataTest.php +++ b/modules/metastore/tests/src/Functional/Storage/NodeDataTest.php @@ -50,16 +50,16 @@ public function testStorageRetrieveMethods() { $allPublished = $datasetStorage->retrieveAll(); $datasetData = json_decode($allPublished[0]); $this->assertEquals("123", $datasetData->identifier); - $this->assertEquals(1, count($allPublished)); + $this->assertCount(1, $allPublished); $all = $datasetStorage->retrieveAll(NULL, NULL, TRUE); - $this->assertEquals(2, count($all)); + $this->assertCount(2, $all); $rangeUnpublished = $datasetStorage->retrieveAll(0, 1, TRUE); - $this->assertEquals(1, count($rangeUnpublished)); + $this->assertCount(1, $rangeUnpublished); $allIds = $datasetStorage->retrieveIds(NULL, NULL, TRUE); - $this->assertEquals(2, count($allIds)); + $this->assertCount(2, $allIds); $this->assertEquals("456", $allIds[1]); $this->expectException(MissingObjectException::class); diff --git a/modules/metastore/tests/src/Unit/DatabaseTableMock.php b/modules/metastore/tests/src/Unit/DatabaseTableMock.php index 8bb81d0b3c..475387d95b 100644 --- a/modules/metastore/tests/src/Unit/DatabaseTableMock.php +++ b/modules/metastore/tests/src/Unit/DatabaseTableMock.php @@ -9,8 +9,8 @@ * */ class DatabaseTableMock implements DatabaseTableInterface { - private $id = 0; - private $store = []; + private int $id = 0; + private array $store = []; public function primaryKey() { return 'id'; diff --git a/modules/metastore/tests/src/Unit/MetastoreSubscriberTest.php b/modules/metastore/tests/src/Unit/MetastoreSubscriberTest.php index b261d102e7..42b7533f15 100644 --- a/modules/metastore/tests/src/Unit/MetastoreSubscriberTest.php +++ b/modules/metastore/tests/src/Unit/MetastoreSubscriberTest.php @@ -34,7 +34,7 @@ class MetastoreSubscriberTest extends TestCase { * * @var string */ - const HOST = 'http://h-o.st'; + public const HOST = 'http://h-o.st'; /** * The ValidMetadataFactory class used for testing. diff --git a/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php b/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php index be4080e70f..ffeb868e73 100644 --- a/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php +++ b/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php @@ -38,23 +38,23 @@ class ReferencerTest extends TestCase { * * @var string */ - const FILE_PATH = 'tmp/mycsv.csv'; + public const FILE_PATH = 'tmp/mycsv.csv'; /** * HTTP host protocol and domain for testing download URL. * * @var string */ - const HOST = 'http://example.com'; + public const HOST = 'http://example.com'; - const MIME_TYPE = 'text/csv'; + public const MIME_TYPE = 'text/csv'; /** * List referenceable dataset properties. * * @var string[] */ - const REFERENCEABLE_PROPERTY_LIST = [ + public const REFERENCEABLE_PROPERTY_LIST = [ 'keyword' => 0, 'distribution' => 'distribution', 'title' => 0, diff --git a/modules/metastore/tests/src/Unit/SchemaRetrieverTest.php b/modules/metastore/tests/src/Unit/SchemaRetrieverTest.php index 2ebc9b4bd0..06392c4f9b 100644 --- a/modules/metastore/tests/src/Unit/SchemaRetrieverTest.php +++ b/modules/metastore/tests/src/Unit/SchemaRetrieverTest.php @@ -19,7 +19,7 @@ class SchemaRetrieverTest extends TestCase { use ServiceCheckTrait; - const APP_ROOT = __DIR__ . '/../files'; + public const APP_ROOT = __DIR__ . '/../files'; /** * Protected. diff --git a/modules/metastore/tests/src/Unit/Storage/DataTest.php b/modules/metastore/tests/src/Unit/Storage/DataTest.php index b37e8d2675..a58d30061d 100644 --- a/modules/metastore/tests/src/Unit/Storage/DataTest.php +++ b/modules/metastore/tests/src/Unit/Storage/DataTest.php @@ -103,9 +103,9 @@ public function testRetrieveRangeUuids(): void { for ($i = 0; $i < 5; $i ++) { $nodes[$i] = new class { - private $uuid; + private ?string $uuid = null; public function uuid() { - return isset($this->uuid) ? $this->uuid : $this->uuid = uniqid(); + return $this->uuid ?? ($this->uuid = uniqid()); } }; $uuids[$i] = $nodes[$i]->uuid(); From f84d8eada6ebcc48d8ecdacee9c838d8341ed2d6 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 17 Mar 2023 16:35:21 -0700 Subject: [PATCH 11/22] countonnullrector for modules --- modules/common/src/Storage/AbstractDatabaseTable.php | 2 +- modules/datastore/src/Form/DashboardForm.php | 2 +- .../datastore/src/Plugin/DkanApiDocs/DatastoreApiDocs.php | 4 ++-- modules/datastore/src/Storage/DatabaseTable.php | 6 +++--- modules/datastore/src/Storage/QueryFactory.php | 6 +++--- modules/metastore/metastore.module | 2 +- modules/metastore/src/LifeCycle/LifeCycle.php | 8 ++++---- .../metastore/src/Storage/ResourceMapperDatabaseTable.php | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/common/src/Storage/AbstractDatabaseTable.php b/modules/common/src/Storage/AbstractDatabaseTable.php index 9d94c88d21..b028f191b9 100644 --- a/modules/common/src/Storage/AbstractDatabaseTable.php +++ b/modules/common/src/Storage/AbstractDatabaseTable.php @@ -173,7 +173,7 @@ public function storeMultiple(array $data) { /** * Private. */ - protected function getNonSerialFields() { + protected function getNonSerialFields(): array { $fields = []; foreach ($this->schema['fields'] as $field => $info) { if ($info['type'] != 'serial') { diff --git a/modules/datastore/src/Form/DashboardForm.php b/modules/datastore/src/Form/DashboardForm.php index 688fc5fdb4..fe1e0a41c9 100644 --- a/modules/datastore/src/Form/DashboardForm.php +++ b/modules/datastore/src/Form/DashboardForm.php @@ -360,7 +360,7 @@ protected function buildRevisionRows(array $datasetInfo, string $harvestStatus) $distributions = $rev['distributions']; // For first distribution, combine with revision information. $rows[] = array_merge( - $this->buildRevisionRow($rev, count($distributions), $harvestStatus), + $this->buildRevisionRow($rev, is_countable($distributions) ? count($distributions) : 0, $harvestStatus), $this->buildResourcesRow(array_shift($distributions)) ); // If there are more distributions, add additional rows for them. diff --git a/modules/datastore/src/Plugin/DkanApiDocs/DatastoreApiDocs.php b/modules/datastore/src/Plugin/DkanApiDocs/DatastoreApiDocs.php index 3cf3e7c322..784a236aa6 100644 --- a/modules/datastore/src/Plugin/DkanApiDocs/DatastoreApiDocs.php +++ b/modules/datastore/src/Plugin/DkanApiDocs/DatastoreApiDocs.php @@ -291,11 +291,11 @@ private function queryExample($exampleId = NULL, $format = NULL) { * @todo Page through results in case 20 isn't enough. */ private function getExampleIdentifiers() { - $all = $this->metastore->getAll("dataset", 0, 20); + $all = $this->metastore->getAll("dataset", 0, 20) ?? []; $i = 0; $datastore = FALSE; $identifiers = []; - while ($datastore == FALSE && $i < count($all)) { + while ($datastore == FALSE && $i < (is_countable($all) ? count($all) : 0)) { $item = $all[$i]; $i++; $datastore = (bool) ($identifiers = $this->getDatastoreIds($item)); diff --git a/modules/datastore/src/Storage/DatabaseTable.php b/modules/datastore/src/Storage/DatabaseTable.php index ebdd153a42..71cd00ca14 100755 --- a/modules/datastore/src/Storage/DatabaseTable.php +++ b/modules/datastore/src/Storage/DatabaseTable.php @@ -47,10 +47,10 @@ public function __construct(Connection $connection, DatastoreResource $resource) */ public function getSummary() { $schema = $this->getSchema(); - $columns = $schema['fields']; + $columns = $schema['fields'] ?? []; $indexes = $schema['indexes'] ?? NULL; $fulltext_indexes = $schema['fulltext indexes'] ?? NULL; - $numOfColumns = count($columns); + $numOfColumns = is_countable($columns) ? count($columns) : 0; $numOfRows = $this->count(); return new TableSummary( $numOfColumns, @@ -127,7 +127,7 @@ public function primaryKey() { /** * Protected. */ - protected function getNonSerialFields() { + protected function getNonSerialFields(): array { $fields = parent::getNonSerialFields(); $index = array_search($this->primaryKey(), $fields); if ($index !== FALSE) { diff --git a/modules/datastore/src/Storage/QueryFactory.php b/modules/datastore/src/Storage/QueryFactory.php index acd5aa66e2..427c26a976 100644 --- a/modules/datastore/src/Storage/QueryFactory.php +++ b/modules/datastore/src/Storage/QueryFactory.php @@ -298,11 +298,11 @@ private function populateQueryGroup($conditionGroup) { * DKAN query object we're building. */ private function populateQueryJoins(Query $query) { - if (empty($this->datastoreQuery->{"$.joins"}) && count($this->datastoreQuery->{"$.resources"}) <= 1) { + if (empty($this->datastoreQuery->{"$.joins"}) && count($this->datastoreQuery->{"$.resources"} ?? []) <= 1) { return; } - if (count($this->datastoreQuery->{"$.resources"}) > 1 - && count($this->datastoreQuery->{"$.joins"}) < (count($this->datastoreQuery->{"$.resources"}) - 1)) { + if (count($this->datastoreQuery->{"$.resources"} ?? []) > 1 + && (is_countable($this->datastoreQuery->{"$.joins"}) ? count($this->datastoreQuery->{"$.joins"}) : 0) < ((is_countable($this->datastoreQuery->{"$.resources"}) ? count($this->datastoreQuery->{"$.resources"}) : 0) - 1)) { throw new \Exception("Too many resources specified."); } foreach ($this->datastoreQuery->{"$.joins"} as $join) { diff --git a/modules/metastore/metastore.module b/modules/metastore/metastore.module index fcd55f4969..3251f9591d 100644 --- a/modules/metastore/metastore.module +++ b/modules/metastore/metastore.module @@ -127,7 +127,7 @@ function metastore_form_alter(&$form, FormStateInterface $form_state, $form_id) } // TODO: use an actual schema id. $object = \Drupal::service('dkan.metastore.valid_metadata')->get($json); - $object = \Drupal\metastore\Service::removeReferences($object); + $object = Service::removeReferences($object); $form[$fieldName]['widget'][0]['value']['#default_value'] = json_encode($object); } } diff --git a/modules/metastore/src/LifeCycle/LifeCycle.php b/modules/metastore/src/LifeCycle/LifeCycle.php index b912d04c60..8f4b5e1f72 100644 --- a/modules/metastore/src/LifeCycle/LifeCycle.php +++ b/modules/metastore/src/LifeCycle/LifeCycle.php @@ -161,11 +161,11 @@ protected function distributionLoad(MetastoreItemInterface $data) { if (isset($downloadUrl) && !filter_var($downloadUrl, FILTER_VALIDATE_URL)) { $resourceIdentifier = $downloadUrl; - $ref = NULL; - $original = NULL; - [$ref, $original] = $this->retrieveDownloadUrlFromResourceMapper($resourceIdentifier); + $downloadInfo = $this->retrieveDownloadUrlFromResourceMapper($resourceIdentifier); + $ref = (array) $downloadInfo[0] ?? []; + $original = $downloadInfo[1] ?? ''; - $downloadUrl = isset($original) ? $original : ""; + $downloadUrl = isset($original) ? $original : ''; $refProperty = "%Ref:downloadURL"; $metadata->data->{$refProperty} = count($ref) == 0 ? NULL : $ref; diff --git a/modules/metastore/src/Storage/ResourceMapperDatabaseTable.php b/modules/metastore/src/Storage/ResourceMapperDatabaseTable.php index 32f159987d..e5032c542d 100644 --- a/modules/metastore/src/Storage/ResourceMapperDatabaseTable.php +++ b/modules/metastore/src/Storage/ResourceMapperDatabaseTable.php @@ -121,7 +121,7 @@ public function primaryKey() { /** * Protected. */ - protected function getNonSerialFields() { + protected function getNonSerialFields(): array { $fields = parent::getNonSerialFields(); $index = array_search($this->primaryKey(), $fields); if ($index !== FALSE) { From 86f7d4b4d22eccc1c3d0ff860122d6df1989b8ac Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Fri, 17 Mar 2023 16:46:52 -0700 Subject: [PATCH 12/22] fqcn --- modules/common/src/EventDispatcherTrait.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/common/src/EventDispatcherTrait.php b/modules/common/src/EventDispatcherTrait.php index c4bd15890c..2b382dad9f 100644 --- a/modules/common/src/EventDispatcherTrait.php +++ b/modules/common/src/EventDispatcherTrait.php @@ -3,6 +3,7 @@ namespace Drupal\common; use Drupal\common\Events\Event; +use Symfony\Contracts\EventDispatcher\Event as SymfonyEvent; /** * Event dispatcher trait. @@ -57,7 +58,7 @@ private function dispatchEvent($eventName, $data, $validator = NULL) { * True if the newer Symfony event system is available. */ private function useLegacyDispatcher() { - return !class_exists('\Symfony\Contracts\EventDispatcher\Event'); + return !class_exists(SymfonyEvent::class); } /** From 78206d2ab63354d8921b8092f0424211e4b98410 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Sat, 18 Mar 2023 13:26:41 -0700 Subject: [PATCH 13/22] rector config --- rector.php | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 rector.php diff --git a/rector.php b/rector.php new file mode 100644 index 0000000000..41fdf43282 --- /dev/null +++ b/rector.php @@ -0,0 +1,59 @@ +sets([ + LevelSetList::UP_TO_PHP_74, + ]); + $rectorConfig->skip([ + JsonThrowOnErrorRector::class, + ClosureToArrowFunctionRector::class, + ]); + $rectorConfig->ruleWithConfiguration( + ReturnTypeWillChangeRector::class, + [new ClassMethodReference('JsonSerializable', 'jsonSerialize')] + ); + +// $rectorConfig->rule(\Rector\Php71\Rector\FuncCall\CountOnNullRector::class); + + $parameters = $rectorConfig->parameters(); + + $drupalFinder = new DrupalFinder(); + $drupalFinder->locateRoot(__DIR__); + $drupalRoot = $drupalFinder->getDrupalRoot(); + $rectorConfig->autoloadPaths([ + $drupalRoot . '/core', + $drupalRoot . '/modules', + $drupalRoot . '/profiles', + $drupalRoot . '/themes', + ]); + + $rectorConfig->fileExtensions([ + 'php', + 'module', + 'theme', + 'install', + 'profile', + 'inc', + 'engine', + ]); + $rectorConfig->importNames(TRUE, FALSE); + $rectorConfig->importShortClasses(FALSE); + $parameters->set('drupal_rector_notices_as_comments', TRUE); +}; From c8d59b7203d0dbb407c6fdb1a46e421c3be60d72 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Thu, 23 Mar 2023 09:41:46 -0700 Subject: [PATCH 14/22] added matrix test --- .circleci/config.yml | 166 +++++++++++++++++++++++++++++++------------ 1 file changed, 121 insertions(+), 45 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 579d637f2a..408f00ea5f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,8 @@ -version: 2.1 +# Circle CI script to run a matrix of tests in DDev. + +version: '2.1' +orbs: + docker: circleci/docker@2.2.0 commands: install-ddev: @@ -13,13 +17,17 @@ commands: curl https://apt.fury.io/drud/gpg.key | sudo apt-key add - echo "deb https://apt.fury.io/drud/ * *" | sudo tee -a /etc/apt/sources.list.d/ddev.list sudo apt update && sudo apt install -y ddev + prepare_build: - # TODO: Figure out the best way to share this build between the various jobs. + # TODO: Currently the DKAN ddev addon adds an extra config file called + # config.dkan.yml. This prevents us from just calling + # `ddev config --php-version` to change PHP version. In the future, + # change this around so we can just tell ddev to change the PHP version. parameters: - upgrade: - description: "If true, will install the latest stable version and test upgrade" - default: false - type: boolean + php_version: + description: 'PHP major.minor for DDev to use.' + default: '7.4' + type: string steps: - run: name: Set up composer config @@ -33,7 +41,13 @@ commands: which ddev ddev --version ddev config --project-name test-$CIRCLE_WORKFLOW_JOB_ID --project-type drupal9 --docroot docroot --create-docroot - ddev get https://github.com/GetDKAN/dkan-ddev-addon/archive/refs/heads/php81.tar.gz + ddev get https://github.com/GetDKAN/dkan-ddev-addon/archive/refs/heads/main.tar.gz + # Modify config to use our PHP version. + sed -i 's/^php_version.*$/php_version: "<< parameters.php_version >>"/' .ddev/config.dkan.yaml + # Clear out omit_containers. + sed -i '/omit_containers/d' .ddev/config.dkan.yaml + # Don't load the DBA container. + echo "omit_containers: [dba]" >> .ddev/config.dkan.yaml ddev restart ddev status ddev dkan-init --force @@ -41,14 +55,36 @@ commands: chmod +x ./cc-test-reporter mkdir -p test_results + prepare_drupal_core: + # TODO: Hopefully getdkan/recommended-project will have tagged releases at some point. + parameters: + drupal_core_constraint: + description: 'Drupal core version to use as a Composer constraint.' + default: '~9.5.0' + type: string + steps: + - run: + name: Use Drupal core version + command: | + ddev composer show "drupal/core*" --no-ansi + # Remove drupal/core-recommended and swap for drupal/core so that + # we can install core 9.5 using PHP 8.1. (Guzzle would block otherwise.) + ddev composer remove drupal/core-recommended --no-update + ddev composer require drupal/core-composer-scaffold:<< parameters.drupal_core_constraint >> --no-update + ddev composer require drupal/core-project-message:<< parameters.drupal_core_constraint >> --no-update + ddev composer require drupal/core:<< parameters.drupal_core_constraint >> --no-update + ddev composer require --dev drupal/core-dev:<< parameters.drupal_core_constraint >> --no-update + ddev composer update --no-audit + ddev composer show "drupal/core*" --no-ansi + prepare_site: parameters: upgrade: - description: "If true, will install the latest stable version and test upgrade" + description: 'If true, will install the latest stable version and test upgrade' default: false type: boolean needs_cypress: - description: "If true, will add Cypress to the DDev environment" + description: 'If true, will add Cypress to the DDev environment' default: false type: boolean steps: @@ -95,34 +131,35 @@ commands: jobs: phpunit: - machine: - image: ubuntu-2004:current + executor: docker/machine parameters: - upgrade: - description: "If true, will install the latest stable version and test upgrade" + php_version: + description: 'PHP major.minor for DDev to use.' + default: '8.0' + type: string + drupal_core_constraint: + description: 'Drupal core version to use as a Composer constraint.' + default: '~9.5.0' + type: string + report_coverage: + description: 'Generate coverage report and send it to CodeClimate' default: false type: boolean - needs_cypress: - description: "If true, will add Cypress to the DDev environment" + upgrade: + description: 'If true, will install the latest stable DKAN version and test upgrade' default: false type: boolean steps: + - docker/install-docker-tools - prepare_build: - upgrade: << parameters.upgrade >> + php_version: << parameters.php_version >> + - prepare_drupal_core: + drupal_core_constraint: << parameters.drupal_core_constraint >> - prepare_site: upgrade: << parameters.upgrade >> - needs_cypress: << parameters.needs_cypress >> + needs_cypress: false - when: - condition: << parameters.upgrade >> - steps: - - run: - name: Run PHPUnit tests - command: | - ddev dkan-test-phpunit \ - --log-junit ../test_results/phpunit_results.xml - - unless: - # Only collect coverage info for non-upgrade PHPUnit tests. - condition: << parameters.upgrade >> + condition: << parameters.report_coverage >> steps: - run: name: Run PHPUnit tests with coverage report @@ -133,7 +170,8 @@ jobs: $CIRCLE_WORKING_DIRECTORY/cc-test-reporter before-build ddev dkan-test-phpunit \ --coverage-clover /var/www/html/docroot/modules/contrib/dkan/clover.xml \ - --log-junit ../test_results/phpunit_results.xml + --coverage-html /var/www/html/docroot/modules/contrib/dkan/coverage-html \ + --log-junit /var/www/html/docroot/modules/contrib/dkan/junit/junit.xml TEST_RESULT=$? if [ -f docroot/modules/contrib/dkan/clover.xml ]; then echo "Coverage file: docroot/modules/contrib/dkan/clover.xml" @@ -146,34 +184,53 @@ jobs: --prefix /var/www/html/dkan \ --exit-code $TEST_RESULT exit $TEST_RESULT + - store_artifacts: + path: docroot/modules/contrib/dkan/coverage-html + - unless: + condition: << parameters.report_coverage >> + steps: + - run: + name: Run PHPUnit tests + command: | + ddev dkan-test-phpunit \ + --log-junit /var/www/html/docroot/modules/contrib/dkan/junit/junit.xml - store_test_results: - path: test_results + path: dkan/junit cypress: machine: image: ubuntu-2004:current parallelism: 4 parameters: + php_version: + description: 'PHP major.minor for DDev to use.' + default: '8.0' + type: string + drupal_core_constraint: + description: 'Drupal core version to use as a Composer constraint.' + default: '~9.5.0' + type: string upgrade: - description: "If true, will install the latest stable version and test upgrade" - default: false - type: boolean - needs_cypress: - description: "If true, will add Cypress to the DDev environment" + description: 'If true, will install the latest stable DKAN version and test upgrade' default: false type: boolean steps: + - docker/install-docker-tools - prepare_build: - upgrade: << parameters.upgrade >> + php_version: << parameters.php_version >> + - prepare_drupal_core: + drupal_core_constraint: << parameters.drupal_core_constraint >> - prepare_site: upgrade: << parameters.upgrade >> - needs_cypress: << parameters.needs_cypress >> + needs_cypress: true - run: name: Run Cypress tests command: | - mkdir dkan/cypress/tmp && mkdir dkan/cypress/results + mkdir dkan/cypress/tmp + mkdir dkan/cypress/results mv $(circleci tests glob dkan/cypress/integration/*.spec.js | circleci tests split --split-by=timings) dkan/cypress/tmp || true - rm dkan/cypress/integration/* && mv dkan/cypress/tmp/* dkan/cypress/integration + rm dkan/cypress/integration/* + mv dkan/cypress/tmp/* dkan/cypress/integration ddev dkan-module-test-cypress \ --headless \ --reporter junit \ @@ -188,18 +245,37 @@ jobs: workflows: version: 2 install_and_test: + # We use matrix for all these parameters so that we can tell them apart in report screens. jobs: - - phpunit: - name: install_test_phpunit - cypress: name: install_test_cypress - needs_cypress: true + - phpunit: + matrix: + parameters: + drupal_core_constraint: ['~9.4.0'] + php_version: ['7.4'] + - phpunit: + matrix: + parameters: + drupal_core_constraint: ['~9.5.0'] + php_version: ['7.4', '8.1'] + - phpunit: + name: 'Install current target (Drupal 9.5, PHP 8.0)' + report_coverage: true + drupal_core_constraint: '~9.5.0' + php_version: '8.0' + - phpunit: + matrix: + parameters: + drupal_core_constraint: ['~10.0.0'] + php_version: ['8.1'] upgrade_and_test: jobs: - - phpunit: - name: upgrade_test_phpunit - upgrade: true - cypress: name: upgrade_test_cypress upgrade: true - needs_cypress: true + - phpunit: + name: 'Upgrade current target (Drupal 9.5, PHP 8.0)' + upgrade: true + drupal_core_constraint: '~9.5.0' + php_version: '8.0' From bb50e8dcad34811f9a0e229d2fd858e3abf2b503 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Thu, 23 Mar 2023 10:09:17 -0700 Subject: [PATCH 15/22] use php81 addon --- .circleci/config.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 408f00ea5f..a131d45c49 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,6 +28,10 @@ commands: description: 'PHP major.minor for DDev to use.' default: '7.4' type: string + addon_branch: + description: 'Repo branch name for the dkan-ddev-addon you want to test against.' + default: 'main' + type: string steps: - run: name: Set up composer config @@ -41,7 +45,7 @@ commands: which ddev ddev --version ddev config --project-name test-$CIRCLE_WORKFLOW_JOB_ID --project-type drupal9 --docroot docroot --create-docroot - ddev get https://github.com/GetDKAN/dkan-ddev-addon/archive/refs/heads/main.tar.gz + ddev get https://github.com/GetDKAN/dkan-ddev-addon/archive/refs/heads/<< parameters.addon_branch >>.tar.gz # Modify config to use our PHP version. sed -i 's/^php_version.*$/php_version: "<< parameters.php_version >>"/' .ddev/config.dkan.yaml # Clear out omit_containers. @@ -153,6 +157,7 @@ jobs: - docker/install-docker-tools - prepare_build: php_version: << parameters.php_version >> + addon_branch: php81 - prepare_drupal_core: drupal_core_constraint: << parameters.drupal_core_constraint >> - prepare_site: From b7f489e0f7c67c2732e140d1fc16ceed06c46240 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Thu, 23 Mar 2023 10:42:32 -0700 Subject: [PATCH 16/22] use 2.x for config_update --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d4aabd1497..a836efa269 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "description": "DKAN Open Data Catalog", "require": { "drupal/admin_toolbar": "^3", - "drupal/config_update": "^1.6", + "drupal/config_update": "^2@dev", "drupal/moderated_content_bulk_publish": "~2.0.20", "drupal/search_api": "^1.15", "drupal/select_or_other": "dev-4.x#ae0585ff8c", From f34a752fba268896e9e9ed7a05cc1f255304209e Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Mon, 27 Mar 2023 16:15:51 -0700 Subject: [PATCH 17/22] newest circleci --- .circleci/config.yml | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a131d45c49..e87141d135 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -157,7 +157,6 @@ jobs: - docker/install-docker-tools - prepare_build: php_version: << parameters.php_version >> - addon_branch: php81 - prepare_drupal_core: drupal_core_constraint: << parameters.drupal_core_constraint >> - prepare_site: @@ -250,37 +249,41 @@ jobs: workflows: version: 2 install_and_test: - # We use matrix for all these parameters so that we can tell them apart in report screens. + # We use matrix for these parameters so that we can tell them apart in report screens. jobs: - cypress: name: install_test_cypress - phpunit: matrix: parameters: - drupal_core_constraint: ['~9.4.0'] - php_version: ['7.4'] + drupal_core_constraint: [ '~9.4.0' ] + php_version: [ '7.4' ] - phpunit: matrix: parameters: - drupal_core_constraint: ['~9.5.0'] - php_version: ['7.4', '8.1'] + drupal_core_constraint: [ '~9.5.0' ] + php_version: [ '7.4', '8.1' ] - phpunit: - name: 'Install current target (Drupal 9.5, PHP 8.0)' + name: 'Install target (Drupal 9.5, PHP 8.0)' report_coverage: true - drupal_core_constraint: '~9.5.0' - php_version: '8.0' - - phpunit: matrix: parameters: - drupal_core_constraint: ['~10.0.0'] - php_version: ['8.1'] + drupal_core_constraint: [ '~9.5.0' ] + php_version: [ '8.0' ] + # - phpunit: + # matrix: + # parameters: + # drupal_core_constraint: [ '~10.0.0' ] + # php_version: [ '8.1' ] upgrade_and_test: jobs: - cypress: name: upgrade_test_cypress upgrade: true - phpunit: - name: 'Upgrade current target (Drupal 9.5, PHP 8.0)' + name: 'Upgrade target (Drupal 9.5, PHP 8.0)' upgrade: true - drupal_core_constraint: '~9.5.0' - php_version: '8.0' + matrix: + parameters: + drupal_core_constraint: [ '~9.5.0' ] + php_version: [ '8.0' ] From 54c049db39b3a1ed9fa77d3efadc54931dddd2ae Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Thu, 30 Mar 2023 10:24:20 -0700 Subject: [PATCH 18/22] phpcs and rector --- .codeclimate.yml | 2 +- modules/common/src/EventDispatcherTrait.php | 3 +-- .../src/Storage/AbstractDatabaseTable.php | 2 +- .../tests/src/Functional/DkanDocsTest.php | 2 +- .../tests/src/Kernel/ConfigFormTestBase.php | 1 - .../src/Unit/Commands/CommonCommandsTest.php | 11 +++++--- .../tests/src/Unit/Storage/JobStoreTest.php | 4 +-- .../src/Unit/Storage/QueryDataProvider.php | 8 +++--- .../src/Unit/Storage/SelectFactoryTest.php | 2 +- modules/datastore/src/Form/DashboardForm.php | 2 +- .../Plugin/DkanApiDocs/DatastoreApiDocs.php | 4 +-- .../datastore/src/Storage/DatabaseTable.php | 6 ++--- .../datastore/src/Storage/QueryFactory.php | 6 ++--- .../datastore/tests/src/Mock/Container.php | 9 +++---- .../Unit/Controller/QueryControllerTest.php | 2 -- .../QueryDownloadControllerTest.php | 2 -- .../tests/src/Unit/Form/DashboardFormTest.php | 12 ++++----- .../Unit/Plugin/QueueWorker/ImportJobTest.php | 2 +- .../Unit/Plugin/QueueWorker/ImportTest.php | 2 +- .../tests/src/Unit/Service/ImportTest.php | 2 +- .../Unit/Service/ResourceLocalizerTest.php | 2 +- .../Unit/Controller/ControllerPageTest.php | 4 ++- .../harvest/tests/src/Unit/ServiceTest.php | 23 +++++++++++----- .../tests/src/Unit/StringHelperTest.php | 1 - modules/metastore/metastore.module | 2 +- modules/metastore/src/LifeCycle/LifeCycle.php | 8 +++--- .../Storage/ResourceMapperDatabaseTable.php | 2 +- .../src/Functional/Api1/DatasetItemTest.php | 4 +-- .../Functional/Api1/DatasetRevisionTest.php | 8 +++--- .../Functional/DatasetSpecificDocsTest.php | 2 +- .../src/Functional/OnPreReferenceTest.php | 2 +- .../src/Functional/Storage/NodeDataTest.php | 8 +++--- .../tests/src/Unit/DatabaseTableMock.php | 4 +-- .../src/Unit/MetastoreSubscriberTest.php | 2 +- .../src/Unit/Reference/ReferencerTest.php | 12 ++++----- .../tests/src/Unit/SchemaRetrieverTest.php | 2 +- .../tests/src/Unit/Storage/DataTest.php | 4 +-- phpcs.xml | 26 +++++++++++++++++++ rector.php | 8 +++--- 39 files changed, 120 insertions(+), 88 deletions(-) create mode 100644 phpcs.xml diff --git a/.codeclimate.yml b/.codeclimate.yml index 890420be65..771c130b8c 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -38,4 +38,4 @@ exclude_patterns: - "**/*.module" - ".circleci/" - ".gitignore" - \ No newline at end of file + - "rector.php" diff --git a/modules/common/src/EventDispatcherTrait.php b/modules/common/src/EventDispatcherTrait.php index 2b382dad9f..c4bd15890c 100644 --- a/modules/common/src/EventDispatcherTrait.php +++ b/modules/common/src/EventDispatcherTrait.php @@ -3,7 +3,6 @@ namespace Drupal\common; use Drupal\common\Events\Event; -use Symfony\Contracts\EventDispatcher\Event as SymfonyEvent; /** * Event dispatcher trait. @@ -58,7 +57,7 @@ private function dispatchEvent($eventName, $data, $validator = NULL) { * True if the newer Symfony event system is available. */ private function useLegacyDispatcher() { - return !class_exists(SymfonyEvent::class); + return !class_exists('\Symfony\Contracts\EventDispatcher\Event'); } /** diff --git a/modules/common/src/Storage/AbstractDatabaseTable.php b/modules/common/src/Storage/AbstractDatabaseTable.php index b028f191b9..9d94c88d21 100644 --- a/modules/common/src/Storage/AbstractDatabaseTable.php +++ b/modules/common/src/Storage/AbstractDatabaseTable.php @@ -173,7 +173,7 @@ public function storeMultiple(array $data) { /** * Private. */ - protected function getNonSerialFields(): array { + protected function getNonSerialFields() { $fields = []; foreach ($this->schema['fields'] as $field => $info) { if ($info['type'] != 'serial') { diff --git a/modules/common/tests/src/Functional/DkanDocsTest.php b/modules/common/tests/src/Functional/DkanDocsTest.php index 3b704decf3..5b475e8cbb 100644 --- a/modules/common/tests/src/Functional/DkanDocsTest.php +++ b/modules/common/tests/src/Functional/DkanDocsTest.php @@ -36,7 +36,7 @@ public function testGetCompleteYaml() { $controller = $this->getController(); $response = $controller->getComplete('yaml'); $this->assertEquals(200, $response->getStatusCode()); - $data = Yaml::decode($response->getContent()); + $data = Yaml::decode($response->getContent(), TRUE); // Basic auth is included. $this->assertTrue(isset($data["components"]["securitySchemes"]["basic_auth"])); diff --git a/modules/common/tests/src/Kernel/ConfigFormTestBase.php b/modules/common/tests/src/Kernel/ConfigFormTestBase.php index 6bad2c3915..96e18fa087 100644 --- a/modules/common/tests/src/Kernel/ConfigFormTestBase.php +++ b/modules/common/tests/src/Kernel/ConfigFormTestBase.php @@ -52,7 +52,6 @@ abstract public function provideFormData(): array; * @dataProvider provideFormData */ public function testConfigForm(array $form_values) { - $values = []; // Programmatically submit the given values. foreach ($form_values as $form_key => $data) { $values[$form_key] = $data['#value']; diff --git a/modules/common/tests/src/Unit/Commands/CommonCommandsTest.php b/modules/common/tests/src/Unit/Commands/CommonCommandsTest.php index b382527337..8bd4f4195a 100644 --- a/modules/common/tests/src/Unit/Commands/CommonCommandsTest.php +++ b/modules/common/tests/src/Unit/Commands/CommonCommandsTest.php @@ -16,13 +16,16 @@ class CommonCommandsTest extends TestCase { * */ public function testDatasetInfo() { - $data = ['uuid' => 'foo']; - $this->expectOutputString(json_encode($data, JSON_PRETTY_PRINT)); $datasetInfo = (new Chain($this)) - ->add(DatasetInfo::class, 'gather', $data); + ->add(DatasetInfo::class, 'gather', ['uuid' => 'foo']); + $drush = new CommonCommands($datasetInfo->getMock()); - $drush->datasetInfo('foo'); + $result = $drush->datasetInfo('foo'); + + $expected = json_encode(['uuid' => 'foo'], JSON_PRETTY_PRINT); + + $this->expectOutputString($expected, $result); } } diff --git a/modules/common/tests/src/Unit/Storage/JobStoreTest.php b/modules/common/tests/src/Unit/Storage/JobStoreTest.php index 180a1be707..38d20e8622 100644 --- a/modules/common/tests/src/Unit/Storage/JobStoreTest.php +++ b/modules/common/tests/src/Unit/Storage/JobStoreTest.php @@ -60,7 +60,7 @@ public function testRetrieve() { ->add(StatementWrapper::class, 'fetchAll', $fieldInfo); $jobStore = new JobStore(FileFetcher::class, $chain->getMock()); - $this->assertEquals($job_data, $jobStore->retrieve("1")); + $this->assertEquals($job_data, $jobStore->retrieve("1", FileFetcher::class)); } /** @@ -153,7 +153,7 @@ public function testRemove() { $jobStore = new JobStore(FileFetcher::class, $connection); - $this->assertEquals("", $jobStore->remove("1")); + $this->assertEquals("", $jobStore->remove("1", FileFetcher::class)); } /** diff --git a/modules/common/tests/src/Unit/Storage/QueryDataProvider.php b/modules/common/tests/src/Unit/Storage/QueryDataProvider.php index f2d11b452c..03e4398b6d 100644 --- a/modules/common/tests/src/Unit/Storage/QueryDataProvider.php +++ b/modules/common/tests/src/Unit/Storage/QueryDataProvider.php @@ -16,10 +16,10 @@ */ class QueryDataProvider { - public const QUERY_OBJECT = 1; - public const SQL = 2; - public const EXCEPTION = 3; - public const VALUES = 4; + const QUERY_OBJECT = 1; + const SQL = 2; + const EXCEPTION = 3; + const VALUES = 4; /** * diff --git a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php index a6f5168813..45b4da1392 100644 --- a/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php +++ b/modules/common/tests/src/Unit/Storage/SelectFactoryTest.php @@ -13,7 +13,7 @@ * */ class SelectFactoryTest extends TestCase { - private Query $query; + private $query; /** * SelectFactory object. diff --git a/modules/datastore/src/Form/DashboardForm.php b/modules/datastore/src/Form/DashboardForm.php index fe1e0a41c9..688fc5fdb4 100644 --- a/modules/datastore/src/Form/DashboardForm.php +++ b/modules/datastore/src/Form/DashboardForm.php @@ -360,7 +360,7 @@ protected function buildRevisionRows(array $datasetInfo, string $harvestStatus) $distributions = $rev['distributions']; // For first distribution, combine with revision information. $rows[] = array_merge( - $this->buildRevisionRow($rev, is_countable($distributions) ? count($distributions) : 0, $harvestStatus), + $this->buildRevisionRow($rev, count($distributions), $harvestStatus), $this->buildResourcesRow(array_shift($distributions)) ); // If there are more distributions, add additional rows for them. diff --git a/modules/datastore/src/Plugin/DkanApiDocs/DatastoreApiDocs.php b/modules/datastore/src/Plugin/DkanApiDocs/DatastoreApiDocs.php index 784a236aa6..3cf3e7c322 100644 --- a/modules/datastore/src/Plugin/DkanApiDocs/DatastoreApiDocs.php +++ b/modules/datastore/src/Plugin/DkanApiDocs/DatastoreApiDocs.php @@ -291,11 +291,11 @@ private function queryExample($exampleId = NULL, $format = NULL) { * @todo Page through results in case 20 isn't enough. */ private function getExampleIdentifiers() { - $all = $this->metastore->getAll("dataset", 0, 20) ?? []; + $all = $this->metastore->getAll("dataset", 0, 20); $i = 0; $datastore = FALSE; $identifiers = []; - while ($datastore == FALSE && $i < (is_countable($all) ? count($all) : 0)) { + while ($datastore == FALSE && $i < count($all)) { $item = $all[$i]; $i++; $datastore = (bool) ($identifiers = $this->getDatastoreIds($item)); diff --git a/modules/datastore/src/Storage/DatabaseTable.php b/modules/datastore/src/Storage/DatabaseTable.php index 71cd00ca14..ebdd153a42 100755 --- a/modules/datastore/src/Storage/DatabaseTable.php +++ b/modules/datastore/src/Storage/DatabaseTable.php @@ -47,10 +47,10 @@ public function __construct(Connection $connection, DatastoreResource $resource) */ public function getSummary() { $schema = $this->getSchema(); - $columns = $schema['fields'] ?? []; + $columns = $schema['fields']; $indexes = $schema['indexes'] ?? NULL; $fulltext_indexes = $schema['fulltext indexes'] ?? NULL; - $numOfColumns = is_countable($columns) ? count($columns) : 0; + $numOfColumns = count($columns); $numOfRows = $this->count(); return new TableSummary( $numOfColumns, @@ -127,7 +127,7 @@ public function primaryKey() { /** * Protected. */ - protected function getNonSerialFields(): array { + protected function getNonSerialFields() { $fields = parent::getNonSerialFields(); $index = array_search($this->primaryKey(), $fields); if ($index !== FALSE) { diff --git a/modules/datastore/src/Storage/QueryFactory.php b/modules/datastore/src/Storage/QueryFactory.php index 427c26a976..acd5aa66e2 100644 --- a/modules/datastore/src/Storage/QueryFactory.php +++ b/modules/datastore/src/Storage/QueryFactory.php @@ -298,11 +298,11 @@ private function populateQueryGroup($conditionGroup) { * DKAN query object we're building. */ private function populateQueryJoins(Query $query) { - if (empty($this->datastoreQuery->{"$.joins"}) && count($this->datastoreQuery->{"$.resources"} ?? []) <= 1) { + if (empty($this->datastoreQuery->{"$.joins"}) && count($this->datastoreQuery->{"$.resources"}) <= 1) { return; } - if (count($this->datastoreQuery->{"$.resources"} ?? []) > 1 - && (is_countable($this->datastoreQuery->{"$.joins"}) ? count($this->datastoreQuery->{"$.joins"}) : 0) < ((is_countable($this->datastoreQuery->{"$.resources"}) ? count($this->datastoreQuery->{"$.resources"}) : 0) - 1)) { + if (count($this->datastoreQuery->{"$.resources"}) > 1 + && count($this->datastoreQuery->{"$.joins"}) < (count($this->datastoreQuery->{"$.resources"}) - 1)) { throw new \Exception("Too many resources specified."); } foreach ($this->datastoreQuery->{"$.joins"} as $join) { diff --git a/modules/datastore/tests/src/Mock/Container.php b/modules/datastore/tests/src/Mock/Container.php index f2dbb141cb..52db31c52f 100644 --- a/modules/datastore/tests/src/Mock/Container.php +++ b/modules/datastore/tests/src/Mock/Container.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\datastore\Unit\Mock; -use Drupal\Core\Queue\QueueInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\Schema; @@ -24,11 +23,11 @@ */ class Container { - private TestCase $testCase; + private $testCase; - private \stdClass $jobStoreData; + private $jobStoreData; private $tableName; - private bool $noNode = FALSE; + private $noNode = FALSE; /** * @@ -105,7 +104,7 @@ private function getQueueFactoryMock() { * Private. */ private function getQueueMock() { - $mock = $this->testCase->getMockBuilder('\\' . QueueInterface::class) + $mock = $this->testCase->getMockBuilder("\Drupal\Core\Queue\QueueInterface") ->disableOriginalConstructor() ->setMethods(['createItem']) ->getMockForAbstractClass(); diff --git a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php index f753434bc1..4efb90e677 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryControllerTest.php @@ -358,7 +358,6 @@ public function testDistributionIndexWrongIdentifier() { * */ public function testDistributionIndexWrongIndex() { - $info = []; $data = json_encode([ "results" => TRUE, ]); @@ -374,7 +373,6 @@ public function testDistributionIndexWrongIndex() { * */ public function testDistributionIndex() { - $info = []; $data = json_encode([ "results" => TRUE, ]); diff --git a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php index c8411614b9..31e25604f7 100644 --- a/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php +++ b/modules/datastore/tests/src/Unit/Controller/QueryDownloadControllerTest.php @@ -99,7 +99,6 @@ public function testStreamedQueryCsv() { } public function queryResultReformatted($data){ - $streamedCsv = null; $request = $this->mockRequest($data); $dataDictionaryFields = [ 'name' => 'date', @@ -470,7 +469,6 @@ public function mockRequest($data = '') { * A database table storage class useable for datastore queries. */ public function mockDatastoreTable($connection, $id, $csvFile, $fields) { - $createFields = []; foreach ($fields as $name => $field) { $types[] = $field['type']; $notNull = $field['not null'] ?? FALSE; diff --git a/modules/datastore/tests/src/Unit/Form/DashboardFormTest.php b/modules/datastore/tests/src/Unit/Form/DashboardFormTest.php index 882a88fe11..4b0e30363e 100644 --- a/modules/datastore/tests/src/Unit/Form/DashboardFormTest.php +++ b/modules/datastore/tests/src/Unit/Form/DashboardFormTest.php @@ -113,7 +113,7 @@ public function testBuildTableRowsWithHarvestIdFilter() { \Drupal::setContainer($container); $form = DashboardForm::create($container)->buildForm([], new FormState()); - $this->assertCount(1, $form['table']['#rows']); + $this->assertEquals(1, count($form['table']['#rows'])); $this->assertEquals('dataset-1', $form['table']['#rows'][0][0]['data']['#uuid']); $this->assertEquals('Dataset 1', $form['table']['#rows'][0][0]['data']['#title']); $this->assertEquals('NEW', $form['table']['#rows'][0][2]['data']); @@ -148,7 +148,7 @@ public function testBuildTableRowsWithUuidFilter() { \Drupal::setContainer($container); $form = DashboardForm::create($container)->buildForm([], new FormState()); - $this->assertCount(1, $form['table']['#rows']); + $this->assertEquals(1, count($form['table']['#rows'])); $this->assertEquals('test', $form['table']['#rows'][0][0]['data']['#uuid']); $this->assertEquals('Title', $form['table']['#rows'][0][0]['data']['#title']); $this->assertEquals('N/A', $form['table']['#rows'][0][2]['data']); @@ -215,7 +215,7 @@ public function testBuildTableRowsWithAllDatasets() { $form = DashboardForm::create($container->getMock())->buildForm([], new FormState()); // Assert that there are both datasets: harvested and non-harvested. - $this->assertCount(2, $form['table']['#rows']); + $this->assertEquals(2, count($form['table']['#rows'])); $this->assertEquals('dataset-1', $form['table']['#rows'][0][0]['data']['#uuid']); $this->assertEquals('Dataset 1', $form['table']['#rows'][0][0]['data']['#title']); @@ -296,12 +296,12 @@ public function testBuildTableRowsDatasetMultipleDistribution() { \Drupal::setContainer($container); $form = DashboardForm::create($container)->buildForm([], new FormState()); - $this->assertCount(2, $form['table']['#rows']); + $this->assertEquals(2, count($form['table']['#rows'])); // First row has six columns and rowspan on first two - $this->assertCount(6, $form['table']['#rows'][0]); + $this->assertEquals(6, count($form['table']['#rows'][0])); $this->assertEquals(2, $form['table']['#rows'][0][1]['rowspan']); // The second row has only three columns. - $this->assertCount(3, $form['table']['#rows'][1]); + $this->assertEquals(3, count($form['table']['#rows'][1])); $this->assertEquals('dist-1', $form['table']['#rows'][0][3]['data']['#uuid']); $this->assertEquals('dist-2', $form['table']['#rows'][1][0]['data']['#uuid']); diff --git a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php index 6228857666..5073538644 100644 --- a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php +++ b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportJobTest.php @@ -16,7 +16,7 @@ */ class ImportJobTest extends TestCase { - private ?TestMemStorage $database = null; + private $database; /** * This method is called before each test. diff --git a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportTest.php b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportTest.php index fede1ed617..beaa468cac 100644 --- a/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportTest.php +++ b/modules/datastore/tests/src/Unit/Plugin/QueueWorker/ImportTest.php @@ -25,7 +25,7 @@ */ class ImportTest extends TestCase { - private array $data = [ + private $data = [ 'data' => [ 'identifier' => '12345', 'version' => '23456', diff --git a/modules/datastore/tests/src/Unit/Service/ImportTest.php b/modules/datastore/tests/src/Unit/Service/ImportTest.php index c34b546f01..292ec8d379 100644 --- a/modules/datastore/tests/src/Unit/Service/ImportTest.php +++ b/modules/datastore/tests/src/Unit/Service/ImportTest.php @@ -35,7 +35,7 @@ class ImportTest extends TestCase { * * @var string */ - public const HOST = 'http://h-o.st'; + const HOST = 'http://h-o.st'; /** * diff --git a/modules/datastore/tests/src/Unit/Service/ResourceLocalizerTest.php b/modules/datastore/tests/src/Unit/Service/ResourceLocalizerTest.php index c7d2233446..ff5ad9d269 100644 --- a/modules/datastore/tests/src/Unit/Service/ResourceLocalizerTest.php +++ b/modules/datastore/tests/src/Unit/Service/ResourceLocalizerTest.php @@ -29,7 +29,7 @@ class ResourceLocalizerTest extends TestCase { * * @var string */ - public const HOST = 'http://example.com'; + const HOST = 'http://example.com'; /** * diff --git a/modules/frontend/tests/src/Unit/Controller/ControllerPageTest.php b/modules/frontend/tests/src/Unit/Controller/ControllerPageTest.php index d28a5c5b09..2ff2a33349 100644 --- a/modules/frontend/tests/src/Unit/Controller/ControllerPageTest.php +++ b/modules/frontend/tests/src/Unit/Controller/ControllerPageTest.php @@ -14,8 +14,10 @@ class ControllerPageTest extends TestCase { /** * Cache max age config value. + * + * @var int */ - private int $cacheMaxAge; + private $cacheMaxAge; protected function setUp(): void { parent::setUp(); diff --git a/modules/harvest/tests/src/Unit/ServiceTest.php b/modules/harvest/tests/src/Unit/ServiceTest.php index 5bf6de0500..8ccfb868b5 100644 --- a/modules/harvest/tests/src/Unit/ServiceTest.php +++ b/modules/harvest/tests/src/Unit/ServiceTest.php @@ -29,7 +29,7 @@ class ServiceTest extends TestCase { use ServiceCheckTrait; - private ?FactoryInterface $storageFactory = null; + private $storageFactory; /** * @@ -73,7 +73,7 @@ public function test() { $result = $service->runHarvest('test_plan'); $this->assertEquals("SUCCESS", $result['status']['extract']); - $this->assertCount(2, $result['status']['extracted_items_ids']); + $this->assertEquals(2, count($result['status']['extracted_items_ids'])); $this->assertEquals(json_encode(["NEW", "NEW"]), json_encode(array_values($result['status']['load']))); $storedObject = $this->getStorageFactory()->getInstance('harvest_test_plan_items')->retrieve("cedcd327-4e5d-43f9-8eb1-c11850fa7c55"); @@ -85,7 +85,7 @@ public function test() { $result = $service->runHarvest('test_plan'); $this->assertEquals("SUCCESS", $result['status']['extract']); - $this->assertCount(2, $result['status']['extracted_items_ids']); + $this->assertEquals(2, count($result['status']['extracted_items_ids'])); $this->assertEquals(json_encode(["UNCHANGED", "UNCHANGED"]), json_encode(array_values($result['status']['load']))); // Run harvest with changes. @@ -95,7 +95,7 @@ public function test() { $result = $service->runHarvest('test_plan'); $this->assertEquals("SUCCESS", $result['status']['extract']); - $this->assertCount(2, $result['status']['extracted_items_ids']); + $this->assertEquals(2, count($result['status']['extracted_items_ids'])); $this->assertEquals(json_encode(["UPDATED", "UNCHANGED"]), json_encode(array_values($result['status']['load']))); $storedObject = $this->getStorageFactory()->getInstance('harvest_test_plan_items')->retrieve("cedcd327-4e5d-43f9-8eb1-c11850fa7c55"); @@ -112,12 +112,12 @@ public function test() { 'harvest_test_plan_runs', ]; foreach ($storageTypes as $storageId) { - $this->assertCount(0, $this->getStorageFactory()->getInstance($storageId)->retrieveAll()); + $this->assertEquals(0, count($this->getStorageFactory()->getInstance($storageId)->retrieveAll())); } // Deregister harvest. $service->deregisterHarvest('test_plan'); - $this->assertCount(0, $this->getStorageFactory()->getInstance('harvest_plans')->retrieveAll()); + $this->assertEquals(0, count($this->getStorageFactory()->getInstance('harvest_plans')->retrieveAll())); } /** @@ -166,16 +166,25 @@ public function testGetHarvestRunInfo() { private function getStorageFactory() { if (!isset($this->storageFactory)) { $this->storageFactory = new class() implements FactoryInterface { - private array $stores = []; + private $stores = []; + /** + * Getter. + */ public function getInstance(string $identifier, array $config = []) { if (!isset($this->stores[$identifier])) { $this->stores[$identifier] = new class() extends Memory { + /** + * + */ public function retrieveAll(): array { return array_keys(parent::retrieveAll()); } + /** + * + */ public function destruct() { $this->storage = []; } diff --git a/modules/json_form_widget/tests/src/Unit/StringHelperTest.php b/modules/json_form_widget/tests/src/Unit/StringHelperTest.php index d9dbab8534..a3473e5bf0 100644 --- a/modules/json_form_widget/tests/src/Unit/StringHelperTest.php +++ b/modules/json_form_widget/tests/src/Unit/StringHelperTest.php @@ -20,7 +20,6 @@ class StringHelperTest extends TestCase { * Test. */ public function testEmailValidate() { - $element = []; $options = (new Options()) ->add('string_translation', TranslationManager::class) ->add('email.validator', EmailValidator::class) diff --git a/modules/metastore/metastore.module b/modules/metastore/metastore.module index 3251f9591d..fcd55f4969 100644 --- a/modules/metastore/metastore.module +++ b/modules/metastore/metastore.module @@ -127,7 +127,7 @@ function metastore_form_alter(&$form, FormStateInterface $form_state, $form_id) } // TODO: use an actual schema id. $object = \Drupal::service('dkan.metastore.valid_metadata')->get($json); - $object = Service::removeReferences($object); + $object = \Drupal\metastore\Service::removeReferences($object); $form[$fieldName]['widget'][0]['value']['#default_value'] = json_encode($object); } } diff --git a/modules/metastore/src/LifeCycle/LifeCycle.php b/modules/metastore/src/LifeCycle/LifeCycle.php index 8f4b5e1f72..b912d04c60 100644 --- a/modules/metastore/src/LifeCycle/LifeCycle.php +++ b/modules/metastore/src/LifeCycle/LifeCycle.php @@ -161,11 +161,11 @@ protected function distributionLoad(MetastoreItemInterface $data) { if (isset($downloadUrl) && !filter_var($downloadUrl, FILTER_VALIDATE_URL)) { $resourceIdentifier = $downloadUrl; - $downloadInfo = $this->retrieveDownloadUrlFromResourceMapper($resourceIdentifier); - $ref = (array) $downloadInfo[0] ?? []; - $original = $downloadInfo[1] ?? ''; + $ref = NULL; + $original = NULL; + [$ref, $original] = $this->retrieveDownloadUrlFromResourceMapper($resourceIdentifier); - $downloadUrl = isset($original) ? $original : ''; + $downloadUrl = isset($original) ? $original : ""; $refProperty = "%Ref:downloadURL"; $metadata->data->{$refProperty} = count($ref) == 0 ? NULL : $ref; diff --git a/modules/metastore/src/Storage/ResourceMapperDatabaseTable.php b/modules/metastore/src/Storage/ResourceMapperDatabaseTable.php index e5032c542d..32f159987d 100644 --- a/modules/metastore/src/Storage/ResourceMapperDatabaseTable.php +++ b/modules/metastore/src/Storage/ResourceMapperDatabaseTable.php @@ -121,7 +121,7 @@ public function primaryKey() { /** * Protected. */ - protected function getNonSerialFields(): array { + protected function getNonSerialFields() { $fields = parent::getNonSerialFields(); $index = array_search($this->primaryKey(), $fields); if ($index !== FALSE) { diff --git a/modules/metastore/tests/src/Functional/Api1/DatasetItemTest.php b/modules/metastore/tests/src/Functional/Api1/DatasetItemTest.php index 44afca3752..58da82893d 100644 --- a/modules/metastore/tests/src/Functional/Api1/DatasetItemTest.php +++ b/modules/metastore/tests/src/Functional/Api1/DatasetItemTest.php @@ -19,7 +19,7 @@ public function testList() { ->get->responses->{"200"}->content->{"application/json"}->schema; $response = $this->http->request('GET', $this->endpoint); $responseBody = json_decode($response->getBody()); - $this->assertCount(2, $responseBody); + $this->assertEquals(2, count($responseBody)); $this->assertTrue(is_object($responseBody[1])); $this->assertJsonIsValid($responseSchema, $responseBody); } @@ -131,4 +131,4 @@ private function assertDatasetGet($dataset) { $this->assertEquals($dataset, $responseBody); } -} +} \ No newline at end of file diff --git a/modules/metastore/tests/src/Functional/Api1/DatasetRevisionTest.php b/modules/metastore/tests/src/Functional/Api1/DatasetRevisionTest.php index b9cba62cc4..49cf40a389 100644 --- a/modules/metastore/tests/src/Functional/Api1/DatasetRevisionTest.php +++ b/modules/metastore/tests/src/Functional/Api1/DatasetRevisionTest.php @@ -28,7 +28,7 @@ public function testList() { ]); $responseBody = json_decode($response->getBody()); $this->assertEquals(200, $response->getStatusCode()); - $this->assertCount(2, $responseBody); + $this->assertEquals(2, count($responseBody)); $this->assertTrue($responseBody[0]->identifier > $responseBody[1]->identifier); $this->assertTrue($responseBody[0]->published); @@ -146,7 +146,7 @@ public function testPost() { RequestOptions::AUTH => $this->auth, ]); $responseBody = json_decode($response->getBody()); - $this->assertEquals($count, is_countable($responseBody) ? count($responseBody) : 0); + $this->assertEquals($count, count($responseBody)); // Confirm dataset visibility matches expected. $expectedCode = $public ? 200 : 404; @@ -166,7 +166,7 @@ public function testPost() { RequestOptions::AUTH => $this->auth, ]); $responseBody = json_decode($response->getBody()); - $this->assertEquals($count, is_countable($responseBody) ? count($responseBody) : 0); + $this->assertEquals($count, count($responseBody)); // Test a bad dataset ID. $newRevision = (object) [ @@ -185,7 +185,7 @@ public function testPost() { RequestOptions::AUTH => $this->auth, ]); $responseBody = json_decode($response->getBody()); - $this->assertEquals($count, is_countable($responseBody) ? count($responseBody) : 0); + $this->assertEquals($count, count($responseBody)); } diff --git a/modules/metastore/tests/src/Functional/DatasetSpecificDocsTest.php b/modules/metastore/tests/src/Functional/DatasetSpecificDocsTest.php index f2d6199646..d8b7302f70 100644 --- a/modules/metastore/tests/src/Functional/DatasetSpecificDocsTest.php +++ b/modules/metastore/tests/src/Functional/DatasetSpecificDocsTest.php @@ -11,7 +11,7 @@ class DatasetSpecificDocsTest extends ExistingSiteBase { use CleanUp; - private string $downloadUrl = "https://dkan-default-content-files.s3.amazonaws.com/phpunit/district_centerpoints_small.csv"; + private $downloadUrl = "https://dkan-default-content-files.s3.amazonaws.com/phpunit/district_centerpoints_small.csv"; /** * diff --git a/modules/metastore/tests/src/Functional/OnPreReferenceTest.php b/modules/metastore/tests/src/Functional/OnPreReferenceTest.php index ab5b3b7eaa..8c88db05b3 100644 --- a/modules/metastore/tests/src/Functional/OnPreReferenceTest.php +++ b/modules/metastore/tests/src/Functional/OnPreReferenceTest.php @@ -11,7 +11,7 @@ class OnPreReferenceTest extends ExistingSiteBase { use CleanUp; - private string $downloadUrl = "https://dkan-default-content-files.s3.amazonaws.com/phpunit/district_centerpoints_small.csv"; + private $downloadUrl = "https://dkan-default-content-files.s3.amazonaws.com/phpunit/district_centerpoints_small.csv"; /** * diff --git a/modules/metastore/tests/src/Functional/Storage/NodeDataTest.php b/modules/metastore/tests/src/Functional/Storage/NodeDataTest.php index ce5e3009b4..f52617d32b 100644 --- a/modules/metastore/tests/src/Functional/Storage/NodeDataTest.php +++ b/modules/metastore/tests/src/Functional/Storage/NodeDataTest.php @@ -50,16 +50,16 @@ public function testStorageRetrieveMethods() { $allPublished = $datasetStorage->retrieveAll(); $datasetData = json_decode($allPublished[0]); $this->assertEquals("123", $datasetData->identifier); - $this->assertCount(1, $allPublished); + $this->assertEquals(1, count($allPublished)); $all = $datasetStorage->retrieveAll(NULL, NULL, TRUE); - $this->assertCount(2, $all); + $this->assertEquals(2, count($all)); $rangeUnpublished = $datasetStorage->retrieveAll(0, 1, TRUE); - $this->assertCount(1, $rangeUnpublished); + $this->assertEquals(1, count($rangeUnpublished)); $allIds = $datasetStorage->retrieveIds(NULL, NULL, TRUE); - $this->assertCount(2, $allIds); + $this->assertEquals(2, count($allIds)); $this->assertEquals("456", $allIds[1]); $this->expectException(MissingObjectException::class); diff --git a/modules/metastore/tests/src/Unit/DatabaseTableMock.php b/modules/metastore/tests/src/Unit/DatabaseTableMock.php index 475387d95b..8bb81d0b3c 100644 --- a/modules/metastore/tests/src/Unit/DatabaseTableMock.php +++ b/modules/metastore/tests/src/Unit/DatabaseTableMock.php @@ -9,8 +9,8 @@ * */ class DatabaseTableMock implements DatabaseTableInterface { - private int $id = 0; - private array $store = []; + private $id = 0; + private $store = []; public function primaryKey() { return 'id'; diff --git a/modules/metastore/tests/src/Unit/MetastoreSubscriberTest.php b/modules/metastore/tests/src/Unit/MetastoreSubscriberTest.php index 42b7533f15..b261d102e7 100644 --- a/modules/metastore/tests/src/Unit/MetastoreSubscriberTest.php +++ b/modules/metastore/tests/src/Unit/MetastoreSubscriberTest.php @@ -34,7 +34,7 @@ class MetastoreSubscriberTest extends TestCase { * * @var string */ - public const HOST = 'http://h-o.st'; + const HOST = 'http://h-o.st'; /** * The ValidMetadataFactory class used for testing. diff --git a/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php b/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php index ffeb868e73..2b4871374f 100644 --- a/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php +++ b/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php @@ -23,7 +23,7 @@ use Drupal\node\Entity\Node; use Drupal\node\NodeStorage; -use GuzzleHttp\Exception\ConnectException; +use GuzzleHttp\Exception\RequestException; use MockChain\Chain; use MockChain\Options; use PHPUnit\Framework\TestCase; @@ -38,23 +38,23 @@ class ReferencerTest extends TestCase { * * @var string */ - public const FILE_PATH = 'tmp/mycsv.csv'; + const FILE_PATH = 'tmp/mycsv.csv'; /** * HTTP host protocol and domain for testing download URL. * * @var string */ - public const HOST = 'http://example.com'; + const HOST = 'http://example.com'; - public const MIME_TYPE = 'text/csv'; + const MIME_TYPE = 'text/csv'; /** * List referenceable dataset properties. * * @var string[] */ - public const REFERENCEABLE_PROPERTY_LIST = [ + const REFERENCEABLE_PROPERTY_LIST = [ 'keyword' => 0, 'distribution' => 'distribution', 'title' => 0, @@ -452,7 +452,7 @@ public function getMimeType() { return ReferencerTest::MIME_TYPE; } $this->assertEquals(self::MIME_TYPE, $container_chain->getStoredInput('resource')[0]->getMimeType(), 'Unable to fetch MIME type for remote file'); // Test Mime Type detection on a invalid remote file path. $data = $this->getData('http://invalid'); - $this->expectException(ConnectException::class); + $this->expectException(RequestException::class); $referencer->reference($data); } diff --git a/modules/metastore/tests/src/Unit/SchemaRetrieverTest.php b/modules/metastore/tests/src/Unit/SchemaRetrieverTest.php index 06392c4f9b..2ebc9b4bd0 100644 --- a/modules/metastore/tests/src/Unit/SchemaRetrieverTest.php +++ b/modules/metastore/tests/src/Unit/SchemaRetrieverTest.php @@ -19,7 +19,7 @@ class SchemaRetrieverTest extends TestCase { use ServiceCheckTrait; - public const APP_ROOT = __DIR__ . '/../files'; + const APP_ROOT = __DIR__ . '/../files'; /** * Protected. diff --git a/modules/metastore/tests/src/Unit/Storage/DataTest.php b/modules/metastore/tests/src/Unit/Storage/DataTest.php index a58d30061d..b37e8d2675 100644 --- a/modules/metastore/tests/src/Unit/Storage/DataTest.php +++ b/modules/metastore/tests/src/Unit/Storage/DataTest.php @@ -103,9 +103,9 @@ public function testRetrieveRangeUuids(): void { for ($i = 0; $i < 5; $i ++) { $nodes[$i] = new class { - private ?string $uuid = null; + private $uuid; public function uuid() { - return $this->uuid ?? ($this->uuid = uniqid()); + return isset($this->uuid) ? $this->uuid : $this->uuid = uniqid(); } }; $uuids[$i] = $nodes[$i]->uuid(); diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000000..88cb1ffeeb --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,26 @@ + + + + Default PHP CodeSniffer configuration for Drupal core. + + . + + + + + + + + + + + + + + + + + + + + diff --git a/rector.php b/rector.php index 41fdf43282..0d0d4caa71 100644 --- a/rector.php +++ b/rector.php @@ -1,5 +1,9 @@ rule(\Rector\Php71\Rector\FuncCall\CountOnNullRector::class); - $parameters = $rectorConfig->parameters(); $drupalFinder = new DrupalFinder(); From 254489da0bb004e528bbd54e5c245c737d2367b3 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Thu, 30 Mar 2023 10:37:00 -0700 Subject: [PATCH 19/22] test fix --- .../tests/src/Unit/Reference/ReferencerTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php b/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php index 2b4871374f..ffeb868e73 100644 --- a/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php +++ b/modules/metastore/tests/src/Unit/Reference/ReferencerTest.php @@ -23,7 +23,7 @@ use Drupal\node\Entity\Node; use Drupal\node\NodeStorage; -use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Exception\ConnectException; use MockChain\Chain; use MockChain\Options; use PHPUnit\Framework\TestCase; @@ -38,23 +38,23 @@ class ReferencerTest extends TestCase { * * @var string */ - const FILE_PATH = 'tmp/mycsv.csv'; + public const FILE_PATH = 'tmp/mycsv.csv'; /** * HTTP host protocol and domain for testing download URL. * * @var string */ - const HOST = 'http://example.com'; + public const HOST = 'http://example.com'; - const MIME_TYPE = 'text/csv'; + public const MIME_TYPE = 'text/csv'; /** * List referenceable dataset properties. * * @var string[] */ - const REFERENCEABLE_PROPERTY_LIST = [ + public const REFERENCEABLE_PROPERTY_LIST = [ 'keyword' => 0, 'distribution' => 'distribution', 'title' => 0, @@ -452,7 +452,7 @@ public function getMimeType() { return ReferencerTest::MIME_TYPE; } $this->assertEquals(self::MIME_TYPE, $container_chain->getStoredInput('resource')[0]->getMimeType(), 'Unable to fetch MIME type for remote file'); // Test Mime Type detection on a invalid remote file path. $data = $this->getData('http://invalid'); - $this->expectException(RequestException::class); + $this->expectException(ConnectException::class); $referencer->reference($data); } From 614d4f535cc5eb783686f2bf64a086a9d91822aa Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Mon, 3 Apr 2023 08:37:39 -0700 Subject: [PATCH 20/22] codeclimate yaml --- .codeclimate.yml | 66 ++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 771c130b8c..5915ccf703 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -6,36 +6,36 @@ plugins: config: standard: "Drupal,DrupalPractice" exclude_patterns: - - "cypress/" - - "config/" - - "db/" - - "dist/" - - "docs/" - - "documentation/" - - "features/" - - "**/node_modules/" - - "script/" - - "**/spec/" - - "**/test/" - - "**/tests/" - - "Tests/" - - "**/vendor/" - - "**/*_test.go" - - "**/*.d.ts" - - "**/*.yml" - - "**/*.json" - - "**/*.js" - - "**/*.jsx" - - "*.md" - - "**/*.md" - - "*.install" - - "*.profile" - - "*.module" - - "*.xml" - - "**/*.xml" - - "**/*.install" - - "**/*.profile" - - "**/*.module" - - ".circleci/" - - ".gitignore" - - "rector.php" + - "cypress/" + - "config/" + - "db/" + - "dist/" + - "docs/" + - "documentation/" + - "features/" + - "**/node_modules/" + - "script/" + - "**/spec/" + - "**/test/" + - "**/tests/" + - "Tests/" + - "**/vendor/" + - "**/*_test.go" + - "**/*.d.ts" + - "**/*.yml" + - "**/*.json" + - "**/*.js" + - "**/*.jsx" + - "*.md" + - "**/*.md" + - "*.install" + - "*.profile" + - "*.module" + - "*.xml" + - "**/*.xml" + - "**/*.install" + - "**/*.profile" + - "**/*.module" + - ".circleci/" + - ".gitignore" + - "rector.php" From a085c95376566ebe4ff45ceb074716d0f6879e28 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Mon, 3 Apr 2023 08:46:47 -0700 Subject: [PATCH 21/22] removed rector.php --- .codeclimate.yml | 1 - rector.php | 59 ------------------------------------------------ 2 files changed, 60 deletions(-) delete mode 100644 rector.php diff --git a/.codeclimate.yml b/.codeclimate.yml index 5915ccf703..7f749ff32a 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -38,4 +38,3 @@ exclude_patterns: - "**/*.module" - ".circleci/" - ".gitignore" - - "rector.php" diff --git a/rector.php b/rector.php deleted file mode 100644 index 0d0d4caa71..0000000000 --- a/rector.php +++ /dev/null @@ -1,59 +0,0 @@ -sets([ - LevelSetList::UP_TO_PHP_74, - ]); - $rectorConfig->skip([ - JsonThrowOnErrorRector::class, - ClosureToArrowFunctionRector::class, - ]); - $rectorConfig->ruleWithConfiguration( - ReturnTypeWillChangeRector::class, - [new ClassMethodReference('JsonSerializable', 'jsonSerialize')] - ); - - $parameters = $rectorConfig->parameters(); - - $drupalFinder = new DrupalFinder(); - $drupalFinder->locateRoot(__DIR__); - $drupalRoot = $drupalFinder->getDrupalRoot(); - $rectorConfig->autoloadPaths([ - $drupalRoot . '/core', - $drupalRoot . '/modules', - $drupalRoot . '/profiles', - $drupalRoot . '/themes', - ]); - - $rectorConfig->fileExtensions([ - 'php', - 'module', - 'theme', - 'install', - 'profile', - 'inc', - 'engine', - ]); - $rectorConfig->importNames(TRUE, FALSE); - $rectorConfig->importShortClasses(FALSE); - $parameters->set('drupal_rector_notices_as_comments', TRUE); -}; From d176f77f81bdacef2269c01ecc68b61f01185200 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Mon, 3 Apr 2023 09:02:31 -0700 Subject: [PATCH 22/22] rm phpcs.xml --- phpcs.xml | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 phpcs.xml diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index 88cb1ffeeb..0000000000 --- a/phpcs.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - Default PHP CodeSniffer configuration for Drupal core. - - . - - - - - - - - - - - - - - - - - - - -