Skip to content

Commit

Permalink
Merge pull request #250 from drevops/feature/drupal-10
Browse files Browse the repository at this point in the history
Added Rector and Drupal Check and fixed Drupal 10 compatibility.
  • Loading branch information
jhedstrom authored Nov 23, 2022
2 parents 55af647 + 03ae7c9 commit 6057ebd
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
fail-fast: false
matrix:
php_version: ["7.4", "8.0", "8.1"]
drupal_version: ["9"]
drupal_version: ["9", "10"]
exclude:
- php_version: "7.4"
drupal_version: "10"
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ composer.lock
reports
vendor
drush
/drupal

.phpunit.result.cache
/.editorconfig
/.gitattributes
48 changes: 42 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,38 @@
"php": ">=7.4",
"symfony/process": "~2.5|~3.0|~4.4|^6",
"symfony/dependency-injection": "~2.6|~3.0|~4.4|^6",
"drupal/core-utility": "^8.4 || ^9 || ^10.0.0-alpha1"
"drupal/core-utility": "^8.4 || ^9 || ^10@beta"
},
"require-dev": {
"composer/installers": "^2.1",
"drupal/coder": "~8.3.0",
"phpspec/phpspec": "~2.0 || ~4.0 || ~6.1 || dev-main",
"phpunit/phpunit": "~6.0 || ~7.0 || ^9",
"mockery/mockery": "^0.9.4",
"mockery/mockery": "^1.5",
"drupal/core-composer-scaffold": "^8.4 || ^9 || ^10@beta",
"drupal/core-recommended": "^8.4 || ^9 || ^10@beta",
"drupal/mailsystem": "^4.4",
"drush-ops/behat-drush-endpoint": "*",
"php-parallel-lint/php-parallel-lint": "^1.0",
"dms/phpunit-arraysubset-asserts": "^0.4.0"
"dms/phpunit-arraysubset-asserts": "^0.4.0",
"mglaman/drupal-check": "^1",
"palantirnet/drupal-rector": "^0.13",
"symfony/phpunit-bridge": "^6.1"
},
"conflict": {
"drupal/core": ">=8.0 <9.3"
},
"scripts": {
"test": [
"composer validate --no-interaction",
"parallel-lint src spec tests",
"phpunit",
"phpspec run -f pretty --no-interaction",
"phpcs --standard=./phpcs-ruleset.xml ."

"phpcs --standard=./phpcs-ruleset.xml .",
"./vendor/bin/drupal-check --drupal-root=drupal ./src/Drupal/Driver/Cores/Drupal8.php ./src/Drupal/Driver/Fields/Drupal8",
"cp ./vendor/palantirnet/drupal-rector/rector.php drupal/.",
"cd drupal && ../vendor/bin/rector process ../src/Drupal/Driver/Cores/Drupal8.php --dry-run",
"cd drupal && ../vendor/bin/rector process ../src/Drupal/Driver/Fields/Drupal8 --dry-run"
]
},
"autoload": {
Expand All @@ -42,14 +55,37 @@
"Drupal\\Tests\\Driver" : "tests/"
}
},
"repositories": {
"drupal": {
"type": "composer",
"url": "https://packages.drupal.org/8"
}
},
"prefer-stable": true,
"minimum-stability": "beta",
"extra": {
"branch-alias": {
"dev-master": "2.3.x-dev"
},
"installer-paths": {
"drupal/core": [
"type:drupal-core"
],
"drupal/modules/{$name}": [
"type:drupal-module"
]
},
"drupal-scaffold": {
"locations": {
"web-root": "drupal/"
}
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"drupal/core-composer-scaffold": true,
"composer/installers": true
}
}
}
1 change: 1 addition & 0 deletions phpcs-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/CHANGELOG.md</exclude-pattern>
<exclude-pattern>*/README.md</exclude-pattern>
<exclude-pattern>./drupal/*</exclude-pattern>

</ruleset>
2 changes: 1 addition & 1 deletion src/Drupal/Driver/Cores/Drupal7.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public function languageCreate(\stdClass $language) {

// If the language code is not valid then throw an InvalidArgumentException.
if (!isset($predefined_languages[$language->langcode])) {
throw new InvalidArgumentException("There is no predefined language with langcode '{$language->langcode}'.");
throw new \InvalidArgumentException("There is no predefined language with langcode '{$language->langcode}'.");
}

// Enable a language only if it has not been enabled already.
Expand Down
18 changes: 13 additions & 5 deletions src/Drupal/Driver/Cores/Drupal8.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\DrupalKernel;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Routing\RouteObjectInterface;
use Drupal\Driver\Exception\BootstrapException;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
Expand Down Expand Up @@ -77,6 +78,7 @@ public function clearCache() {
*/
public function nodeCreate($node) {
// Throw an exception if the node type is missing or does not exist.
/** @var \Drupal\node\Entity\Node $node */
if (!isset($node->type) || !$node->type) {
throw new \Exception("Cannot create content because it is missing the required property 'type'.");
}
Expand All @@ -85,11 +87,12 @@ public function nodeCreate($node) {
$bundle_info = \Drupal::service('entity_type.bundle.info');
$bundles = $bundle_info->getBundleInfo('node');
if (!in_array($node->type, array_keys($bundles))) {
throw new \Exception("Cannot create content because provided content type '$node->type' does not exist.");
throw new \Exception(sprintf('Cannot create content because provided content type %s does not exist.', $node->type));
}
// If 'author' is set, remap it to 'uid'.
if (isset($node->author)) {
$user = user_load_by_name($node->author);
/** @var \Drupal\user\Entity\User $user */
if ($user) {
$node->uid = $user->id();
}
Expand Down Expand Up @@ -331,8 +334,13 @@ public function termCreate(\stdClass $term) {
$term->vid = $term->vocabulary_machine_name;

if (isset($term->parent)) {
$parent = \taxonomy_term_load_multiple_by_name($term->parent, $term->vocabulary_machine_name);
$query = \Drupal::entityQuery('taxonomy_term')
->accessCheck(FALSE)
->condition('id', $term->parent)
->condition('vid', $term->vocabulary_machine_name);
$parent = $query->execute();
if (!empty($parent)) {
/** @var \Drupal\taxonomy\Entity\Term $parent */
$parent = reset($parent);
$term->parent = $parent->id();
}
Expand Down Expand Up @@ -382,12 +390,12 @@ public function getExtensionPathList() {
*
* @param string $entity_type
* The entity type for which to return the field types.
* @param object $entity
* @param \StdClass $entity
* Entity object.
* @param array $base_fields
* Base fields to be expanded in addition to user defined fields.
*/
public function expandEntityBaseFields($entity_type, \stdClass $entity, array $base_fields) {
public function expandEntityBaseFields($entity_type, \StdClass $entity, array $base_fields) {
$this->expandEntityFields($entity_type, $entity, $base_fields);
}

Expand Down Expand Up @@ -438,7 +446,7 @@ public function languageCreate(\stdClass $language) {
if (!ConfigurableLanguage::load($langcode)) {
$created_language = ConfigurableLanguage::createFromLangcode($language->langcode);
if (!$created_language) {
throw new InvalidArgumentException("There is no predefined language with langcode '{$langcode}'.");
throw new \InvalidArgumentException("There is no predefined language with langcode '{$langcode}'.");
}
$created_language->save();
return $language;
Expand Down
2 changes: 1 addition & 1 deletion src/Drupal/Driver/DrushDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public function drush($command, array $arguments = [], array $options = []) {
// Add any global arguments.
$global = $this->getArguments();

$process = new Process("{$this->binary} {$alias} {$string_options} {$global} {$command} {$arguments}");
$process = Process::fromShellCommandline("{$this->binary} {$alias} {$string_options} {$global} {$command} {$arguments}");
$process->setTimeout(3600);
$process->run();

Expand Down
4 changes: 2 additions & 2 deletions src/Drupal/Driver/Fields/Drupal8/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class AbstractHandler implements FieldHandlerInterface {
/**
* Constructs an AbstractHandler object.
*
* @param object $entity
* @param \StdClass $entity
* The simulated entity object containing field information.
* @param string $entity_type
* The entity type.
Expand All @@ -35,7 +35,7 @@ abstract class AbstractHandler implements FieldHandlerInterface {
* @throws \Exception
* Thrown when the given field name does not exist on the entity.
*/
public function __construct(\stdClass $entity, $entity_type, $field_name) {
public function __construct(\StdClass $entity, $entity_type, $field_name) {
if (empty($entity_type)) {
throw new \Exception("You must specify an entity type in order to parse entity fields.");
}
Expand Down
4 changes: 1 addition & 3 deletions src/Drupal/Driver/Fields/Drupal8/ImageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public function expand($values) {
}

/** @var \Drupal\file\FileInterface $file */
$file = file_save_data(
$data,
'public://' . uniqid() . '.jpg');
$file = \Drupal::service('file.repository')->writeData($data, 'public://' . uniqid() . '.jpg');

if (FALSE === $file) {
throw new \Exception("Error saving file");
Expand Down

0 comments on commit 6057ebd

Please sign in to comment.