- Issue created by @zniki.ru
- π·πΊRussia zniki.ru
These tests:
- Drupal\Tests\comment\Kernel\CommentIntegrationTest
- Drupal\Tests\field_ui\Kernel\EntityDisplayTest
- Drupal\Tests\image\Kernel\ImageItemTest
- Drupal\Tests\jsonapi\Kernel\ResourceType\RelatedResourceTypesTest
- Drupal\KernelTests\Core\Action\EmailActionTest
have same goal. Find single message and check variables. Maybe we can create trait for this, to be able to register logger and check message.
Example:
$logged = Database::getConnection()->select('watchdog') ->fields('watchdog', ['variables']) ->condition('type', 'jsonapi') ->condition('message', 'The "@name" at "@target_entity_type_id:@target_bundle" references the "@entity_type_id:@bundle" entity type that does not exist.') ->execute() ->fetchField(); $this->assertEquals(serialize($arguments), $logged);
- Merge request !10791Draft: Resolve #3496184: Expirement logger test trait β (Closed) created by zniki.ru
- π·πΊRussia zniki.ru
I create trait that register \Symfony\Component\ErrorHandler\BufferingLogger as logger service.
And have new assert method.
I found that using BufferingLogger have some cons:While working CommentIntegrationTest.php, there was one error log that was not checked by tests, that caused error fail on test finish. Because of BufferingLogger::__desctruct() showing all errors on test finish.
Also BufferingLogger::__desctruct() method doesn't support drupal token replacement.
I believe this is not behavior I want.
If tests doesn't care about log, we also need to ignore that.Also I don't like implementing register() method at trait. Maybe we can directly inject logger to KernelTest.
- π·πΊRussia zniki.ru
I decide that it would be great to have TestLogger to use at tests as dblog alternative.
And found that we already using \ColinODell\PsrTestLogger\TestLogger at some tests.
Another great example is \Drupal\Tests\feeds\Kernel\TestLogger and Drupal\Tests\feeds\Kernel\FeedsKernelTestBase. - Merge request !10808#3496184: TestLogger as dblog alternative at tests β (Closed) created by zniki.ru
- Merge request !10810Draft: Issue #3496184: use ColinODell\PsrTestLogger\TestLogger alternative to dblog β (Closed) created by zniki.ru
- πΊπΈUnited States nicxvan
That would be interesting! Just in case you didn't know, adding a dependency to core has a lot of gates: https://github.com/colinodell/psr-testlogger
https://www.drupal.org/about/core/policies/core-dependency-policies/depe... β
Might be worth asking in the core development channel for advice before going too far down this path.
- π·πΊRussia zniki.ru
@nicxvan thanks for feedback.
But as I can see colinodell/psr-testlogger is already a part of Core dependency.I will ask for advice anyway, thanks. Just want to make some research before, to have better understanding of the topic.
- πΊπΈUnited States nicxvan
Oh sorry, I thought were researching a new dependency, I misunderstood!
- π·πΊRussia zniki.ru
I create helper class TestLogger. Attaching it directly in the test method looks very easy, and hasn't a lot of boilerplate.
I was thinking to use colinodell/psr-testlogger, but there are a lot of data in the log->context. In order to filter it, we can use proxy and facade approach, but I want to keep it simple. Creating custom class looks like good alternative.
Also I added rendered message to log, and TestLogger can search rendered message, this is not used in MR, but this should be useful for someone who is searching simple rendered message.Set to NR to get some feedback.
- π·πΊRussia zniki.ru
I created a Proxy for \ColinODell\PsrTestLogger\TestLogger to filter context of log records.
And result looks good. All \ColinODell\PsrTestLogger\TestLogger methods can be used.
Probably this is better than creating custom TestLogger from scratch. - Merge request !10863Resolve #3496184: Replace dblog at tests with Logger β (Closed) created by zniki.ru
- π·πΊRussia zniki.ru
nikolay shapovalov β changed the visibility of the branch 3496184-logger-test-class to hidden.
- π·πΊRussia zniki.ru
nikolay shapovalov β changed the visibility of the branch 3496184-convert-smart-default-settings to hidden.
- π·πΊRussia zniki.ru
This is gonna be solved at π Replace usage of dblog module at tests with alternative Active