Task to convert core/modules/search/lib/Drupal/search/Tests/SearchExpressionInsertExtractTest.php to phpunit.

See #1938068: Convert UnitTestBase to PHPUnit.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhedstrom’s picture

Status: Active » Needs review
FileSize
2.92 KB

Again fairly simple.

dawehner’s picture

It would be great to convert this to dataProviders

$cases = array(
array('foo', 'bar', 'foo:bar', 'bar'), // Normal case.
array('foo', NULL, '', NULL), // Empty value: shouldn't insert.
array('foo', ' ', 'foo:', ''), // Space as value: should insert but retrieve empty string.
array('foo', '', 'foo:', ''), // Empty string as value: should insert but retrieve empty string.
array('foo', '0', 'foo:0', '0'), // String zero as value: should insert.
array('foo', 0, 'foo:0', '0'), // Numeric zero as value: should insert.
);

PS: It might make sense to put this static stuff into classes.

dawehner’s picture

Status: Needs review » Needs work

.

ParisLiakos’s picture

yeah we should first convert procedural code to OOP and its test to PHPUnit first:) not the other way around

dawehner’s picture

Status: Needs work » Needs review
FileSize
10.37 KB

Instead of relying on pure static methods I think we have clearly an object here: the search expression.

ParisLiakos’s picture

besides the assertion message everything looks good. if we want to keep them we should reverse them, so they make some sense when phpunit displays them (only upon failure)

dawehner’s picture

Title: Convert core/modules/search/lib/Drupal/search/Tests/SearchExpressionInsertExtractTest.php to phpunit » Convert core/modules/search/lib/Drupal/search/Tests/SearchExpressionTest.php to phpunit
FileSize
1.95 KB
10.37 KB

The message should be also inverted, as it is just displayed on failure.

Status: Needs review » Needs work
Issue tags: -PHPUnit

The last submitted patch, search_expression-2002190-7.patch, failed testing.

ParisLiakos’s picture

Status: Needs work » Needs review

#7: search_expression-2002190-7.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +PHPUnit

The last submitted patch, search_expression-2002190-7.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
FileSize
10.36 KB
889 bytes

There was a typo in #7, where both arguments were passed to trim(). This version removes trim() altogether as I didn't see the need for it.

dawehner’s picture

Oh thanks! I fear that I can't RTBC it.

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

i love this patch, thanks!

jhedstrom’s picture

Regarding the inverting of the messages, my understanding is the printed message should reflect the expected outcome, not an error message, in which case we'd need to flip these messages back to the original text.

ParisLiakos’s picture

this is the case for simpletest not PHPUnit. PHPUnit only displays those messages upon failure.
assertEquals example:

Reports an error identified by $message if the two variables $expected and $actual are not equal.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 7b0039e and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.

jhedstrom’s picture