<p>In one of the lessons in my <a href="/atdc">free automated testing in Drupal email course</a>, I explain how I create configuration that I need within my tests, such as adding a custom field:</p>
<blockquote>
<p>But how do you know what to name the configuration files and what content to put in them?</p>
<p>Rather than trying to write them by hand, I create the configuration I need, such as fields, within a Drupal site and then export and edit the files I need.</p>
</blockquote>
<p>As well as creating the fields in the Drupal UI, I was also using it to export the configuration files I needed:</p>
<blockquote>
<p>Once Drupal is installed and the configuration has been created, you can go to - /admin/config/development/configuration/single/export and select the configuration type and name.</p>
<p>The filename is shown at the bottom of the page, and you can copy the content into files within your module.</p>
</blockquote>
<h2 id="there%27s-another-way">There's another way</h2>
<p>After reading that lesson, somene replied and reminded me that there's a <code>--destination</code> option you can use with the <code>drush config:export</code> command.</p>
<p>Instead of exporting to the standard configuration directory, I can do it to a temporary directory:</p>
<p>Everyhing in a <code>.ignored</code> direcotry is automatically ignored by Git, and to get the files I need, I can use Linux's <code>find</code> command to find any files that contain the field name and copy them into my test module directory:</p>
<p>I still need to edit the files to remove the <code>uuid</code> and <code>_core</code> values, but this approach means less clicking in the Drupal UI which makes me more productive.</p>
<p>I used this approach when <a href="/daily/2024/02/16/keep-logic-within-tests-for-as-long-as-you-can">writing my SaaS code yesterday</a> and it worked well.</p>
<p>In one of the lessons in my <a href="/atdc">free automated testing in Drupal email course</a>, I explain how I create configuration that I need within my tests, such as adding a custom field:</p>
<p>But how do you know what to name the configuration files and what content to put in them?</p>
<p>Rather than trying to write them by hand, I create the configuration I need, such as fields, within a Drupal site and then export and edit the files I need.</p>
</blockquote>
<p>As well as creating the fields in the Drupal UI, I was also using it to export the configuration files I needed:</p>
<blockquote>
<p>Once Drupal is installed and the configuration has been created, you can go to - /admin/config/development/configuration/single/export and select the configuration type and name.</p>
<p>The filename is shown at the bottom of the page, and you can copy the content into files within your module.</p>
</blockquote>
<h2 id="there%27s-another-way">There's another way</h2>
<p>After reading that lesson, somene replied and reminded me that there's a <code>--destination</code> option you can use with the <code>drush config:export</code> command.</p>
<p>Instead of exporting to the standard configuration directory, I can do it to a temporary directory:</p>
<p>Everyhing in a <code>.ignored</code> direcotry is automatically ignored by Git, and to get the files I need, I can use Linux's <code>find</code> command to find any files that contain the field name and copy them into my test module directory:</p>
<p>I still need to edit the files to remove the <code>uuid</code> and <code>_core</code> values, but this approach means less clicking in the Drupal UI which makes me more productive.</p>
<p>I used this approach when <a href="/daily/2024/02/16/keep-logic-within-tests-for-as-long-as-you-can">writing my SaaS code yesterday</a> and it worked well.</p>