"value":"\n <p>Happy Christmas!<\/p>\n\n<p>Here's my present - a sneak peek at the first lesson in my free upcoming Automated Testing for Drupal email course.<\/p>\n\n<p>In this lesson, we start from scratch and end with a working test suite.<\/p>\n\n<p>If you like it, <a href=\"https:\/\/www.oliverdavies.uk\/atdc\">register for free and get the full course<\/a> when it launches.<\/p>\n\n<h2 id=\"creating-a-drupal-project\">Creating a Drupal project<\/h2>\n\n<p>If you don't have one, you'll need to create a new Drupal project. I'd suggest using Drupal 10.2 and the instructions at <a href=\"https:\/\/www.drupal.org\/download\">https:\/\/www.drupal.org\/download<\/a>.<\/p>\n\n<p>You'll need <a href=\"https:\/\/www.php.net\/manual\/en\/install.php\">PHP<\/a> and <a href=\"https:\/\/getcomposer.org\/doc\/00-intro.md\">Composer<\/a>.<\/p>\n\n<p>First, run <code>composer create-project drupal\/recommended-project drupal<\/code> followed by <code>cd drupal && composer require --dev drupal\/core-dev<\/code> to add the development dependencies, including PHPUnit.<\/p>\n\n<p>At this point, you should have a <code>web<\/code> directory and a <code>phpunit<\/code> file within <code>vendor\/bin<\/code>.<\/p>\n\n<p>Finally, run <code>php -S 0.0.0.0:8000 -t web<\/code> to start a local web server.<\/p>\n\n<p>You don't need to install Drupal - as long as you see the installation page, that's fine.<\/p>\n\n<h2 id=\"creating-a-custom-module\">Creating a custom module<\/h2>\n\n<p>Before adding tests, you must create a module to place them in.<\/p>\n\n<p>Run <code>mkdir -p web\/modules\/custom\/atdc<\/code> to create an empty module directory, and create an <code>atdc.info.yml<\/code> file within it with this content:<\/p>\n\n<pre><code class=\"language-yaml\">name: Example\ntype: module\ncore_version_requirement: ^10\npackage: Custom\n<\/code><\/pre>\n\n<p>This is the minimum content needed for a module to be installable.<\/p>\n\n<h3 id=\"writing-your-first-test-class\">Writing your first test class<\/h3>\n\n<p>Test classes are placed within each module's <code>tests\/src<\/code> directory.<\/p>\n\n<p>Run <code>mkdir -p web\/modules\/custom\/atdc\/tests\/src\/Functional && touch web\/modules\/custom\/atdc\/tests\/src\/Functional\/ExampleTest.php<\/code> to create the directory structure and a blank test class.<\/p>\n\n<p>Then, add this content.<\/p>\n\n<pre><code class=\"language-php\"><?php\n\nnamespace Drupal\\Tests\\atdc\\Functional;\n\nuse Drupal\\Tests\\BrowserTestBase;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\nclass ExampleTest extends BrowserTestBase {\n\n\u00a0 public $defaultTheme = 'stark';\n\n}\n<\/code><\/pre>\n\n<p>Note: within a test class, the namespace is <code>Drupal\\Tests\\{module_name}<\/code> instead of <code>Drupal\\{module_name}<\/code>.<\/p>\n\n<p>With the boilerplate class added, create a test method within it:<\/p>\n\n<pre><code class=\"language-php\">public function testBasic(): void {\n\u00a0 self::assertTrue(FALSE);\n}\n<\/code><\/pre>\n\n<p>Note: the class name must be suffixed with <code>Test<\/code>, and the test method must be prefixed with <code>test<\/code> for them to be run.<\/p>\n\n<p>Now we have a test with an assertion, we need to run it and see if it passes.<\/p>\n\n<h2 id=\"running-the-test\">Running the test<\/h2>\n\n<p>On the command line, run <code>vendor\/bin\/phpunit web\/modules\/custom<\/code>, and you'll get an error like:<\/p>\n\n<blockquote>\n <p>PHPUnit\\TextUI\\RuntimeException: Class \"Drupal\\Tests\\BrowserTestBase\" not found.<\/p>\n<\/blockquote>\n\n<p>This isn't an assertion failure, but that PHPUnit can't find the files it needs to run.<\/p>\n\n<p>To fix this, let's configure PHPUnit.<\/p>\n\n<h2 id=\"configuring-phpunit\">Configuring PHPUnit<\/h2>\n\n<p>Create a new <code>phpunit.xml.dist<\/code> file at the root of your project, with this content:<\/p>\n\n<pre><code class=\"xml\"><?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit bootstrap=\"web\/core\/tests\/bootstrap.php\" colors=\"true\">\n<php>\n
"format":"full_html",
"processed":"\n <p>Happy Christmas!<\/p>\n\n<p>Here's my present - a sneak peek at the first lesson in my free upcoming Automated Testing for Drupal email course.<\/p>\n\n<p>In this lesson, we start from scratch and end with a working test suite.<\/p>\n\n<p>If you like it, <a href=\"https:\/\/www.oliverdavies.uk\/atdc\">register for free and get the full course<\/a> when it launches.<\/p>\n\n<h2 id=\"creating-a-drupal-project\">Creating a Drupal project<\/h2>\n\n<p>If you don't have one, you'll need to create a new Drupal project. I'd suggest using Drupal 10.2 and the instructions at <a href=\"https:\/\/www.drupal.org\/download\">https:\/\/www.drupal.org\/download<\/a>.<\/p>\n\n<p>You'll need <a href=\"https:\/\/www.php.net\/manual\/en\/install.php\">PHP<\/a> and <a href=\"https:\/\/getcomposer.org\/doc\/00-intro.md\">Composer<\/a>.<\/p>\n\n<p>First, run <code>composer create-project drupal\/recommended-project drupal<\/code> followed by <code>cd drupal && composer require --dev drupal\/core-dev<\/code> to add the development dependencies, including PHPUnit.<\/p>\n\n<p>At this point, you should have a <code>web<\/code> directory and a <code>phpunit<\/code> file within <code>vendor\/bin<\/code>.<\/p>\n\n<p>Finally, run <code>php -S 0.0.0.0:8000 -t web<\/code> to start a local web server.<\/p>\n\n<p>You don't need to install Drupal - as long as you see the installation page, that's fine.<\/p>\n\n<h2 id=\"creating-a-custom-module\">Creating a custom module<\/h2>\n\n<p>Before adding tests, you must create a module to place them in.<\/p>\n\n<p>Run <code>mkdir -p web\/modules\/custom\/atdc<\/code> to create an empty module directory, and create an <code>atdc.info.yml<\/code> file within it with this content:<\/p>\n\n<pre><code class=\"language-yaml\">name: Example\ntype: module\ncore_version_requirement: ^10\npackage: Custom\n<\/code><\/pre>\n\n<p>This is the minimum content needed for a module to be installable.<\/p>\n\n<h3 id=\"writing-your-first-test-class\">Writing your first test class<\/h3>\n\n<p>Test classes are placed within each module's <code>tests\/src<\/code> directory.<\/p>\n\n<p>Run <code>mkdir -p web\/modules\/custom\/atdc\/tests\/src\/Functional && touch web\/modules\/custom\/atdc\/tests\/src\/Functional\/ExampleTest.php<\/code> to create the directory structure and a blank test class.<\/p>\n\n<p>Then, add this content.<\/p>\n\n<pre><code class=\"language-php\"><?php\n\nnamespace Drupal\\Tests\\atdc\\Functional;\n\nuse Drupal\\Tests\\BrowserTestBase;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\nclass ExampleTest extends BrowserTestBase {\n\n public $defaultTheme = 'stark';\n\n}\n<\/code><\/pre>\n\n<p>Note: within a test class, the namespace is <code>Drupal\\Tests\\{module_name}<\/code> instead of <code>Drupal\\{module_name}<\/code>.<\/p>\n\n<p>With the boilerplate class added, create a test method within it:<\/p>\n\n<pre><code class=\"language-php\">public function testBasic(): void {\n self::assertTrue(FALSE);\n}\n<\/code><\/pre>\n\n<p>Note: the class name must be suffixed with <code>Test<\/code>, and the test method must be prefixed with <code>test<\/code> for them to be run.<\/p>\n\n<p>Now we have a test with an assertion, we need to run it and see if it passes.<\/p>\n\n<h2 id=\"running-the-test\">Running the test<\/h2>\n\n<p>On the command line, run <code>vendor\/bin\/phpunit web\/modules\/custom<\/code>, and you'll get an error like:<\/p>\n\n<blockquote>\n <p>PHPUnit\\TextUI\\RuntimeException: Class \"Drupal\\Tests\\BrowserTestBase\" not found.<\/p>\n<\/blockquote>\n\n<p>This isn't an assertion failure, but that PHPUnit can't find the files it needs to run.<\/p>\n\n<p>To fix this, let's configure PHPUnit.<\/p>\n\n<h2 id=\"configuring-phpunit\">Configuring PHPUnit<\/h2>\n\n<p>Create a new <code>phpunit.xml.dist<\/code> file at the root of your project, with this content:<\/p>\n\n<pre><code class=\"xml\"><?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<phpunit bootstrap=\"web\/core\/tests\/bootstrap.php\" colors=\"true\">\n<php>\