The parent issue highlights test that can be convert to phpunit related tests.

The tests under the spotlight here:

./Image/ToolkitSetupFormTest.php
./Image/ToolkitTest.php
./Image/ToolkitTestBase.php

We are cutting off legacy support for the implicit public API that is ToolkitTestBase.php
Here is the change record.

https://www.drupal.org/node/2873299

CommentFileSizeAuthor
#41 interdiff-2862641-38-41.txt456 bytesmartin107
#41 unconfirmed-2862641-41.patch8.64 KBmartin107
#38 interdiff-34-38.txt1.12 KBmartin107
#38 internal-2809519-38.patch8.65 KBmartin107
#34 interdiff-2862641-33-34.txt427 bytesmartin107
#34 trigger_error-2862641-34.patch8.63 KBmartin107
#33 interdiff-2862641-29-33.txt5.05 KBmartin107
#33 trigger_error-2862641-33.patch8.63 KBmartin107
#29 btb-2862641-29.patch3.9 KBmartin107
#29 interdiff-2862641-26-29.txt596 bytesmartin107
#26 interdiff-2862641-23-26.txt2.23 KBmartin107
#26 btb-2862641-26.patch3.91 KBmartin107
#23 interdiff-2862641-18-23.txt3.74 KBmartin107
#23 btb-2862641-23.patch5.66 KBmartin107
#18 interdiff-14-17.txt2 KBboaloysius
#18 btb-2862641-17.patch4.01 KBboaloysius
#16 interdiff-2862641-14-16.txt3.36 KBmartin107
#16 next-2862641-16.patch5.01 KBmartin107
#14 btb-2862641-14.patch5.71 KBmartin107
#14 interdiff-2862641-8-14.txt1.52 KBmartin107
#8 interdiff-2862641-5-8.txt2.51 KBmartin107
#8 traitAndDeprected-2862641-8.patch5.76 KBmartin107
#5 justMove-2862641-5.patch3.89 KBjofitz
#5 interdiff-2-5.txt1.5 KBjofitz
#2 justMove-2862641-2.patch2.39 KBmartin107
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

martin107 created an issue. See original summary.

martin107’s picture

FileSize
2.39 KB

Initial iteration - Just moving files and taking care of namespaces.

martin107’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: justMove-2862641-2.patch, failed testing.

jofitz’s picture

Status: Needs work » Needs review
FileSize
1.5 KB
3.89 KB

Apparently ToolkitTestBase.php is also referenced in a couple of other files too.

martin107’s picture

Title: Make image tests to extend JavascriptTestBase » Make image tests extend JavascriptTestBase

patch looks good --- what does not is my title :(

Status: Needs review » Needs work

The last submitted patch, 5: justMove-2862641-5.patch, failed testing.

martin107’s picture

Status: Needs work » Needs review
FileSize
5.76 KB
2.51 KB

1) WebTests was the old source of drupalGetTestFiles, now ToolkitTestBase is that common point from which to pick up the method.

2) Converted deprecated SafeMarkup into FormattableMarkup

@Jo Fitzgerald if you want to work on this just unassign me... and I will help out with reviews. and also start on another conversion issue.

Status: Needs review » Needs work

The last submitted patch, 8: traitAndDeprected-2862641-8.patch, failed testing.

martin107’s picture

@Jo Fitzgerald can I pick your brains .....

My first patch timed out, I assume, because the time spend looking for the missing base class exploded and tripped a fail-safe

How did you know to correct the problems .... was it from inspection of the error logs or from knowledge of the sub-module

I ask because when I mirror my actions in #2862885: Batch: Convert system functional tests to phpunit

I trip the fail-safe

jofitz’s picture

To get to the bottom of the initial problems I click to see more details of the test failure (https://www.drupal.org/pift-ci-job/627973), then clicked "View results on dispatcher" (https://dispatcher.drupalci.org/job/drupal_patches/7129/) and "Console Output" (https://dispatcher.drupalci.org/job/drupal_patches/7129/console). Scrolling to the bottom I found the error:

23:14:09 Fatal error: Class 'Drupal\system\Tests\Image\ToolkitTestBase' not found in /var/www/html/core/modules/image/tests/src/Functional/ImageEffectsTest.php on line 13

Hope that helps.

dawehner’s picture

  1. +++ b/core/modules/system/tests/src/Functional/Image/ToolkitTest.php
    @@ -1,6 +1,6 @@
    diff --git a/core/modules/system/src/Tests/Image/ToolkitTestBase.php b/core/modules/system/tests/src/Functional/Image/ToolkitTestBase.php
    
    diff --git a/core/modules/system/src/Tests/Image/ToolkitTestBase.php b/core/modules/system/tests/src/Functional/Image/ToolkitTestBase.php
    similarity index 81%
    
    similarity index 81%
    rename from core/modules/system/src/Tests/Image/ToolkitTestBase.php
    
    rename from core/modules/system/src/Tests/Image/ToolkitTestBase.php
    rename to core/modules/system/tests/src/Functional/Image/ToolkitTestBase.php
    
    rename to core/modules/system/tests/src/Functional/Image/ToolkitTestBase.php
    index 0051e94..2e92858 100644
    
    index 0051e94..2e92858 100644
    --- a/core/modules/system/src/Tests/Image/ToolkitTestBase.php
    
    --- a/core/modules/system/src/Tests/Image/ToolkitTestBase.php
    +++ b/core/modules/system/tests/src/Functional/Image/ToolkitTestBase.php
    

    Note: We need to keep the existing base class around.

  2. +++ b/core/modules/system/tests/src/Functional/Image/ToolkitTestBase.php
    @@ -1,14 +1,19 @@
      */
    -abstract class ToolkitTestBase extends WebTestBase {
    +abstract class ToolkitTestBase extends JavascriptTestBase {
    

    Any reason you extend from JavascriptTestBase and not BrowserTestBase ?

martin107’s picture

May I ask what you are thinking when you say

Note: We need to keep the existing base class around.

Is that so it will present the minimum disruption to contrib modules?

As I understand no new simpletest test will be accepted into core and there is an inevitable slow drift moving thing for example from

Drupal\system\Tests\Image

into the

Drupal\Tests\system\XYZ

namespace.

If contrib is not a factor - am I free so intercept what you say as

"we need to find a place within the Drupal\Tests\system\ namespace so that it can also be used in unit tests?"

martin107’s picture

Title: Make image tests extend JavascriptTestBase » Image: Convert system functional tests to phpunit
Status: Needs work » Needs review
FileSize
1.52 KB
5.71 KB

@Jo Fitzgerald thanks for the prompt reply....

@dawehner

Any reason you extend from JavascriptTestBase and not BrowserTestBase ?

No reason that withstands a closer look ... thank you.

dawehner’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/tests/src/Functional/Image/ToolkitTestBase.php
@@ -99,10 +104,10 @@ public function assertToolkitOperationsCalled(array $expected) {
-      $this->assertTrue(FALSE, SafeMarkup::format('Expected operations %expected to be called but %uncalled was not called.', ['%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)]));
...
-      $this->assertTrue(TRUE, SafeMarkup::format('All the expected operations were called: %expected', ['%expected' => implode(', ', $expected)]));
+      $this->assertTrue(TRUE, new FormattableMarkup('All the expected operations were called: %expected', ['%expected' => implode(', ', $expected)]));

@@ -110,7 +115,7 @@ public function assertToolkitOperationsCalled(array $expected) {
-      $this->assertTrue(FALSE, SafeMarkup::format('Unexpected operations were called: %unexpected.', ['%unexpected' => implode(', ', $unexpected)]));
+      $this->assertTrue(FALSE, new FormattableMarkup('Unexpected operations were called: %unexpected.', ['%unexpected' => implode(', ', $unexpected)]));

Please don't change that as part of the conversion. This makes the patch harder to review for both the committer and the other reviewers.

martin107’s picture

Assigned: martin107 » Unassigned
Status: Needs work » Needs review
FileSize
5.01 KB
3.36 KB

Please don't change that as part of the conversion.

Fair enough..removed

Removed a few deprecated calls of the form

-    $this->assertFieldByName('test[test_parameter]', '10');
+    $assertSession->fieldValueEquals('test[test_parameter]', '10');

Status: Needs review » Needs work

The last submitted patch, 16: next-2862641-16.patch, failed testing.

boaloysius’s picture

made changes as per #15. Haven't touched deprecated calls as in #16.

boaloysius’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 18: btb-2862641-17.patch, failed testing.

dawehner’s picture

+++ b/core/modules/image/tests/src/Functional/ImageEffectsTest.php
@@ -3,7 +3,7 @@
-use Drupal\system\Tests\Image\ToolkitTestBase;
+use Drupal\Tests\system\Functional\Image\ToolkitTestBase;
 

Note: Given that \Drupal\Core\ImageToolkit\ImageToolkitBase is in core, I think the tests should be moved to core/tests/Drupal/FunctionalTests

boaloysius’s picture

martin107’s picture

Status: Needs work » Needs review
FileSize
5.66 KB
3.74 KB

Note: Given that \Drupal\Core\ImageToolkit\ImageToolkitBase is in core, I think the tests should be moved to core/tests/Drupal/FunctionalTests

1) That is a good idea - Moved Image directory.
2) Converted a few deprecated calls to SafeMarkup::format()

I have an issue which I cannot solve ... I would be grateful if someone could get me over the hump

the test module image_test still resides as /modules/system/tests/modules/image_test

now that image is no longer in system we need to find a good home for it.

It tried a few directories within the new directory structure but the autoloader failed to pick it up... advice welcome

Status: Needs review » Needs work

The last submitted patch, 23: btb-2862641-23.patch, failed testing.

dawehner’s picture

+++ b/core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php
@@ -103,10 +104,10 @@ public function assertToolkitOperationsCalled(array $expected) {
     if (count($uncalled)) {
-      $this->assertTrue(FALSE, SafeMarkup::format('Expected operations %expected to be called but %uncalled was not called.', ['%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)]));
+      $this->assertTrue(FALSE, new FormattableMarkup('Expected operations %expected to be called but %uncalled was not called.', ['%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)]));
     }
     else {
-      $this->assertTrue(TRUE, SafeMarkup::format('All the expected operations were called: %expected', ['%expected' => implode(', ', $expected)]));
+      $this->assertTrue(TRUE, new FormattableMarkup('All the expected operations were called: %expected', ['%expected' => implode(', ', $expected)]));

@@ -114,7 +115,7 @@ public function assertToolkitOperationsCalled(array $expected) {
     $unexpected = array_diff($actual, $expected);
     if (count($unexpected) && (!in_array('apply', $expected) || count(array_intersect($unexpected, $operations)) !== count($unexpected))) {
-      $this->assertTrue(FALSE, SafeMarkup::format('Unexpected operations were called: %unexpected.', ['%unexpected' => implode(', ', $unexpected)]));
+      $this->assertTrue(FALSE, new FormattableMarkup('Unexpected operations were called: %unexpected.', ['%unexpected' => implode(', ', $unexpected)]));

These changes are out of scope, aka. they increase the patch size more than needed. Do you mind reverting those changes?

martin107’s picture

Status: Needs work » Needs review
FileSize
3.91 KB
2.23 KB

Sorry, I have the memory of a goldfish

this is not the first time in this issue I replaced the deprecated method calls.... martin107--

The real source of the errors is that in backing out the changes last time I did not restore the "use Smarkmarkup" at the start of the file.

Status: Needs review » Needs work

The last submitted patch, 26: btb-2862641-26.patch, failed testing.

dawehner’s picture

this is not the first time in this issue I replaced the deprecated method calls.... martin107--

Hey, no worries.

martin107’s picture

Status: Needs work » Needs review
FileSize
596 bytes
3.9 KB

Thanks, it is hard to judge emotions in the issue queue -- thanks for the suicide watch but - in reality I am generally a happy bunny :)

This change is a one line change to make the last test pass.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Nice minimal changes, I think this is ready to go.

michielnugter’s picture

Issue tags: +phpunit initiative
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/tests/Drupal/FunctionalTests/Image/ToolkitTest.php
similarity index 94%
rename from core/modules/system/src/Tests/Image/ToolkitTestBase.php

rename from core/modules/system/src/Tests/Image/ToolkitTestBase.php
rename to core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php

We need to leave base classes in place and deprecate them as this might be extended by contrib.

martin107’s picture

Status: Needs work » Needs review
FileSize
8.63 KB
5.05 KB

that is a good push back

martin107’s picture

Sorry testbot this is what I wanted ...

The last submitted patch, 33: trigger_error-2862641-33.patch, failed testing.

dawehner’s picture

  1. +++ b/core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php
    @@ -0,0 +1,159 @@
    +  public function assertToolkitOperationsCalled(array $expected) {
    ...
    +  public function imageTestReset() {
    ...
    +  public function imageTestGetAllCalls() {
    

    Is there a reason these methods are marked as public?

  2. +++ b/core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php
    @@ -0,0 +1,159 @@
    +    if (count($uncalled)) {
    +      $this->assertTrue(FALSE, SafeMarkup::format('Expected operations %expected to be called but %uncalled was not called.', ['%expected' => implode(', ', $expected), '%uncalled' => implode(', ', $uncalled)]));
    +    }
    +    else {
    +      $this->assertTrue(TRUE, SafeMarkup::format('All the expected operations were called: %expected', ['%expected' => implode(', ', $expected)]));
    +    }
    ...
    +    if (count($unexpected) && (!in_array('apply', $expected) || count(array_intersect($unexpected, $operations)) !== count($unexpected))) {
    +      $this->assertTrue(FALSE, SafeMarkup::format('Unexpected operations were called: %unexpected.', ['%unexpected' => implode(', ', $unexpected)]));
    +    }
    +    else {
    +      $this->assertTrue(TRUE, 'No unexpected operations were called.');
    +    }
    

    You want to use assertEmpty() here and just skip the second assertion

martin107’s picture

Assigned: Unassigned » martin107
Status: Needs review » Needs work

There is a DrupalCon on at the moment .... so I am just signalling ... I am working on this now.

martin107’s picture

Assigned: martin107 » Unassigned
Status: Needs work » Needs review
FileSize
8.65 KB
1.12 KB

Given a recent talks about the hazards of implied API's

https://events.drupal.org/baltimore2017/sessions/backwards-compatibility...

public methods on base class are "API" --- That is a really good idea.

If I understood the talk correctly -- at one point there seems to be widespread support of a yet unconfirmed policy of
going through the list of undeclared internal APIs in this document and marking them as such.

https://www.drupal.org/node/2550249

With that in mind "test" is on the list so I am adding a @internal tag to the converted version of ToolkitTestBase.

I try to see both sides of any argument --- Image manipulation is something that contrib might want to do alot
so declaring this new API as subject to change ... might be a problem.

#36.2

You want to use assertEmpty() here and just skip the second assertion

I would like to constructively disagree ....

I see this code as defensively written with good DX in mind.... when things blow up
the pairs of two seemingly duplicated asserts as subtly different and can be read as

When things blow up here is useful debug so you can track your problem.

It pains me to say good DX ... to criticise the programming style of the second example

    if (count($unexpected) && (!in_array('apply', $expected) || count(array_intersect($unexpected, $operations)) !== count($unexpected))) {

this is unreadable code -- it is crying out to be broken into meaningful partial booleans

$expecting_apply = in_array('apply', $expected);
$count_mismatch = count(array_intersect($unexpected, $operations)) !== count($unexpected);

so that the can say the mismatch is only a problem if apply was expected

if ( $countMismatch && !expected_apply )

or something like that....

but this issue is supposed to be a conversion exercise ... If you would like me open a new issue ... that is something I would work on!

Sorry if this is a awful lots of words for such a small patch.

martin107’s picture

Issue summary: View changes

Issue summary changes

We are cutting off legacy support for the implicit public API that is ToolkitTestBase.php
Here is the change record.

dawehner’s picture

Status: Needs review » Needs work

public methods on base class are "API" --- That is a really good idea.

If I understood the talk correctly -- at one point there seems to be widespread support of a yet unconfirmed policy of
going through the list of undeclared internal APIs in this document and marking them as such.

While I totally agree this is an important discussion to have, can we please leave them out of these conversions? Any of those changes requires every other person involved to think about it.

Do you want to open up an issue to discuss best practices for test base classes (like adding @internal when it should be just used for the module itself). There are test base classes, which should be used by other implementors/entity types etc.

Thank you :)

martin107’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
8.64 KB
456 bytes

Do you want to open up an issue to discuss best practices for test base classes (like adding @internal when it should be just used for the module itself). There are test base classes, which should be used by other implementors/entity types etc.

There is already an issue which expresses many of the things I want to say ...

#2873395: [meta] Add @internal to core classes, methods, properties

It is a unconfirmed policy.

Ok, as for the patch I have dropped the @internal tag.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @martin107!

  • catch committed 7cc1987 on 8.4.x
    Issue #2862641 by martin107, boaloysius, Jo Fitzgerald, dawehner,...

  • catch committed ca32d51 on 8.3.x
    Issue #2862641 by martin107, boaloysius, Jo Fitzgerald, dawehner,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.4.x and cherry-picked to 8.3.x, thanks!

Fixed this on commit.

FILE: .../8.x/core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 13 | ERROR | [x] Additional blank lines found at end of doc comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Status: Fixed » Closed (fixed)

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

quietone’s picture

Published the change record.