Is there a script, console, drush command etc that can dump a node in the format needed to create a test case?

How can I rapidly fill out

$this->drupalCreateContentType(['type' => 'bond',
  'name' => 'Bond',
  'field_bond_amt_issued' => '1000000000',

You can use drush:

drush ev "var_export(\Drupal\node\Entity\Node::load(123)->toArray());"

and delete stuff you don't need like uuid, revision_*, ...

By the way if you are wondering why does this output old style array syntax, see https://stackoverflow.com/questions/24316347/how-to-format-var-export-to-php5-4-array-syntax

... or paste the output into your IDE and configure it to autocorrect the format.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.