Skip to content

Instantly share code, notes, and snippets.

@Marko-M
Created June 22, 2022 19:58
Show Gist options
  • Save Marko-M/6133134472d1619fb391539e9c4e26c1 to your computer and use it in GitHub Desktop.
Save Marko-M/6133134472d1619fb391539e9c4e26c1 to your computer and use it in GitHub Desktop.
From 063359089809f7da4a4f6a95b4523135e6c4711f Mon Sep 17 00:00:00 2001
From: Luke Rodgers <lr@amp.co>
Date: Thu, 9 Jun 2022 11:58:46 +0100
Subject: [PATCH 1/4] Fix Test Logger monolog compatability
# System info
- Magento 2.4.4
- PHP 8.1
# To reproduce
1. Get a setup of 2.4.4 installed
2. See that in the constraints allow for an install of `monolog/logger` at `2.7.0`
3. Try to run integration tests (https://devdocs.magento.com/guides/v2.4/test/integration/integration_test_execution.html)
# The error
Currently we get this error because the method signatures are different
```
PHP Fatal error: Declaration of Magento\TestFramework\ErrorLog\Logger::addRecord(int $level, string $message, array $context = []): bool must be compatible with Monolog\Logger::addRecord(int $level, string $message, array $context = [], ?Monolog\DateTimeImmutable $datetime = null): bool in dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php on line 69
```
# Root cause
This version of `monlog/logger` was tagged about an hour ago https://github.com/Seldaek/monolog/releases/tag/2.7.0
See this entry
> Added $datetime parameter to Logger::addRecord as low level API to allow logging into the past or future (https://github.com/Seldaek/monolog/pull/1682)
Which goes along with this commit
https://github.com/Seldaek/monolog/commit/0ddba7342ff919990e1914d24db15e565f153676#diff-1e7fd545cec457de96f5ed6bd7249ba091cd9e699b4057db15ff1e2e0364025bR297
This changes the method signature of `addRecord` like so
```diff
- public function addRecord(int|Level $level, string $message, array $context = []): bool
+ public function addRecord(int|Level $level, string $message, array $context = [], DateTimeImmutable $datetime = null): bool
```
See the magento core logger is defined like this
https://github.com/magento/magento2/blob/a8543fed035d85c667195e95f69476d51f98381b/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php#L69-L73
The method signature needs to be updated to match `monolog/logger` definition
---
.../framework/Magento/TestFramework/ErrorLog/Logger.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php b/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php
index dc7ad3742615..ed2166a04c81 100644
--- a/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php
+++ b/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php
@@ -69,7 +69,8 @@ public function getMessages(): array
public function addRecord(
int $level,
string $message,
- array $context = []
+ array $context = [],
+ DateTimeImmutable $datetime = null
): bool {
if ($level <= $this->minimumErrorLevel) {
$this->messages[] = [
From fa14483f28eec3a0cdd3c5e9c8a07619a6ecf656 Mon Sep 17 00:00:00 2001
From: Luke Rodgers <lr@amp.co>
Date: Thu, 9 Jun 2022 12:19:56 +0100
Subject: [PATCH 2/4] Update Logger.php
---
.../framework/Magento/TestFramework/ErrorLog/Logger.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php b/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php
index ed2166a04c81..64b38ce849b4 100644
--- a/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php
+++ b/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php
@@ -78,6 +78,6 @@ public function addRecord(
'message' => $message,
];
}
- return parent::addRecord($level, $message, $context);
+ return parent::addRecord($level, $message, $context, $datetime);
}
}
From ad78835aa6200d31a7adf3127545f98b9072c0ab Mon Sep 17 00:00:00 2001
From: Luke Rodgers <lr@amp.co>
Date: Thu, 9 Jun 2022 13:37:18 +0100
Subject: [PATCH 3/4] Update Logger.php
---
.../framework/Magento/TestFramework/ErrorLog/Logger.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php b/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php
index 64b38ce849b4..ce17ddd15662 100644
--- a/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php
+++ b/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php
@@ -64,13 +64,14 @@ public function getMessages(): array
* @param int $level The logging level
* @param string $message The log message
* @param array $context The log context
+ * @param \DateTimeImmutable Optional log date to log into the past or future
* @return bool Whether the record has been processed
*/
public function addRecord(
int $level,
string $message,
array $context = [],
- DateTimeImmutable $datetime = null
+ \DateTimeImmutable $datetime = null
): bool {
if ($level <= $this->minimumErrorLevel) {
$this->messages[] = [
From fa23003d146ecef74320cae269cc2918e823c59d Mon Sep 17 00:00:00 2001
From: Luke Rodgers <lukerodgers90@gmail.com>
Date: Sun, 12 Jun 2022 12:39:42 +0100
Subject: [PATCH 4/4] Use correct DateTimeImmutable
---
.../framework/Magento/TestFramework/ErrorLog/Logger.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php b/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php
index ce17ddd15662..90704bc5c68b 100644
--- a/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php
+++ b/dev/tests/integration/framework/Magento/TestFramework/ErrorLog/Logger.php
@@ -9,6 +9,7 @@
use Magento\Framework\Logger\Monolog;
use Monolog\Handler\HandlerInterface;
+use Monolog\DateTimeImmutable;
class Logger extends Monolog
{
@@ -64,14 +65,14 @@ public function getMessages(): array
* @param int $level The logging level
* @param string $message The log message
* @param array $context The log context
- * @param \DateTimeImmutable Optional log date to log into the past or future
+ * @param DateTimeImmutable Optional log date to log into the past or future
* @return bool Whether the record has been processed
*/
public function addRecord(
int $level,
string $message,
array $context = [],
- \DateTimeImmutable $datetime = null
+ DateTimeImmutable $datetime = null
): bool {
if ($level <= $this->minimumErrorLevel) {
$this->messages[] = [
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment