Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 31

Use it for questions about automated Drupal tests.

5 votes
Accepted

How to shadow a core function used in two different tests files?

Wrap it in a !function_exists() See core/tests/Drupal/Tests/Core/Render/Element/MachineNameTest.php for example: <?php namespace Drupal\Core\Render\Element; if (!function_exists('t')) { functio …
Berdir's user avatar
  • 83.5k
0 votes

how to exclude PHPUnit based functional tests from runnning?

Since those tests are grouped by namespace/directory, you can just pass the respective path to phpunit, simply add tests/src/Unit to your existing path.
Berdir's user avatar
  • 83.5k
2 votes
Accepted

How to test an exception have been logged instead of thrown?

There is no standard test feature to assert a logged message. The simplest approach is to just install dblog in your test and then inspect the watchdog table for the expected record. Alternatively, …
Berdir's user avatar
  • 83.5k
4 votes
Accepted

Running unit test only for my custom module

Sure, all you need to do is provide a path/file to phpunit and it will be limited to that. vendor/bin/phpunit -c core modules/custom
Berdir's user avatar
  • 83.5k
4 votes
Accepted

Error running BrowserTest (Drupal\Core\Config\Schema\SchemaIncompleteException: No schema ...)

The Schema file is: https://github.com/aneek/rate_limiter/blob/develop/config/install/rate_limiter.settings.yml No, that is not the schema file, that is the config file for which you need to crea …
avpaderno's user avatar
  • 97.9k
3 votes
Accepted

Should I translate string inside a Unit test?

No, you should not. An assertion message is basically on the same level as a code comment, you're not translating that either. We used to do that in core, also because it was all Simpletest then and …
Berdir's user avatar
  • 83.5k
4 votes

How to unit test hook_form_alter implementation code in custom module

See https://www.drupal.org/docs/8/testing/types-of-tests-in-drupal-8 for documentation of different types of tests in Drupal 8 and when they should be used. …
Berdir's user avatar
  • 83.5k
5 votes
Accepted

Strategy for unit testing classes that interact with the Entity API

In regards to the testing pyramid, that is the ideal scenario, but it's not always feasible. I also think that it is makes more sense in a scenario where you built and control the whole system. …
Berdir's user avatar
  • 83.5k
12 votes
Accepted

Trying TDD with PHPUnit

My guess is that you're not including the phpunit.xml.dist file, which sits in the core folder. Either run tests from there (./vendor/bin/phpunit ../modules/your_module) or specify that file with -c. …
avpaderno's user avatar
  • 97.9k
3 votes
Accepted

phpunit test: drupalGet a public node returns 404

BrowserTestBase do not run against your installation, they do a new installation and then run against that. There is no content, no modules, pretty much nothing there by default, everything you need …
Berdir's user avatar
  • 83.5k
2 votes

Difficulty running tests, --group option not being respected

edit: This might be my issue. Yes. The error happens during test discovery, first it has to find all tests and then limit it based on the group. The easiest workaround is simply to specifiy you …
Berdir's user avatar
  • 83.5k
2 votes
Accepted

How to rebuild derived plugins after new entities are installed?

Yes you should do that. Module install is not really a problem as all plugins are invalidated then anyway, but entities can also be changed in the UI. See \Drupal\block_content\Entity\BlockContent:: …
Berdir's user avatar
  • 83.5k
3 votes
Accepted

How to force cron to use config saved during a SimpleTest?

As commented, you were missing the save call in the test. That means that the change is only in the runtime object returned by getEditable() and since get() and getEditable() do not share the static …
avpaderno's user avatar
  • 97.9k
0 votes
Accepted

Functional test not displaying context aware block

As discussed in IRC, pretty sure your problem is $this->drupalPlaceBlock('my_context_aware_block'); which doesn't configure the necessary context mapping. That's not visible in the UI if you only have …
Berdir's user avatar
  • 83.5k
3 votes
Accepted

Why is doing KernelTests Code Coverage so slow?

A kernel tests actually installs Drupal (in-memory only, but still), that means it runs thounsands and thousands of lines of code. You can't really do anything to change that, xdebug (I guess you use …
Berdir's user avatar
  • 83.5k

15 30 50 per page