Auto clean-up entities
When creating entities through form submissions it's really hard to track them. Is it possible to clean-up entities automatically?
I think that can be implemented as follows.
- Add a protected property to DrupalTrait which would hold entity types to clean-up.
- In ::setupDrupal() fetch all ID's for the specified entity types and store them in a private property.
- In ::tearDownDrupal() fetch those ID's once again and calculate a difference with
array_diff
. - Remove newly created entities.
From the user perspective enabling this option would by as simple as overriding autoCleanup property in a test class. Like this.
$this->autoCleanup = ['node'];