Support from Acquia helps fund testing for Drupal Acquia logo

Comments

philltran’s picture

Status: Active » Needs review
FileSize
2.88 KB

Here is a patch with a simple test, so the testbot lets us pass.

greggles’s picture

Thanks so much! I'm not super familiar with unit tests, so I'll defer to others to review.

Mile23’s picture

Status: Needs review » Needs work

Looks pretty good, but...

+++ b/tests/src/Unit/FetchManagerTest.php
@@ -0,0 +1,105 @@
+      $stream_wrapper_manager = $this->getMockBuilder('Drupal\Core\StreamWrapper\StreamWrapperManagerInterface')
...
+      $this->logger = $this->getMockBuilder('Psr\Log\LoggerInterface')
...
+      $this->fileSystem = new FileSystem($stream_wrapper_manager, $settings, $this->logger);
+      $this->fetchManager = new FetchManager($this->client, $this->fileSystem, $this->logger);
...
+  if (!function_exists('file_default_scheme')) {

If you find yourself doing a lot of mocking of services, you should probably convert to a KernelTestBase test. That will do a lot of the work for you in terms of setting up services and loading modules (but not enabling them).

philltran’s picture

Thanks Mile23. I will refactor as a kernel test .

philltran’s picture

Status: Needs work » Needs review
FileSize
2.17 KB
4.82 KB

Here is a patch with the test re-written as a kernel test instead of a unit test.

Please review. Thanks!

greggles’s picture

That's indeed a lot simpler. Thanks for posting it.

philltran’s picture

You are welcome!

greggles’s picture

@mile23 can you review again? Does this seem good to you?

neclimdul’s picture

Status: Needs review » Reviewed & tested by the community

I disagree on the service mocking argument because if there are interfaces mock away and you can better assert your excepted behaviors with fewer complications.

That said, the config and file system complications make this better suited for the kernel test. LGTM.

  • greggles committed a6b23fa on 8.x-1.x authored by philltran
    Issue #3085280 by philltran, greggles, neclimdul, Mile23: Add a (at...
greggles’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the reviews, neclimdul and mile23, and for the patch here, philltran.

philltran’s picture

Thanks neclimdul and mile23 for reviewing and for the pointers.

Status: Fixed » Closed (fixed)

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