Skip to content

Commit 4894788

Browse files
committed
docs: Add to user guide and changelog
1 parent 2302dbc commit 4894788

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

user_guide_src/source/changelogs/v4.3.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ Testing
128128
- The CITestStreamFilter filter class now implements methods for adding a filter to streams. See :ref:`testing-cli-output`.
129129
- Added the ``PhpStreamWrapper`` to make it easier to work with setting data to ``php://stdin``. See :ref:`testing-cli-input`.
130130
- Added method :ref:`benchmark-timer-record` to measure performance in a callable. Also enhanced common function ``timer()`` to accept optional callable.
131+
- A boolean third parameter ``$useExactComparison`` is added to ``TestLogger::didLog()`` which sets whether log messages are checked verbatim. This defaults to ``true``.
132+
- Added method ``CIUnitTestCase::assertLogContains()`` which compares log messages by parts instead of the whole of the message.
131133

132134
Database
133135
========

user_guide_src/source/testing/overview.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ Additional Assertions
126126
assertLogged($level, $expectedMessage)
127127
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
128128

129-
Ensure that something you expected to be logged actually was:
129+
Ensure that something you expected to be logged was actually logged:
130+
131+
assertLogContains($level, $logMessage)
132+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
133+
134+
Ensure that there's a record in the logs which contains a message part.
130135

131136
.. literalinclude:: overview/007.php
132137

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

3-
$config = new LoggerConfig();
4-
$logger = new Logger($config);
3+
$config = new Config\Logger();
4+
$logger = new CodeIgniter\Log\Logger($config);
55

6-
// ... do something that you expect a log entry from
6+
// check verbatim the log message
77
$logger->log('error', "That's no moon");
8-
98
$this->assertLogged('error', "That's no moon");
9+
10+
// check that a portion of the message is found in the logs
11+
$exception = new RuntimeException('Hello world.');
12+
$logger->log('error', $exception->getTraceAsString());
13+
$this->assertLogContains('error', '{main}');

0 commit comments

Comments
 (0)