It seems error logging is unable to work:
https://git.drupalcode.org/project/mailchimp_ecommerce/blob/8.x-1.x/mailchimp_ecommerce.module#L94

/**
 * Logs an error message using watchdog, if enabled.
 *
 * @todo This function cannot run, the function "watchdog" is never defined.
 *
 * @param string $message
 *   The error message to log.
 */
function mailchimp_ecommerce_log_error_message($message) {
  if (function_exists('watchdog')) {
    \Drupal::logger('mailchimp_ecommerce')->error('%message', array(
      '%message' => $message,
    ));
  }
}

Notice the @todo. I am not entirely sure why we would want to have this function at all rather than just injecting the logger service where needed. I think that would offer more flexibility, as this is only logging errors, and there could be other places we would want logging. For instance, there are a lot of drupal_set_message where a log entry might be more appropriate.

How do we want to proceed here?

  1. Fix this function ( remove the check for 'watchdog' )
  2. Remove this function and inject the logger service

Comments

scottsawyer created an issue. See original summary.

scottsawyer’s picture

Status: Active » Needs review
StatusFileSize
new18.52 KB

I went the dependency injection route. I also uncommented a couple of places there was logging. Please test.

scottsawyer’s picture

StatusFileSize
new19.92 KB

Forgot to update the test.

acbramley’s picture

Status: Needs review » Needs work
+++ b/tests/src/Unit/CartHandlerTest.php
@@ -65,7 +73,8 @@ class CartHandlerTest extends UnitTestCase {
+    $this->logger = $this->createMock(LoggerChannelFactoryInterface::class);
+    $this->handler = new CartHandler($this->mcEcommerce, $this->helper, $this->messenger, $this->logger);

The failure is due to the fact that your mock logger needs the get function mocked.

Similar to how the messenger has the addError method mocked, you'll need to mock get on the logger to return a mock LoggerChannelInterface

scottsawyer’s picture

Status: Needs work » Needs review
StatusFileSize
new20.09 KB

Updated test

samuel.mortenson’s picture

Status: Needs review » Needs work

Setting to NW for test failures.

  • xenophyle committed 2062514f on 2.x
    Issue #3099554 by scottsawyer, acbramley, xenophyle: Error logging seems...
xenophyle’s picture

Version: 8.x-1.x-dev » 2.x-dev
Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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