Skip to content

Commit 7ca003e

Browse files
authored
Rename TestCase to MonologTestCase (#1953)
1 parent 9d6bcfc commit 7ca003e

File tree

90 files changed

+197
-262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+197
-262
lines changed

src/Monolog/Test/MonologTestCase.php

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the Monolog package.
5+
*
6+
* (c) Jordi Boggiano <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Monolog\Test;
13+
14+
use Monolog\Level;
15+
use Monolog\Logger;
16+
use Monolog\LogRecord;
17+
use Monolog\JsonSerializableDateTimeImmutable;
18+
use Monolog\Formatter\FormatterInterface;
19+
use Psr\Log\LogLevel;
20+
21+
/**
22+
* Lets you easily generate log records and a dummy formatter for testing purposes
23+
*
24+
* @author Jordi Boggiano <[email protected]>
25+
*/
26+
class MonologTestCase extends \PHPUnit\Framework\TestCase
27+
{
28+
/**
29+
* @param array<mixed> $context
30+
* @param array<mixed> $extra
31+
*
32+
* @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::* $level
33+
*/
34+
protected function getRecord(int|string|Level $level = Level::Warning, string|\Stringable $message = 'test', array $context = [], string $channel = 'test', \DateTimeImmutable $datetime = new JsonSerializableDateTimeImmutable(true), array $extra = []): LogRecord
35+
{
36+
return new LogRecord(
37+
message: (string) $message,
38+
context: $context,
39+
level: Logger::toMonologLevel($level),
40+
channel: $channel,
41+
datetime: $datetime,
42+
extra: $extra,
43+
);
44+
}
45+
46+
/**
47+
* @phpstan-return list<LogRecord>
48+
*/
49+
protected function getMultipleRecords(): array
50+
{
51+
return [
52+
$this->getRecord(Level::Debug, 'debug message 1'),
53+
$this->getRecord(Level::Debug, 'debug message 2'),
54+
$this->getRecord(Level::Info, 'information'),
55+
$this->getRecord(Level::Warning, 'warning'),
56+
$this->getRecord(Level::Error, 'error'),
57+
];
58+
}
59+
60+
protected function getIdentityFormatter(): FormatterInterface
61+
{
62+
$formatter = $this->createMock(FormatterInterface::class);
63+
$formatter->expects(self::any())
64+
->method('format')
65+
->willReturnCallback(function ($record) {
66+
return $record->message;
67+
});
68+
69+
return $formatter;
70+
}
71+
}

src/Monolog/Test/TestCase.php

+2-53
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,13 @@
1111

1212
namespace Monolog\Test;
1313

14-
use Monolog\Level;
15-
use Monolog\Logger;
16-
use Monolog\LogRecord;
17-
use Monolog\JsonSerializableDateTimeImmutable;
18-
use Monolog\Formatter\FormatterInterface;
19-
use Psr\Log\LogLevel;
20-
use ReflectionProperty;
21-
2214
/**
2315
* Lets you easily generate log records and a dummy formatter for testing purposes
2416
*
2517
* @author Jordi Boggiano <[email protected]>
2618
*
27-
* @internal feel free to reuse this to test your own handlers, this is marked internal to avoid issues with PHPStorm https://github.com/Seldaek/monolog/issues/1677
19+
* @deprecated use MonologTestCase instead.
2820
*/
29-
class TestCase extends \PHPUnit\Framework\TestCase
21+
class TestCase extends MonologTestCase
3022
{
31-
/**
32-
* @param array<mixed> $context
33-
* @param array<mixed> $extra
34-
*
35-
* @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::* $level
36-
*/
37-
protected function getRecord(int|string|Level $level = Level::Warning, string|\Stringable $message = 'test', array $context = [], string $channel = 'test', \DateTimeImmutable $datetime = new JsonSerializableDateTimeImmutable(true), array $extra = []): LogRecord
38-
{
39-
return new LogRecord(
40-
message: (string) $message,
41-
context: $context,
42-
level: Logger::toMonologLevel($level),
43-
channel: $channel,
44-
datetime: $datetime,
45-
extra: $extra,
46-
);
47-
}
48-
49-
/**
50-
* @phpstan-return list<LogRecord>
51-
*/
52-
protected function getMultipleRecords(): array
53-
{
54-
return [
55-
$this->getRecord(Level::Debug, 'debug message 1'),
56-
$this->getRecord(Level::Debug, 'debug message 2'),
57-
$this->getRecord(Level::Info, 'information'),
58-
$this->getRecord(Level::Warning, 'warning'),
59-
$this->getRecord(Level::Error, 'error'),
60-
];
61-
}
62-
63-
protected function getIdentityFormatter(): FormatterInterface
64-
{
65-
$formatter = $this->createMock(FormatterInterface::class);
66-
$formatter->expects(self::any())
67-
->method('format')
68-
->willReturnCallback(function ($record) {
69-
return $record->message;
70-
});
71-
72-
return $formatter;
73-
}
7423
}

tests/Monolog/Attribute/AsMonologProcessorTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111

1212
namespace Monolog\Attribute;
1313

14-
use PHPUnit\Framework\TestCase;
15-
1614
/**
1715
* @requires PHP 8.0
1816
*/
19-
final class AsMonologProcessorTest extends TestCase
17+
final class AsMonologProcessorTest extends \Monolog\Test\MonologTestCase
2018
{
2119
public function test(): void
2220
{

tests/Monolog/Attribute/WithMonologChannelTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
namespace Monolog\Attribute;
1313

14-
use PHPUnit\Framework\TestCase;
15-
16-
class WithMonologChannelTest extends TestCase
14+
class WithMonologChannelTest extends \Monolog\Test\MonologTestCase
1715
{
1816
public function test(): void
1917
{

tests/Monolog/Formatter/ChromePHPFormatterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Monolog\Formatter;
1313

1414
use Monolog\Level;
15-
use Monolog\Test\TestCase;
15+
use Monolog\Test\MonologTestCase;
1616

17-
class ChromePHPFormatterTest extends TestCase
17+
class ChromePHPFormatterTest extends MonologTestCase
1818
{
1919
/**
2020
* @covers Monolog\Formatter\ChromePHPFormatter::format

tests/Monolog/Formatter/ElasticaFormatterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Monolog\Formatter;
1313

1414
use Monolog\Level;
15-
use Monolog\Test\TestCase;
15+
use Monolog\Test\MonologTestCase;
1616

17-
class ElasticaFormatterTest extends TestCase
17+
class ElasticaFormatterTest extends MonologTestCase
1818
{
1919
public function setUp(): void
2020
{

tests/Monolog/Formatter/ElasticsearchFormatterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Monolog\Formatter;
1313

1414
use Monolog\Level;
15-
use Monolog\Test\TestCase;
15+
use Monolog\Test\MonologTestCase;
1616

17-
class ElasticsearchFormatterTest extends TestCase
17+
class ElasticsearchFormatterTest extends MonologTestCase
1818
{
1919
/**
2020
* @covers Monolog\Formatter\ElasticsearchFormatter::__construct

tests/Monolog/Formatter/FlowdockFormatterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Monolog\Formatter;
1313

1414
use Monolog\Level;
15-
use Monolog\Test\TestCase;
15+
use Monolog\Test\MonologTestCase;
1616

17-
class FlowdockFormatterTest extends TestCase
17+
class FlowdockFormatterTest extends MonologTestCase
1818
{
1919
/**
2020
* @covers Monolog\Formatter\FlowdockFormatter::format

tests/Monolog/Formatter/FluentdFormatterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Monolog\Formatter;
1313

1414
use Monolog\Level;
15-
use Monolog\Test\TestCase;
15+
use Monolog\Test\MonologTestCase;
1616

17-
class FluentdFormatterTest extends TestCase
17+
class FluentdFormatterTest extends MonologTestCase
1818
{
1919
/**
2020
* @covers Monolog\Formatter\FluentdFormatter::__construct

tests/Monolog/Formatter/GelfMessageFormatterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Monolog\Formatter;
1313

1414
use Monolog\Level;
15-
use Monolog\Test\TestCase;
15+
use Monolog\Test\MonologTestCase;
1616

17-
class GelfMessageFormatterTest extends TestCase
17+
class GelfMessageFormatterTest extends MonologTestCase
1818
{
1919
public function setUp(): void
2020
{

tests/Monolog/Formatter/GoogleCloudLoggingFormatterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
namespace Monolog\Formatter;
1313

1414
use DateTimeInterface;
15-
use Monolog\Test\TestCase;
15+
use Monolog\Test\MonologTestCase;
1616
use function json_decode;
1717

18-
class GoogleCloudLoggingFormatterTest extends TestCase
18+
class GoogleCloudLoggingFormatterTest extends MonologTestCase
1919
{
2020
/**
2121
* @test

tests/Monolog/Formatter/JsonFormatterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
use Monolog\Level;
1515
use Monolog\LogRecord;
1616
use JsonSerializable;
17-
use Monolog\Test\TestCase;
17+
use Monolog\Test\MonologTestCase;
1818

19-
class JsonFormatterTest extends TestCase
19+
class JsonFormatterTest extends MonologTestCase
2020
{
2121
/**
2222
* @covers Monolog\Formatter\JsonFormatter::__construct

tests/Monolog/Formatter/LineFormatterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
namespace Monolog\Formatter;
1313

14-
use Monolog\Test\TestCase;
14+
use Monolog\Test\MonologTestCase;
1515
use Monolog\Level;
1616
use PHPUnit\Framework\Attributes\DataProvider;
1717
use RuntimeException;
1818

1919
/**
2020
* @covers Monolog\Formatter\LineFormatter
2121
*/
22-
class LineFormatterTest extends TestCase
22+
class LineFormatterTest extends MonologTestCase
2323
{
2424
public function testDefFormatWithString()
2525
{

tests/Monolog/Formatter/LogglyFormatterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
namespace Monolog\Formatter;
1313

14-
use Monolog\Test\TestCase;
14+
use Monolog\Test\MonologTestCase;
1515

16-
class LogglyFormatterTest extends TestCase
16+
class LogglyFormatterTest extends MonologTestCase
1717
{
1818
/**
1919
* @covers Monolog\Formatter\LogglyFormatter::__construct

tests/Monolog/Formatter/LogmaticFormatterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
namespace Monolog\Formatter;
1313

14-
use Monolog\Test\TestCase;
14+
use Monolog\Test\MonologTestCase;
1515

1616
/**
1717
* @author Julien Breux <[email protected]>
1818
*/
19-
class LogmaticFormatterTest extends TestCase
19+
class LogmaticFormatterTest extends MonologTestCase
2020
{
2121
/**
2222
* @covers Monolog\Formatter\LogmaticFormatter::format

tests/Monolog/Formatter/LogstashFormatterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Monolog\Formatter;
1313

1414
use Monolog\Level;
15-
use Monolog\Test\TestCase;
15+
use Monolog\Test\MonologTestCase;
1616

17-
class LogstashFormatterTest extends TestCase
17+
class LogstashFormatterTest extends MonologTestCase
1818
{
1919
/**
2020
* @covers Monolog\Formatter\LogstashFormatter::format

tests/Monolog/Formatter/MongoDBFormatterTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
use MongoDB\BSON\Regex;
1616
use MongoDB\BSON\UTCDateTime;
1717
use Monolog\Level;
18-
use Monolog\Test\TestCase;
1918
use PHPUnit\Framework\Attributes\DataProvider;
2019

2120
/**
2221
* @author Florian Plattner <[email protected]>
2322
*/
24-
class MongoDBFormatterTest extends TestCase
23+
class MongoDBFormatterTest extends \Monolog\Test\MonologTestCase
2524
{
2625
public function setUp(): void
2726
{

tests/Monolog/Formatter/NormalizerFormatterTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111

1212
namespace Monolog\Formatter;
1313

14-
use Monolog\Test\TestCase;
1514
use Monolog\Level;
1615

1716
/**
1817
* @covers Monolog\Formatter\NormalizerFormatter
1918
*/
20-
class NormalizerFormatterTest extends TestCase
19+
class NormalizerFormatterTest extends \Monolog\Test\MonologTestCase
2120
{
2221
public function testFormat()
2322
{

tests/Monolog/Formatter/ScalarFormatterTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
namespace Monolog\Formatter;
1313

1414
use Monolog\JsonSerializableDateTimeImmutable;
15-
use Monolog\Test\TestCase;
1615

17-
class ScalarFormatterTest extends TestCase
16+
class ScalarFormatterTest extends \Monolog\Test\MonologTestCase
1817
{
1918
private ScalarFormatter $formatter;
2019

tests/Monolog/Formatter/SyslogFormatterTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
use Monolog\Level;
1616
use Monolog\LogRecord;
1717
use PHPUnit\Framework\Attributes\DataProvider;
18-
use PHPUnit\Framework\TestCase;
1918

20-
class SyslogFormatterTest extends TestCase
19+
class SyslogFormatterTest extends \Monolog\Test\MonologTestCase
2120
{
2221
/**
2322
* @param mixed[] $context

tests/Monolog/Formatter/WildfireFormatterTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
namespace Monolog\Formatter;
1313

1414
use Monolog\Level;
15-
use Monolog\Test\TestCase;
1615

17-
class WildfireFormatterTest extends TestCase
16+
class WildfireFormatterTest extends \Monolog\Test\MonologTestCase
1817
{
1918
/**
2019
* @covers Monolog\Formatter\WildfireFormatter::format

tests/Monolog/Handler/AbstractHandlerTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
namespace Monolog\Handler;
1313

1414
use Monolog\Level;
15-
use Monolog\Test\TestCase;
1615

17-
class AbstractHandlerTest extends TestCase
16+
class AbstractHandlerTest extends \Monolog\Test\MonologTestCase
1817
{
1918
/**
2019
* @covers Monolog\Handler\AbstractHandler::__construct

0 commit comments

Comments
 (0)