Problem/Motivation
As #1567500: [meta] Replace the testing framework with PHPUnit and possibly rewrite Simpletest is underway we need to convert all Simpletest based unittest to PhpUnit tests.
Proposed resolution
Let's create patches for each directory from the list.
Make sure you use
git diff -M 8.x
Remaining tasks
Documentation for PHPUnit's mocks and stubs: http://phpunit.de/manual/current/en/test-doubles.html
As an example for modules see breakpoint module core/modules/breakpoint/tests/Drupal/breakpoint/Tests/
For Core or Component we already have several tests core/tests/Drupal/Tests/Core|Component
.
- If a test is in the system module, and it tests a class not in system module, then it should be moved to
core/tests/Drupal/Tests/
directory - If a class contains
Unit
in its name, remove it when converting to PHPUnit..there is no point keeping it. - If a class can be converted to use dataproviders it should
As mentioned in #1938068-11: [Meta] Convert UnitTestBase to PHPUnit
Open Issues
core/modules/simpletest/lib/Drupal/simpletest/Tests/MissingDependentModuleUnitTest.php cannot be converted to phpunit since it actually tests Simpletest itself (which requires Drupal bootstrap, etc). Not sure if it deserves a separate issue, or if it should just be removed from this issue summary.
Fill in the documentation void of http://drupal.org/node/1814344 Agile Unit Testing section 'Unit Test Organization'
TODO
#1996868: Start converting image.inc to an Image component
#1938130: Convert User tests to PHPUnit
#2003800: Move drupal_check_memory_limit() and parse_size() functionality to components
#2008566: Convert PasswordHashingTest unit tests to phpunit
#2035133: Convert system module's Mail unit test to phpunit
#2042739: Convert system module's ControllerResolverTest to phpunit
#2051467: Expand and convert to phpunit tests for \Drupal\Component\Transliteration
#2130551: Convert system modules MimeTypeMatcherTest to phpunit
(And then 44 more tests from system module.)
In core / lib / Drupal / Component
Component might be a good place to aim for 100% coverage.
Really though we want to make issues to remove procedural code from classes,
and declare the dependencies (dependency injection), and then add phpunit tests in the issue to "Declare dependecies in *classWhatever*".
Fill in issue numbers if related to getting those tests in, or issue numbers for new issues created to convert tests or improve coverage. Let's try and do one issue per class.
- (todo: improve. done: convert) Datetime, DateTimePlus 83% #2003698: Convert system module's Datetime unit tests to phpunit
- (done) Graph 100% #1935908: Convert Graph tests to phpunit
- Image 100%
- PhpStorage 100% #2051385: Expand phpunit tests for \Drupal\Component\PhpStorage
- FileReadOnlyStorage 77%
- FileStorage 63%
- MTimeProtectedFastFileStorage 83%
- PhpStorageFactory 52%
- Plugin 48% #2052109: Expand phpunit tests for \Drupal\Component\Plugin classes
- Discovery, StaticDiscovery 50%
- PluginBag 56%
- PluginBase 66%
- PluginManagerBase 20%
- Transliteration, PHPTransliteration 86% #2051467: Expand and convert to phpunit tests for \Drupal\Component\Transliteration
- Utitlity 67%
- Crypt 62% #2046207: Expand phpunit tests for \Drupal\Component\Utility\Crypt
- DiffArray 100%
- Json 100%
- MapArray 100%
- NestedArray 100% #2050535: Expand phpunit tests for \Drupal\Component\Utility\NestedArray
- Random 100%
- Settings 100% #2035863: Expand phpunit tests for \Drupal\Component\Utility\Settings
- String 100%
- Tags 100%
- Timer 38% #2049817: Expand phpunit tests for \Drupal\Component\Utility\Timer
- Unicode 48% #1938670: Convert unicode.inc to \Drupal\Component\Utility\Unicode, #2051717: Expand phpunit tests for \Drupal\Component\Utility\Unicode
- Url 39% #2046245: Expand phpunit tests for \Drupal\Component\Utility\Url
- Xss 83%
In core / lib / Drupal / Core / Batch
Batch has 3 classes, but 2 are not in phpunit coverage output since code is not autoloaded as part of tests.
- BatchStorage 0% #2035825: Declare dependencies in BatchStorage and test with phpunit testsAssigned to: splatio
- BatchStorageInterface 0%
- Percentage 100% #2003736: Convert system module's Batch unit tests to phpunit
Done
#2003762: Convert system module's Uuid unit tests to phpunit
#1938184: Convert Drupal\Core\Utility\Color\ColorTest to PHPUnit
#1991078: Convert MachineNameControllerTest to PHPUnit
#1901670: Start using PHPUnit for unit tests
#1935970: Convert timer_* to a utility class and convert tests to phpunit
#1957302: Convert PathProcessorTest to PHPUnit
#2001218: Convert core/modules/views/lib/Drupal/views/Tests/PluginTypeListTest.php to phpunit
#2003342: Convert system module's database unit tests to phpunit
#2002190: Convert core/modules/search/lib/Drupal/search/Tests/SearchExpressionTest.php to phpunit
#2003568: Convert tags,attributes, diff and url validation unit tests to phpunit
#2006568: Convert filter_xss tests to unit tests
#2016299: Convert system module's JsonUnitTest to phpunit
#2042745: Convert system module's RouteTest to phpunit
#2002116: Convert core/modules/update/lib/Drupal/update/Tests/UpdateCoreUnitTest.php to phpunit
#2030173: Convert system module's ValidNumberStepUnitTest to phpunit
API changes
The UnitTest files are moved to ... tbd
====
See coder #1938066: Prepare for phpunit tests