1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-06 13:16:39 +02:00

Fix phpunit deprecations

This commit is contained in:
Jordi Boggiano
2024-04-12 17:26:33 +02:00
parent 5b990255a3
commit b127292ee0
39 changed files with 220 additions and 302 deletions

View File

@@ -29,7 +29,7 @@
"phpstan/phpstan": "^1.9", "phpstan/phpstan": "^1.9",
"phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-strict-rules": "^1.4", "phpstan/phpstan-strict-rules": "^1.4",
"phpunit/phpunit": "^10.1", "phpunit/phpunit": "^10.5.17",
"predis/predis": "^1.1 || ^2", "predis/predis": "^1.1 || ^2",
"ruflin/elastica": "^7", "ruflin/elastica": "^7",
"symfony/mailer": "^5.4 || ^6", "symfony/mailer": "^5.4 || ^6",

View File

@@ -12,6 +12,8 @@
namespace Monolog; namespace Monolog;
use Monolog\Handler\TestHandler; use Monolog\Handler\TestHandler;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
use Psr\Log\LogLevel; use Psr\Log\LogLevel;
class ErrorHandlerTest extends \PHPUnit\Framework\TestCase class ErrorHandlerTest extends \PHPUnit\Framework\TestCase
@@ -23,6 +25,7 @@ class ErrorHandlerTest extends \PHPUnit\Framework\TestCase
$this->assertInstanceOf(ErrorHandler::class, ErrorHandler::register($logger, false, false, false)); $this->assertInstanceOf(ErrorHandler::class, ErrorHandler::register($logger, false, false, false));
} }
#[WithoutErrorHandler]
public function testHandleError() public function testHandleError()
{ {
$logger = new Logger('test', [$handler = new TestHandler]); $logger = new Logger('test', [$handler = new TestHandler]);
@@ -44,7 +47,9 @@ class ErrorHandlerTest extends \PHPUnit\Framework\TestCase
$this->assertTrue($handler->hasErrorRecords()); $this->assertTrue($handler->hasErrorRecords());
trigger_error('Foo', E_USER_NOTICE); trigger_error('Foo', E_USER_NOTICE);
$this->assertCount(2, $handler->getRecords()); $this->assertCount(2, $handler->getRecords());
// check that the remapping of notice to emergency above worked
$this->assertTrue($handler->hasEmergencyRecords()); $this->assertTrue($handler->hasEmergencyRecords());
$this->assertFalse($handler->hasNoticeRecords());
} finally { } finally {
// restore previous handler // restore previous handler
set_error_handler($phpunitHandler); set_error_handler($phpunitHandler);
@@ -68,9 +73,8 @@ class ErrorHandlerTest extends \PHPUnit\Framework\TestCase
return $prop->getValue($instance); return $prop->getValue($instance);
} }
/** #[DataProvider('fatalHandlerProvider')]
* @dataProvider fatalHandlerProvider #[WithoutErrorHandler]
*/
public function testFatalHandler( public function testFatalHandler(
$level, $level,
$reservedMemorySize, $reservedMemorySize,

View File

@@ -13,6 +13,7 @@ namespace Monolog\Formatter;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use Monolog\Level; use Monolog\Level;
use PHPUnit\Framework\Attributes\DataProvider;
use RuntimeException; use RuntimeException;
/** /**
@@ -291,9 +292,7 @@ class LineFormatterTest extends TestCase
$this->assertStringContainsString(' #1', $message); $this->assertStringContainsString(' #1', $message);
} }
/** #[DataProvider('providerMaxLevelNameLength')]
* @dataProvider providerMaxLevelNameLength
*/
public function testMaxLevelNameLength(?int $maxLength, Level $logLevel, string $expectedLevelName): void public function testMaxLevelNameLength(?int $maxLength, Level $logLevel, string $expectedLevelName): void
{ {
$formatter = new LineFormatter(); $formatter = new LineFormatter();
@@ -307,21 +306,21 @@ class LineFormatterTest extends TestCase
{ {
return [ return [
'info_no_max_length' => [ 'info_no_max_length' => [
'max_length' => null, 'maxLength' => null,
'level' => Level::Info, 'logLevel' => Level::Info,
'expected_level_name' => 'INFO', 'expectedLevelName' => 'INFO',
], ],
'error_max_length_3' => [ 'error_max_length_3' => [
'max_length' => 3, 'maxLength' => 3,
'level' => Level::Error, 'logLevel' => Level::Error,
'expected_level_name' => 'ERR', 'expectedLevelName' => 'ERR',
], ],
'debug_max_length_2' => [ 'debug_max_length_2' => [
'max_length' => 2, 'maxLength' => 2,
'level' => Level::Debug, 'logLevel' => Level::Debug,
'expected_level_name' => 'DE', 'expectedLevelName' => 'DE',
], ],
]; ];
} }

View File

@@ -16,6 +16,7 @@ use MongoDB\BSON\Regex;
use MongoDB\BSON\UTCDateTime; use MongoDB\BSON\UTCDateTime;
use Monolog\Level; use Monolog\Level;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
/** /**
* @author Florian Plattner <me@florianplattner.de> * @author Florian Plattner <me@florianplattner.de>
@@ -37,14 +38,7 @@ class MongoDBFormatterTest extends TestCase
]; ];
} }
/** #[DataProvider('constructArgumentProvider')]
* @param $traceDepth
* @param $traceAsString
* @param $expectedTraceDepth
* @param $expectedTraceAsString
*
* @dataProvider constructArgumentProvider
*/
public function testConstruct($traceDepth, $traceAsString, $expectedTraceDepth, $expectedTraceAsString) public function testConstruct($traceDepth, $traceAsString, $expectedTraceDepth, $expectedTraceAsString)
{ {
$formatter = new MongoDBFormatter($traceDepth, $traceAsString); $formatter = new MongoDBFormatter($traceDepth, $traceAsString);

View File

@@ -14,23 +14,16 @@ namespace Monolog\Formatter;
use DateTimeImmutable; use DateTimeImmutable;
use Monolog\Level; use Monolog\Level;
use Monolog\LogRecord; use Monolog\LogRecord;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class SyslogFormatterTest extends TestCase class SyslogFormatterTest extends TestCase
{ {
/** /**
* @dataProvider formatDataProvider
*
* @param string $expected
* @param DateTimeImmutable $dateTime
* @param string $channel
* @param Level $level
* @param string $message
* @param string|null $appName
* @param mixed[] $context * @param mixed[] $context
* @param mixed[] $extra * @param mixed[] $extra
* @return void
*/ */
#[DataProvider('formatDataProvider')]
public function testFormat( public function testFormat(
string $expected, string $expected,
DateTimeImmutable $dateTime, DateTimeImmutable $dateTime,

View File

@@ -25,7 +25,7 @@ class AbstractHandlerTest extends TestCase
*/ */
public function testConstructAndGetSet() public function testConstructAndGetSet()
{ {
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', [Level::Warning, false]); $handler = $this->getMockBuilder('Monolog\Handler\AbstractHandler')->setConstructorArgs([Level::Warning, false])->onlyMethods(['handle'])->getMock();
$this->assertEquals(Level::Warning, $handler->getLevel()); $this->assertEquals(Level::Warning, $handler->getLevel());
$this->assertEquals(false, $handler->getBubble()); $this->assertEquals(false, $handler->getBubble());
@@ -40,7 +40,7 @@ class AbstractHandlerTest extends TestCase
*/ */
public function testHandleBatch() public function testHandleBatch()
{ {
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler'); $handler = $this->createPartialMock('Monolog\Handler\AbstractHandler', ['handle']);
$handler->expects($this->exactly(2)) $handler->expects($this->exactly(2))
->method('handle'); ->method('handle');
$handler->handleBatch([$this->getRecord(), $this->getRecord()]); $handler->handleBatch([$this->getRecord(), $this->getRecord()]);
@@ -51,7 +51,7 @@ class AbstractHandlerTest extends TestCase
*/ */
public function testIsHandling() public function testIsHandling()
{ {
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', [Level::Warning, false]); $handler = $this->getMockBuilder('Monolog\Handler\AbstractHandler')->setConstructorArgs([Level::Warning, false])->onlyMethods(['handle'])->getMock();
$this->assertTrue($handler->isHandling($this->getRecord())); $this->assertTrue($handler->isHandling($this->getRecord()));
$this->assertFalse($handler->isHandling($this->getRecord(Level::Debug))); $this->assertFalse($handler->isHandling($this->getRecord(Level::Debug)));
} }
@@ -61,7 +61,7 @@ class AbstractHandlerTest extends TestCase
*/ */
public function testHandlesPsrStyleLevels() public function testHandlesPsrStyleLevels()
{ {
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', ['warning', false]); $handler = $this->getMockBuilder('Monolog\Handler\AbstractHandler')->setConstructorArgs(['warning', false])->onlyMethods(['handle'])->getMock();
$this->assertFalse($handler->isHandling($this->getRecord(Level::Debug))); $this->assertFalse($handler->isHandling($this->getRecord(Level::Debug)));
$handler->setLevel('debug'); $handler->setLevel('debug');
$this->assertTrue($handler->isHandling($this->getRecord(Level::Debug))); $this->assertTrue($handler->isHandling($this->getRecord(Level::Debug)));

View File

@@ -24,7 +24,7 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testConstructAndGetSet() public function testConstructAndGetSet()
{ {
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', [Level::Warning, false]); $handler = $this->getMockBuilder('Monolog\Handler\AbstractProcessingHandler')->setConstructorArgs([Level::Warning, false])->onlyMethods(['write'])->getMock();
$handler->setFormatter($formatter = new LineFormatter); $handler->setFormatter($formatter = new LineFormatter);
$this->assertSame($formatter, $handler->getFormatter()); $this->assertSame($formatter, $handler->getFormatter());
} }
@@ -34,7 +34,7 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testHandleLowerLevelMessage() public function testHandleLowerLevelMessage()
{ {
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', [Level::Warning, true]); $handler = $this->getMockBuilder('Monolog\Handler\AbstractProcessingHandler')->setConstructorArgs([Level::Warning, true])->onlyMethods(['write'])->getMock();
$this->assertFalse($handler->handle($this->getRecord(Level::Debug))); $this->assertFalse($handler->handle($this->getRecord(Level::Debug)));
} }
@@ -43,7 +43,7 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testHandleBubbling() public function testHandleBubbling()
{ {
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', [Level::Debug, true]); $handler = $this->getMockBuilder('Monolog\Handler\AbstractProcessingHandler')->setConstructorArgs([Level::Debug, true])->onlyMethods(['write'])->getMock();
$this->assertFalse($handler->handle($this->getRecord())); $this->assertFalse($handler->handle($this->getRecord()));
} }
@@ -52,7 +52,7 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testHandleNotBubbling() public function testHandleNotBubbling()
{ {
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', [Level::Debug, false]); $handler = $this->getMockBuilder('Monolog\Handler\AbstractProcessingHandler')->setConstructorArgs([Level::Debug, false])->onlyMethods(['write'])->getMock();
$this->assertTrue($handler->handle($this->getRecord())); $this->assertTrue($handler->handle($this->getRecord()));
} }
@@ -61,7 +61,7 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testHandleIsFalseWhenNotHandled() public function testHandleIsFalseWhenNotHandled()
{ {
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', [Level::Warning, false]); $handler = $this->getMockBuilder('Monolog\Handler\AbstractProcessingHandler')->setConstructorArgs([Level::Warning, false])->onlyMethods(['write'])->getMock();
$this->assertTrue($handler->handle($this->getRecord())); $this->assertTrue($handler->handle($this->getRecord()));
$this->assertFalse($handler->handle($this->getRecord(Level::Debug))); $this->assertFalse($handler->handle($this->getRecord(Level::Debug)));
} }
@@ -71,7 +71,7 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testProcessRecord() public function testProcessRecord()
{ {
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler'); $handler = $this->createPartialMock('Monolog\Handler\AbstractProcessingHandler', ['write']);
$handler->pushProcessor(new WebProcessor([ $handler->pushProcessor(new WebProcessor([
'REQUEST_URI' => '', 'REQUEST_URI' => '',
'REQUEST_METHOD' => '', 'REQUEST_METHOD' => '',
@@ -82,9 +82,9 @@ class AbstractProcessingHandlerTest extends TestCase
$handledRecord = null; $handledRecord = null;
$handler->expects($this->once()) $handler->expects($this->once())
->method('write') ->method('write')
->will($this->returnCallback(function ($record) use (&$handledRecord) { ->willReturnCallback(function ($record) use (&$handledRecord) {
$handledRecord = $record; $handledRecord = $record;
})) })
; ;
$handler->handle($this->getRecord()); $handler->handle($this->getRecord());
$this->assertEquals(6, count($handledRecord['extra'])); $this->assertEquals(6, count($handledRecord['extra']));
@@ -96,7 +96,7 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testPushPopProcessor() public function testPushPopProcessor()
{ {
$logger = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler'); $logger = $this->createPartialMock('Monolog\Handler\AbstractProcessingHandler', ['write']);
$processor1 = new WebProcessor; $processor1 = new WebProcessor;
$processor2 = new WebProcessor; $processor2 = new WebProcessor;
@@ -116,7 +116,7 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testPushProcessorWithNonCallable() public function testPushProcessorWithNonCallable()
{ {
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler'); $handler = $this->createPartialMock('Monolog\Handler\AbstractProcessingHandler', ['write']);
$this->expectException(\TypeError::class); $this->expectException(\TypeError::class);
@@ -129,7 +129,7 @@ class AbstractProcessingHandlerTest extends TestCase
*/ */
public function testGetFormatterInitializesDefault() public function testGetFormatterInitializesDefault()
{ {
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler'); $handler = $this->createPartialMock('Monolog\Handler\AbstractProcessingHandler', ['write']);
$this->assertInstanceOf(LineFormatter::class, $handler->getFormatter()); $this->assertInstanceOf(LineFormatter::class, $handler->getFormatter());
} }
} }

View File

@@ -39,9 +39,9 @@ class AmqpHandlerTest extends TestCase
$exchange->expects($this->any()) $exchange->expects($this->any())
->method('publish') ->method('publish')
->will($this->returnCallback(function ($message, $routing_key, $flags = 0, $attributes = []) use (&$messages) { ->willReturnCallback(function ($message, $routing_key, $flags = 0, $attributes = []) use (&$messages) {
$messages[] = [$message, $routing_key, $flags, $attributes]; $messages[] = [$message, $routing_key, $flags, $attributes];
})) })
; ;
$handler = new AmqpHandler($exchange); $handler = new AmqpHandler($exchange);
@@ -96,9 +96,9 @@ class AmqpHandlerTest extends TestCase
$exchange->expects($this->any()) $exchange->expects($this->any())
->method('basic_publish') ->method('basic_publish')
->will($this->returnCallback(function (AMQPMessage $msg, $exchange = "", $routing_key = "", $mandatory = false, $immediate = false, $ticket = null) use (&$messages) { ->willReturnCallback(function (AMQPMessage $msg, $exchange = "", $routing_key = "", $mandatory = false, $immediate = false, $ticket = null) use (&$messages) {
$messages[] = [$msg, $exchange, $routing_key, $mandatory, $immediate, $ticket]; $messages[] = [$msg, $exchange, $routing_key, $mandatory, $immediate, $ticket];
})) })
; ;
$handler = new AmqpHandler($exchange, 'log'); $handler = new AmqpHandler($exchange, 'log');

View File

@@ -13,6 +13,7 @@ namespace Monolog\Handler;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use Monolog\Level; use Monolog\Level;
use PHPUnit\Framework\Attributes\DataProvider;
/** /**
* @covers Monolog\Handler\ChromePHPHandler * @covers Monolog\Handler\ChromePHPHandler
@@ -25,9 +26,7 @@ class ChromePHPHandlerTest extends TestCase
$_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; Chrome/1.0'; $_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; Chrome/1.0';
} }
/** #[DataProvider('agentsProvider')]
* @dataProvider agentsProvider
*/
public function testHeaders($agent) public function testHeaders($agent)
{ {
$_SERVER['HTTP_USER_AGENT'] = $agent; $_SERVER['HTTP_USER_AGENT'] = $agent;

View File

@@ -30,19 +30,10 @@ class DynamoDbHandlerTest extends TestCase
$this->isV3 = defined('Aws\Sdk::VERSION') && version_compare(\Aws\Sdk::VERSION, '3.0', '>='); $this->isV3 = defined('Aws\Sdk::VERSION') && version_compare(\Aws\Sdk::VERSION, '3.0', '>=');
$implementedMethods = ['__call']; $implementedMethods = ['__call'];
$absentMethods = [];
if (method_exists(DynamoDbClient::class, 'formatAttributes')) {
$implementedMethods[] = 'formatAttributes';
} else {
$absentMethods[] = 'formatAttributes';
}
$clientMockBuilder = $this->getMockBuilder(DynamoDbClient::class) $clientMockBuilder = $this->getMockBuilder(DynamoDbClient::class)
->onlyMethods($implementedMethods) ->onlyMethods($implementedMethods)
->disableOriginalConstructor(); ->disableOriginalConstructor();
if ($absentMethods) {
$clientMockBuilder->addMethods($absentMethods);
}
$this->client = $clientMockBuilder->getMock(); $this->client = $clientMockBuilder->getMock();
} }
@@ -78,12 +69,7 @@ class DynamoDbHandlerTest extends TestCase
->expects($this->once()) ->expects($this->once())
->method('format') ->method('format')
->with($record) ->with($record)
->will($this->returnValue($formatted)); ->willReturn($formatted);
$this->client
->expects($this->isV3 ? $this->never() : $this->once())
->method('formatAttributes')
->with($this->isType('array'))
->will($this->returnValue($formatted));
$this->client $this->client
->expects($this->once()) ->expects($this->once())
->method('__call') ->method('__call')

View File

@@ -18,6 +18,7 @@ use Monolog\Level;
use Elastica\Client; use Elastica\Client;
use Elastica\Request; use Elastica\Request;
use Elastica\Response; use Elastica\Response;
use PHPUnit\Framework\Attributes\DataProvider;
/** /**
* @group Elastica * @group Elastica
@@ -128,8 +129,8 @@ class ElasticaHandlerTest extends TestCase
/** /**
* @covers Monolog\Handler\ElasticaHandler::bulkSend * @covers Monolog\Handler\ElasticaHandler::bulkSend
* @dataProvider providerTestConnectionErrors
*/ */
#[DataProvider('providerTestConnectionErrors')]
public function testConnectionErrors($ignore, $expectedError) public function testConnectionErrors($ignore, $expectedError)
{ {
$clientOpts = ['host' => '127.0.0.1', 'port' => 1]; $clientOpts = ['host' => '127.0.0.1', 'port' => 1];

View File

@@ -19,10 +19,13 @@ use Elasticsearch\Client;
use Elastic\Elasticsearch\Client as Client8; use Elastic\Elasticsearch\Client as Client8;
use Elasticsearch\ClientBuilder; use Elasticsearch\ClientBuilder;
use Elastic\Elasticsearch\ClientBuilder as ClientBuilder8; use Elastic\Elasticsearch\ClientBuilder as ClientBuilder8;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
/** /**
* @group Elasticsearch * @group Elasticsearch
*/ */
#[CoversClass(ElasticsearchHandler::class)]
class ElasticsearchHandlerTest extends TestCase class ElasticsearchHandlerTest extends TestCase
{ {
protected Client|Client8 $client; protected Client|Client8 $client;
@@ -57,9 +60,6 @@ class ElasticsearchHandlerTest extends TestCase
unset($this->client); unset($this->client);
} }
/**
* @covers Monolog\Handler\ElasticsearchHandler::setFormatter
*/
public function testSetFormatter() public function testSetFormatter()
{ {
$handler = new ElasticsearchHandler($this->client); $handler = new ElasticsearchHandler($this->client);
@@ -70,9 +70,6 @@ class ElasticsearchHandlerTest extends TestCase
$this->assertEquals('type_new', $handler->getFormatter()->getType()); $this->assertEquals('type_new', $handler->getFormatter()->getType());
} }
/**
* @covers Monolog\Handler\ElasticsearchHandler::setFormatter
*/
public function testSetFormatterInvalid() public function testSetFormatterInvalid()
{ {
$handler = new ElasticsearchHandler($this->client); $handler = new ElasticsearchHandler($this->client);
@@ -84,10 +81,6 @@ class ElasticsearchHandlerTest extends TestCase
$handler->setFormatter($formatter); $handler->setFormatter($formatter);
} }
/**
* @covers Monolog\Handler\ElasticsearchHandler::__construct
* @covers Monolog\Handler\ElasticsearchHandler::getOptions
*/
public function testOptions() public function testOptions()
{ {
$expected = [ $expected = [
@@ -105,10 +98,7 @@ class ElasticsearchHandlerTest extends TestCase
$this->assertEquals($expected, $handler->getOptions()); $this->assertEquals($expected, $handler->getOptions());
} }
/** #[DataProvider('providerTestConnectionErrors')]
* @covers Monolog\Handler\ElasticsearchHandler::bulkSend
* @dataProvider providerTestConnectionErrors
*/
public function testConnectionErrors($ignore, $expectedError) public function testConnectionErrors($ignore, $expectedError)
{ {
$hosts = ['http://127.0.0.1:1']; $hosts = ['http://127.0.0.1:1'];

View File

@@ -78,13 +78,12 @@ class FlowdockHandlerTest extends TestCase
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('fsockopen') ->method('fsockopen')
->will($this->returnValue($this->res)); ->willReturn($this->res);
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('streamSetTimeout') ->method('streamSetTimeout')
->will($this->returnValue(true)); ->willReturn(true);
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('closeSocket') ->method('closeSocket');
->will($this->returnValue(true));
$this->handler->setFormatter(new FlowdockFormatter('test_source', 'source@test.com')); $this->handler->setFormatter(new FlowdockFormatter('test_source', 'source@test.com'));
} }

View File

@@ -12,6 +12,7 @@
namespace Monolog\Handler; namespace Monolog\Handler;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
/** /**
@@ -45,11 +46,8 @@ class HandlerWrapperTest extends TestCase
]; ];
} }
/** #[DataProvider('trueFalseDataProvider')]
* @param $result public function testIsHandling(bool $result)
* @dataProvider trueFalseDataProvider
*/
public function testIsHandling($result)
{ {
$record = $this->getRecord(); $record = $this->getRecord();
$this->handler->expects($this->once()) $this->handler->expects($this->once())
@@ -60,11 +58,8 @@ class HandlerWrapperTest extends TestCase
$this->assertEquals($result, $this->wrapper->isHandling($record)); $this->assertEquals($result, $this->wrapper->isHandling($record));
} }
/** #[DataProvider('trueFalseDataProvider')]
* @param $result public function testHandle(bool $result)
* @dataProvider trueFalseDataProvider
*/
public function testHandle($result)
{ {
$record = $this->getRecord(); $record = $this->getRecord();
$this->handler->expects($this->once()) $this->handler->expects($this->once())
@@ -75,11 +70,8 @@ class HandlerWrapperTest extends TestCase
$this->assertEquals($result, $this->wrapper->handle($record)); $this->assertEquals($result, $this->wrapper->handle($record));
} }
/** #[DataProvider('trueFalseDataProvider')]
* @param $result public function testHandleBatch(bool $result)
* @dataProvider trueFalseDataProvider
*/
public function testHandleBatch($result)
{ {
$records = $this->getMultipleRecords(); $records = $this->getMultipleRecords();
$this->handler->expects($this->once()) $this->handler->expects($this->once())

View File

@@ -73,12 +73,11 @@ class InsightOpsHandlerTest extends TestCase
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('fsockopen') ->method('fsockopen')
->will($this->returnValue($this->resource)); ->willReturn($this->resource);
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('streamSetTimeout') ->method('streamSetTimeout')
->will($this->returnValue(true)); ->willReturn(true);
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('closeSocket') ->method('closeSocket');
->will($this->returnValue(true));
} }
} }

View File

@@ -77,12 +77,11 @@ class LogEntriesHandlerTest extends TestCase
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('fsockopen') ->method('fsockopen')
->will($this->returnValue($this->res)); ->willReturn($this->res);
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('streamSetTimeout') ->method('streamSetTimeout')
->will($this->returnValue(true)); ->willReturn(true);
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('closeSocket') ->method('closeSocket');
->will($this->returnValue(true));
} }
} }

View File

@@ -77,12 +77,11 @@ class LogmaticHandlerTest extends TestCase
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('fsockopen') ->method('fsockopen')
->will($this->returnValue($this->res)); ->willReturn($this->res);
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('streamSetTimeout') ->method('streamSetTimeout')
->will($this->returnValue(true)); ->willReturn(true);
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('closeSocket') ->method('closeSocket');
->will($this->returnValue(true));
} }
} }

View File

@@ -21,11 +21,11 @@ class MailHandlerTest extends TestCase
*/ */
public function testHandleBatch() public function testHandleBatch()
{ {
$formatter = $this->createMock('Monolog\\Formatter\\FormatterInterface'); $formatter = $this->createMock('Monolog\Formatter\FormatterInterface');
$formatter->expects($this->once()) $formatter->expects($this->once())
->method('formatBatch'); // Each record is formatted ->method('formatBatch'); // Each record is formatted
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler', [], '', true, true, true, ['send', 'write']); $handler = $this->createPartialMock('Monolog\Handler\MailHandler', ['send', 'write']);
$handler->expects($this->once()) $handler->expects($this->once())
->method('send'); ->method('send');
$handler->expects($this->never()) $handler->expects($this->never())
@@ -47,7 +47,7 @@ class MailHandlerTest extends TestCase
$this->getRecord(Level::Info, 'information'), $this->getRecord(Level::Info, 'information'),
]; ];
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler'); $handler = $this->createPartialMock('Monolog\Handler\MailHandler', ['send']);
$handler->expects($this->never()) $handler->expects($this->never())
->method('send'); ->method('send');
$handler->setLevel(Level::Error); $handler->setLevel(Level::Error);
@@ -60,16 +60,15 @@ class MailHandlerTest extends TestCase
*/ */
public function testHandle() public function testHandle()
{ {
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler'); $handler = $this->createPartialMock('Monolog\Handler\MailHandler', ['send']);
$handler->setFormatter(new \Monolog\Formatter\LineFormatter); $handler->setFormatter(new \Monolog\Formatter\LineFormatter);
$record = $this->getRecord(); $record = $this->getRecord(message: 'test handle');
$records = [$record]; $record->formatted = '['.$record->datetime.'] test.WARNING: test handle [] []'."\n";
$records[0]['formatted'] = '['.$record->datetime.'] test.WARNING: test [] []'."\n";
$handler->expects($this->once()) $handler->expects($this->once())
->method('send') ->method('send')
->with($records[0]['formatted'], $records); ->with($record->formatted, [$record]);
$handler->handle($record); $handler->handle($record);
} }

View File

@@ -43,7 +43,7 @@ class MongoDBHandlerTest extends TestCase
$mongodb->expects($this->once()) $mongodb->expects($this->once())
->method('selectCollection') ->method('selectCollection')
->with('db', 'collection') ->with('db', 'collection')
->will($this->returnValue($collection)); ->willReturn($collection);
$record = $this->getRecord(); $record = $this->getRecord();
$expected = $record->toArray(); $expected = $record->toArray();

View File

@@ -13,24 +13,21 @@ namespace Monolog\Handler;
use Monolog\Level; use Monolog\Level;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
/** /**
* @covers Monolog\Handler\NoopHandler::handle * @covers Monolog\Handler\NoopHandler::handle
*/ */
class NoopHandlerTest extends TestCase class NoopHandlerTest extends TestCase
{ {
/** #[DataProvider('logLevelsProvider')]
* @dataProvider logLevelsProvider
*/
public function testIsHandling(Level $level) public function testIsHandling(Level $level)
{ {
$handler = new NoopHandler(); $handler = new NoopHandler();
$this->assertTrue($handler->isHandling($this->getRecord($level))); $this->assertTrue($handler->isHandling($this->getRecord($level)));
} }
/** #[DataProvider('logLevelsProvider')]
* @dataProvider logLevelsProvider
*/
public function testHandle(Level $level) public function testHandle(Level $level)
{ {
$handler = new NoopHandler(); $handler = new NoopHandler();

View File

@@ -20,6 +20,7 @@ use PhpConsole\Connector;
use PhpConsole\Dispatcher\Debug as DebugDispatcher; use PhpConsole\Dispatcher\Debug as DebugDispatcher;
use PhpConsole\Dispatcher\Errors as ErrorDispatcher; use PhpConsole\Dispatcher\Errors as ErrorDispatcher;
use PhpConsole\Handler as VendorPhpConsoleHandler; use PhpConsole\Handler as VendorPhpConsoleHandler;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
/** /**
@@ -99,7 +100,7 @@ class PHPConsoleHandlerTest extends TestCase
$connector->expects($this->any()) $connector->expects($this->any())
->method('isActiveClient') ->method('isActiveClient')
->will($this->returnValue(true)); ->willReturn(true);
return $connector; return $connector;
} }
@@ -246,9 +247,7 @@ class PHPConsoleHandlerTest extends TestCase
]; ];
} }
/** #[DataProvider('provideConnectorMethodsOptionsSets')]
* @dataProvider provideConnectorMethodsOptionsSets
*/
public function testOptionCallsConnectorMethod($option, $method, $value, $isArgument = true) public function testOptionCallsConnectorMethod($option, $method, $value, $isArgument = true)
{ {
$expectCall = $this->connector->expects($this->once())->method($method); $expectCall = $this->connector->expects($this->once())->method($method);
@@ -275,9 +274,7 @@ class PHPConsoleHandlerTest extends TestCase
]; ];
} }
/** #[DataProvider('provideDumperOptionsValues')]
* @dataProvider provideDumperOptionsValues
*/
public function testDumperOptions($option, $dumperProperty, $value) public function testDumperOptions($option, $dumperProperty, $value)
{ {
new PHPConsoleHandler([$option => $value], $this->connector); new PHPConsoleHandler([$option => $value], $this->connector);

View File

@@ -13,6 +13,7 @@ namespace Monolog\Handler;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use Monolog\Level; use Monolog\Level;
use PHPUnit\Framework\Attributes\DataProvider;
class ProcessHandlerTest extends TestCase class ProcessHandlerTest extends TestCase
{ {
@@ -76,11 +77,10 @@ class ProcessHandlerTest extends TestCase
} }
/** /**
* @dataProvider invalidCommandProvider
* @param mixed $invalidCommand
* @covers Monolog\Handler\ProcessHandler::guardAgainstInvalidCommand * @covers Monolog\Handler\ProcessHandler::guardAgainstInvalidCommand
*/ */
public function testConstructWithInvalidCommandThrowsInvalidArgumentException($invalidCommand, $expectedExcep) #[DataProvider('invalidCommandProvider')]
public function testConstructWithInvalidCommandThrowsInvalidArgumentException(mixed $invalidCommand, string $expectedExcep)
{ {
$this->expectException($expectedExcep); $this->expectException($expectedExcep);
new ProcessHandler($invalidCommand, Level::Debug); new ProcessHandler($invalidCommand, Level::Debug);
@@ -99,10 +99,10 @@ class ProcessHandlerTest extends TestCase
} }
/** /**
* @dataProvider invalidCwdProvider
* @param mixed $invalidCwd * @param mixed $invalidCwd
* @covers Monolog\Handler\ProcessHandler::guardAgainstInvalidCwd * @covers Monolog\Handler\ProcessHandler::guardAgainstInvalidCwd
*/ */
#[DataProvider('invalidCwdProvider')]
public function testConstructWithInvalidCwdThrowsInvalidArgumentException($invalidCwd, $expectedExcep) public function testConstructWithInvalidCwdThrowsInvalidArgumentException($invalidCwd, $expectedExcep)
{ {
$this->expectException($expectedExcep); $this->expectException($expectedExcep);
@@ -136,7 +136,7 @@ class ProcessHandlerTest extends TestCase
$handler->expects($this->once()) $handler->expects($this->once())
->method('selectErrorStream') ->method('selectErrorStream')
->will($this->returnValue(false)); ->willReturn(false);
$this->expectException(\UnexpectedValueException::class); $this->expectException(\UnexpectedValueException::class);
/** @var ProcessHandler $handler */ /** @var ProcessHandler $handler */
@@ -170,7 +170,7 @@ class ProcessHandlerTest extends TestCase
$handler->expects($this->exactly(2)) $handler->expects($this->exactly(2))
->method('readProcessErrors') ->method('readProcessErrors')
->willReturnOnConsecutiveCalls('', $this->returnValue('some fake error message here')); ->willReturnOnConsecutiveCalls('', 'some fake error message here');
$this->expectException(\UnexpectedValueException::class); $this->expectException(\UnexpectedValueException::class);
/** @var ProcessHandler $handler */ /** @var ProcessHandler $handler */

View File

@@ -14,6 +14,7 @@ namespace Monolog\Handler;
use Monolog\Level; use Monolog\Level;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use Monolog\Formatter\LineFormatter; use Monolog\Formatter\LineFormatter;
use PHPUnit\Framework\Attributes\DataProvider;
/** /**
* @covers Monolog\Handler\PsrHandler::handle * @covers Monolog\Handler\PsrHandler::handle
@@ -28,9 +29,7 @@ class PsrHandlerTest extends TestCase
); );
} }
/** #[DataProvider('logLevelProvider')]
* @dataProvider logLevelProvider
*/
public function testHandlesAllLevels(string $levelName, Level $level) public function testHandlesAllLevels(string $levelName, Level $level)
{ {
$message = 'Hello, world! ' . $level->value; $message = 'Hello, world! ' . $level->value;

View File

@@ -136,13 +136,12 @@ class PushoverHandlerTest extends TestCase
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('fsockopen') ->method('fsockopen')
->will($this->returnValue($this->res)); ->willReturn($this->res);
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('streamSetTimeout') ->method('streamSetTimeout')
->will($this->returnValue(true)); ->willReturn(true);
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('closeSocket') ->method('closeSocket');
->will($this->returnValue(true));
$this->handler->setFormatter($this->getIdentityFormatter()); $this->handler->setFormatter($this->getIdentityFormatter());
} }

View File

@@ -78,19 +78,19 @@ class RedisHandlerTest extends TestCase
// Redis uses multi // Redis uses multi
$redis->expects($this->once()) $redis->expects($this->once())
->method('multi') ->method('multi')
->will($this->returnSelf()); ->willReturnSelf();
$redis->expects($this->once()) $redis->expects($this->once())
->method('rPush') ->method('rPush')
->will($this->returnSelf()); ->willReturnSelf();
$redis->expects($this->once()) $redis->expects($this->once())
->method('lTrim') ->method('lTrim')
->will($this->returnSelf()); ->willReturnSelf();
$redis->expects($this->once()) $redis->expects($this->once())
->method('exec') ->method('exec')
->will($this->returnSelf()); ->willReturnSelf();
$record = $this->getRecord(Level::Warning, 'test', ['data' => new \stdClass, 'foo' => 34]); $record = $this->getRecord(Level::Warning, 'test', ['data' => new \stdClass, 'foo' => 34]);
@@ -101,32 +101,32 @@ class RedisHandlerTest extends TestCase
public function testPredisHandleCapped() public function testPredisHandleCapped()
{ {
$redis = $this->createPartialMock('Predis\Client', ['transaction']); $redis = new class extends \Predis\Client {
public array $testResults = [];
$redisTransaction = $this->getMockBuilder('Predis\Client') public function rpush(...$args) {
->disableOriginalConstructor() $this->testResults[] = ['rpush', ...$args];
->addMethods(['rPush', 'lTrim']) return $this;
->getMock(); }
public function ltrim(...$args) {
$redisTransaction->expects($this->once()) $this->testResults[] = ['ltrim', ...$args];
->method('rPush') return $this;
->will($this->returnSelf()); }
public function transaction(...$args) {
$redisTransaction->expects($this->once()) $this->testResults[] = ['transaction start'];
->method('lTrim') return ($args[0])($this);
->will($this->returnSelf()); }
};
// Redis uses multi
$redis->expects($this->once())
->method('transaction')
->will($this->returnCallback(function ($cb) use ($redisTransaction) {
$cb($redisTransaction);
}));
$record = $this->getRecord(Level::Warning, 'test', ['data' => new \stdClass, 'foo' => 34]); $record = $this->getRecord(Level::Warning, 'test', ['data' => new \stdClass, 'foo' => 34]);
$handler = new RedisHandler($redis, 'key', Level::Debug, true, 10); $handler = new RedisHandler($redis, 'key', Level::Debug, true, 10);
$handler->setFormatter(new LineFormatter("%message%")); $handler->setFormatter(new LineFormatter("%message%"));
$handler->handle($record); $handler->handle($record);
self::assertsame([
['transaction start'],
['rpush', 'key', 'test'],
['ltrim', 'key', -10, -1],
], $redis->testResults);
} }
} }

View File

@@ -13,6 +13,7 @@ namespace Monolog\Handler;
use InvalidArgumentException; use InvalidArgumentException;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
/** /**
* @covers Monolog\Handler\RotatingFileHandler * @covers Monolog\Handler\RotatingFileHandler
@@ -106,9 +107,7 @@ class RotatingFileHandlerTest extends TestCase
$this->assertEquals('test', file_get_contents($log)); $this->assertEquals('test', file_get_contents($log));
} }
/** #[DataProvider('rotationTests')]
* @dataProvider rotationTests
*/
public function testRotation($createFile, $dateFormat, $timeCallback) public function testRotation($createFile, $dateFormat, $timeCallback)
{ {
touch($old1 = __DIR__.'/Fixtures/foo-'.date($dateFormat, $timeCallback(-1)).'.rot'); touch($old1 = __DIR__.'/Fixtures/foo-'.date($dateFormat, $timeCallback(-1)).'.rot');
@@ -176,9 +175,7 @@ class RotatingFileHandlerTest extends TestCase
return $file; return $file;
} }
/** #[DataProvider('rotationWithFolderByDateTests')]
* @dataProvider rotationWithFolderByDateTests
*/
public function testRotationWithFolderByDate($createFile, $dateFormat, $timeCallback) public function testRotationWithFolderByDate($createFile, $dateFormat, $timeCallback)
{ {
$old1 = $this->createDeep(__DIR__.'/Fixtures/'.date($dateFormat, $timeCallback(-1)).'/foo.rot'); $old1 = $this->createDeep(__DIR__.'/Fixtures/'.date($dateFormat, $timeCallback(-1)).'/foo.rot');
@@ -238,9 +235,7 @@ class RotatingFileHandlerTest extends TestCase
]; ];
} }
/** #[DataProvider('dateFormatProvider')]
* @dataProvider dateFormatProvider
*/
public function testAllowOnlyFixedDefinedDateFormats($dateFormat, $valid) public function testAllowOnlyFixedDefinedDateFormats($dateFormat, $valid)
{ {
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2); $handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2);
@@ -279,9 +274,7 @@ class RotatingFileHandlerTest extends TestCase
]; ];
} }
/** #[DataProvider('filenameFormatProvider')]
* @dataProvider filenameFormatProvider
*/
public function testDisallowFilenameFormatsWithoutDate($filenameFormat, $valid) public function testDisallowFilenameFormatsWithoutDate($filenameFormat, $valid)
{ {
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2); $handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2);
@@ -307,9 +300,7 @@ class RotatingFileHandlerTest extends TestCase
]; ];
} }
/** #[DataProvider('rotationWhenSimilarFilesExistTests')]
* @dataProvider rotationWhenSimilarFilesExistTests
*/
public function testRotationWhenSimilarFileNamesExist($dateFormat) public function testRotationWhenSimilarFileNamesExist($dateFormat)
{ {
touch($old1 = __DIR__.'/Fixtures/foo-foo-'.date($dateFormat).'.rot'); touch($old1 = __DIR__.'/Fixtures/foo-foo-'.date($dateFormat).'.rot');

View File

@@ -13,10 +13,10 @@ namespace Monolog\Handler\Slack;
use Monolog\Level; use Monolog\Level;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
/** #[CoversClass(SlackRecord::class)]
* @coversDefaultClass Monolog\Handler\Slack\SlackRecord
*/
class SlackRecordTest extends TestCase class SlackRecordTest extends TestCase
{ {
public static function dataGetAttachmentColor() public static function dataGetAttachmentColor()
@@ -33,10 +33,7 @@ class SlackRecordTest extends TestCase
]; ];
} }
/** #[DataProvider('dataGetAttachmentColor')]
* @dataProvider dataGetAttachmentColor
* @covers ::getAttachmentColor
*/
public function testGetAttachmentColor(Level $logLevel, string $expectedColour) public function testGetAttachmentColor(Level $logLevel, string $expectedColour)
{ {
$slackRecord = new SlackRecord(); $slackRecord = new SlackRecord();
@@ -78,9 +75,7 @@ class SlackRecordTest extends TestCase
]; ];
} }
/** #[DataProvider('dataStringify')]
* @dataProvider dataStringify
*/
public function testStringify($fields, $expectedResult) public function testStringify($fields, $expectedResult)
{ {
$slackRecord = new SlackRecord( $slackRecord = new SlackRecord(
@@ -162,17 +157,17 @@ class SlackRecordTest extends TestCase
$formatter $formatter
->expects($this->any()) ->expects($this->any())
->method('format') ->method('format')
->will($this->returnCallback(function ($record) { ->willReturnCallback(function ($record) {
return $record->message . 'test'; return $record->message . 'test';
})); });
$formatter2 = $this->createMock('Monolog\\Formatter\\FormatterInterface'); $formatter2 = $this->createMock('Monolog\\Formatter\\FormatterInterface');
$formatter2 $formatter2
->expects($this->any()) ->expects($this->any())
->method('format') ->method('format')
->will($this->returnCallback(function ($record) { ->willReturnCallback(function ($record) {
return $record->message . 'test1'; return $record->message . 'test1';
})); });
$message = 'Test message'; $message = 'Test message';
$record = new SlackRecord(null, null, false, null, false, false, [], $formatter); $record = new SlackRecord(null, null, false, null, false, false, [], $formatter);

View File

@@ -15,6 +15,7 @@ use Monolog\Test\TestCase;
use Monolog\Level; use Monolog\Level;
use Monolog\Formatter\LineFormatter; use Monolog\Formatter\LineFormatter;
use Monolog\Handler\Slack\SlackRecord; use Monolog\Handler\Slack\SlackRecord;
use PHPUnit\Framework\Attributes\DataProvider;
/** /**
* @author Greg Kedzierski <greg@gregkedzierski.com> * @author Greg Kedzierski <greg@gregkedzierski.com>
@@ -93,9 +94,7 @@ class SlackHandlerTest extends TestCase
$this->assertMatchesRegularExpression('/icon_emoji=%3Aalien%3A/', $content); $this->assertMatchesRegularExpression('/icon_emoji=%3Aalien%3A/', $content);
} }
/** #[DataProvider('provideLevelColors')]
* @dataProvider provideLevelColors
*/
public function testWriteContentWithColors($level, $expectedColor) public function testWriteContentWithColors($level, $expectedColor)
{ {
$this->createHandler(); $this->createHandler();
@@ -145,13 +144,12 @@ class SlackHandlerTest extends TestCase
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('fsockopen') ->method('fsockopen')
->will($this->returnValue($this->res)); ->willReturn($this->res);
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('streamSetTimeout') ->method('streamSetTimeout')
->will($this->returnValue(true)); ->willReturn(true);
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('closeSocket') ->method('closeSocket');
->will($this->returnValue(true));
$this->handler->setFormatter($this->getIdentityFormatter()); $this->handler->setFormatter($this->getIdentityFormatter());
} }

View File

@@ -97,7 +97,7 @@ class SocketHandlerTest extends TestCase
$this->setMockHandler(['fsockopen']); $this->setMockHandler(['fsockopen']);
$this->handler->expects($this->once()) $this->handler->expects($this->once())
->method('fsockopen') ->method('fsockopen')
->will($this->returnValue(false)); ->willReturn(false);
$this->expectException(\UnexpectedValueException::class); $this->expectException(\UnexpectedValueException::class);
@@ -109,7 +109,7 @@ class SocketHandlerTest extends TestCase
$this->setMockHandler(['pfsockopen']); $this->setMockHandler(['pfsockopen']);
$this->handler->expects($this->once()) $this->handler->expects($this->once())
->method('pfsockopen') ->method('pfsockopen')
->will($this->returnValue(false)); ->willReturn(false);
$this->handler->setPersistent(true); $this->handler->setPersistent(true);
@@ -123,7 +123,7 @@ class SocketHandlerTest extends TestCase
$this->setMockHandler(['streamSetTimeout']); $this->setMockHandler(['streamSetTimeout']);
$this->handler->expects($this->once()) $this->handler->expects($this->once())
->method('streamSetTimeout') ->method('streamSetTimeout')
->will($this->returnValue(false)); ->willReturn(false);
$this->expectException(\UnexpectedValueException::class); $this->expectException(\UnexpectedValueException::class);
@@ -136,7 +136,7 @@ class SocketHandlerTest extends TestCase
$this->handler->setChunkSize(8192); $this->handler->setChunkSize(8192);
$this->handler->expects($this->once()) $this->handler->expects($this->once())
->method('streamSetChunkSize') ->method('streamSetChunkSize')
->will($this->returnValue(false)); ->willReturn(false);
$this->expectException(\UnexpectedValueException::class); $this->expectException(\UnexpectedValueException::class);
@@ -158,7 +158,7 @@ class SocketHandlerTest extends TestCase
$this->handler->expects($this->exactly(2)) $this->handler->expects($this->exactly(2))
->method('fwrite') ->method('fwrite')
->will($this->returnCallback($callback)); ->willReturnCallback($callback);
$this->expectException(\RuntimeException::class); $this->expectException(\RuntimeException::class);
@@ -180,10 +180,10 @@ class SocketHandlerTest extends TestCase
$this->handler->expects($this->exactly(1)) $this->handler->expects($this->exactly(1))
->method('fwrite') ->method('fwrite')
->will($this->returnCallback($callback)); ->willReturnCallback($callback);
$this->handler->expects($this->exactly(1)) $this->handler->expects($this->exactly(1))
->method('streamGetMetadata') ->method('streamGetMetadata')
->will($this->returnValue(['timed_out' => true])); ->willReturn(['timed_out' => true]);
$this->expectException(\RuntimeException::class); $this->expectException(\RuntimeException::class);
@@ -203,10 +203,10 @@ class SocketHandlerTest extends TestCase
$this->handler->expects($this->exactly(1)) $this->handler->expects($this->exactly(1))
->method('fwrite') ->method('fwrite')
->will($this->returnCallback($callback)); ->willReturnCallback($callback);
$this->handler->expects($this->exactly(1)) $this->handler->expects($this->exactly(1))
->method('streamGetMetadata') ->method('streamGetMetadata')
->will($this->returnValue(['timed_out' => false])); ->willReturn(['timed_out' => false]);
$this->expectException(\RuntimeException::class); $this->expectException(\RuntimeException::class);
@@ -238,7 +238,7 @@ class SocketHandlerTest extends TestCase
$this->handler->expects($this->exactly(2)) $this->handler->expects($this->exactly(2))
->method('fwrite') ->method('fwrite')
->will($this->returnCallback($callback)); ->willReturnCallback($callback);
$this->writeRecord('Hello world'); $this->writeRecord('Hello world');
} }
@@ -268,11 +268,11 @@ class SocketHandlerTest extends TestCase
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('fwrite') ->method('fwrite')
->will($this->returnValue(0)); ->willReturn(0);
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('streamGetMetadata') ->method('streamGetMetadata')
->will($this->returnValue(['timed_out' => false])); ->willReturn(['timed_out' => false]);
$this->handler->setWritingTimeout(1); $this->handler->setWritingTimeout(1);
@@ -311,25 +311,25 @@ class SocketHandlerTest extends TestCase
if (!in_array('fsockopen', $methods)) { if (!in_array('fsockopen', $methods)) {
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('fsockopen') ->method('fsockopen')
->will($this->returnValue($this->res)); ->willReturn($this->res);
} }
if (!in_array('pfsockopen', $methods)) { if (!in_array('pfsockopen', $methods)) {
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('pfsockopen') ->method('pfsockopen')
->will($this->returnValue($this->res)); ->willReturn($this->res);
} }
if (!in_array('streamSetTimeout', $methods)) { if (!in_array('streamSetTimeout', $methods)) {
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('streamSetTimeout') ->method('streamSetTimeout')
->will($this->returnValue(true)); ->willReturn(true);
} }
if (!in_array('streamSetChunkSize', $methods)) { if (!in_array('streamSetChunkSize', $methods)) {
$this->handler->expects($this->any()) $this->handler->expects($this->any())
->method('streamSetChunkSize') ->method('streamSetChunkSize')
->will($this->returnValue(8192)); ->willReturn(8192);
} }
$this->handler->setFormatter($this->getIdentityFormatter()); $this->handler->setFormatter($this->getIdentityFormatter());

View File

@@ -13,6 +13,7 @@ namespace Monolog\Handler;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use Monolog\Level; use Monolog\Level;
use PHPUnit\Framework\Attributes\DataProvider;
class StreamHandlerTest extends TestCase class StreamHandlerTest extends TestCase
{ {
@@ -127,9 +128,9 @@ class StreamHandlerTest extends TestCase
} }
/** /**
* @dataProvider invalidArgumentProvider
* @covers Monolog\Handler\StreamHandler::__construct * @covers Monolog\Handler\StreamHandler::__construct
*/ */
#[DataProvider('invalidArgumentProvider')]
public function testWriteInvalidArgument($invalidArgument) public function testWriteInvalidArgument($invalidArgument)
{ {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);
@@ -207,8 +208,8 @@ STRING;
/** /**
* @covers Monolog\Handler\StreamHandler::__construct * @covers Monolog\Handler\StreamHandler::__construct
* @covers Monolog\Handler\StreamHandler::write * @covers Monolog\Handler\StreamHandler::write
* @dataProvider provideNonExistingAndNotCreatablePath
*/ */
#[DataProvider('provideNonExistingAndNotCreatablePath')]
public function testWriteNonExistingAndNotCreatablePath($nonExistingAndNotCreatablePath) public function testWriteNonExistingAndNotCreatablePath($nonExistingAndNotCreatablePath)
{ {
if (defined('PHP_WINDOWS_VERSION_BUILD')) { if (defined('PHP_WINDOWS_VERSION_BUILD')) {
@@ -259,9 +260,7 @@ STRING;
]; ];
} }
/** #[DataProvider('provideMemoryValues')]
* @dataProvider provideMemoryValues
*/
public function testPreventOOMError($phpMemory, $expectedChunkSize): void public function testPreventOOMError($phpMemory, $expectedChunkSize): void
{ {
$previousValue = ini_set('memory_limit', $phpMemory); $previousValue = ini_set('memory_limit', $phpMemory);

View File

@@ -13,15 +13,14 @@ namespace Monolog\Handler;
use Monolog\Level; use Monolog\Level;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
/** /**
* @covers Monolog\Handler\TestHandler * @covers Monolog\Handler\TestHandler
*/ */
class TestHandlerTest extends TestCase class TestHandlerTest extends TestCase
{ {
/** #[DataProvider('methodProvider')]
* @dataProvider methodProvider
*/
public function testHandler($method, Level $level) public function testHandler($method, Level $level)
{ {
$handler = new TestHandler; $handler = new TestHandler;

View File

@@ -49,11 +49,11 @@ class ZendMonitorHandlerTest extends TestCase
$formatterMock->expects($this->once()) $formatterMock->expects($this->once())
->method('format') ->method('format')
->will($this->returnValue($formatterResult)); ->willReturn($formatterResult);
$zendMonitor->expects($this->once()) $zendMonitor->expects($this->once())
->method('getDefaultFormatter') ->method('getDefaultFormatter')
->will($this->returnValue($formatterMock)); ->willReturn($formatterMock);
$zendMonitor->expects($this->once()) $zendMonitor->expects($this->once())
->method('writeZendMonitorCustomEvent') ->method('writeZendMonitorCustomEvent')

View File

@@ -15,6 +15,7 @@ use Monolog\Handler\HandlerInterface;
use Monolog\Processor\WebProcessor; use Monolog\Processor\WebProcessor;
use Monolog\Handler\TestHandler; use Monolog\Handler\TestHandler;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
class LoggerTest extends TestCase class LoggerTest extends TestCase
{ {
@@ -161,7 +162,7 @@ class LoggerTest extends TestCase
$logger = new Logger(__METHOD__); $logger = new Logger(__METHOD__);
$handler = $this->getMockBuilder('Monolog\Handler\HandlerInterface')->getMock(); $handler = $this->getMockBuilder('Monolog\Handler\HandlerInterface')->getMock();
$handler->expects($this->once())->method('isHandling')->will($this->returnValue(false)); $handler->expects($this->once())->method('isHandling')->willReturn(false);
$handler->expects($this->never())->method('handle'); $handler->expects($this->never())->method('handle');
$logger->pushProcessor(fn (LogRecord $record) => $record); $logger->pushProcessor(fn (LogRecord $record) => $record);
@@ -283,11 +284,11 @@ class LoggerTest extends TestCase
$handler = $this->createMock('Monolog\Handler\HandlerInterface'); $handler = $this->createMock('Monolog\Handler\HandlerInterface');
$handler->expects($this->any()) $handler->expects($this->any())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(true)) ->willReturn(true);
; ;
$handler->expects($this->any()) $handler->expects($this->any())
->method('handle') ->method('handle')
->will($this->returnValue(true)) ->willReturn(true);
; ;
$logger->pushHandler($handler); $logger->pushHandler($handler);
@@ -298,7 +299,7 @@ class LoggerTest extends TestCase
; ;
$processor->expects($this->once()) $processor->expects($this->once())
->method('__invoke') ->method('__invoke')
->will($this->returnArgument(0)) ->willReturnArgument(0)
; ;
$logger->pushProcessor($processor); $logger->pushProcessor($processor);
@@ -314,7 +315,7 @@ class LoggerTest extends TestCase
$handler = $this->createMock('Monolog\Handler\HandlerInterface'); $handler = $this->createMock('Monolog\Handler\HandlerInterface');
$handler->expects($this->once()) $handler->expects($this->once())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(false)) ->willReturn(false);
; ;
$logger->pushHandler($handler); $logger->pushHandler($handler);
$that = $this; $that = $this;
@@ -335,29 +336,29 @@ class LoggerTest extends TestCase
$handler1 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler1 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler1->expects($this->never()) $handler1->expects($this->never())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(false)) ->willReturn(false);
; ;
$handler1->expects($this->once()) $handler1->expects($this->once())
->method('handle') ->method('handle')
->will($this->returnValue(false)) ->willReturn(false);
; ;
$logger->pushHandler($handler1); $logger->pushHandler($handler1);
$handler2 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler2 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler2->expects($this->once()) $handler2->expects($this->once())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(true)) ->willReturn(true);
; ;
$handler2->expects($this->once()) $handler2->expects($this->once())
->method('handle') ->method('handle')
->will($this->returnValue(false)) ->willReturn(false);
; ;
$logger->pushHandler($handler2); $logger->pushHandler($handler2);
$handler3 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler3 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler3->expects($this->once()) $handler3->expects($this->once())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(false)) ->willReturn(false);
; ;
$handler3->expects($this->never()) $handler3->expects($this->never())
->method('handle') ->method('handle')
@@ -375,27 +376,27 @@ class LoggerTest extends TestCase
$handler1 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler1 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler1->expects($this->never()) $handler1->expects($this->never())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(false)) ->willReturn(false);
; ;
$handler1->expects($this->once()) $handler1->expects($this->once())
->method('handle') ->method('handle')
->will($this->returnValue(false)) ->willReturn(false);
; ;
$handler2 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler2 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler2->expects($this->once()) $handler2->expects($this->once())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(true)) ->willReturn(true);
; ;
$handler2->expects($this->once()) $handler2->expects($this->once())
->method('handle') ->method('handle')
->will($this->returnValue(false)) ->willReturn(false);
; ;
$handler3 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler3 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler3->expects($this->once()) $handler3->expects($this->once())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(false)) ->willReturn(false);
; ;
$handler3->expects($this->never()) $handler3->expects($this->never())
->method('handle') ->method('handle')
@@ -417,22 +418,22 @@ class LoggerTest extends TestCase
$handler1 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler1 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler1->expects($this->any()) $handler1->expects($this->any())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(true)) ->willReturn(true);
; ;
$handler1->expects($this->once()) $handler1->expects($this->once())
->method('handle') ->method('handle')
->will($this->returnValue(false)) ->willReturn(false);
; ;
$logger->pushHandler($handler1); $logger->pushHandler($handler1);
$handler2 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler2 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler2->expects($this->any()) $handler2->expects($this->any())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(true)) ->willReturn(true);
; ;
$handler2->expects($this->once()) $handler2->expects($this->once())
->method('handle') ->method('handle')
->will($this->returnValue(false)) ->willReturn(false);
; ;
$logger->pushHandler($handler2); $logger->pushHandler($handler2);
@@ -449,7 +450,7 @@ class LoggerTest extends TestCase
$handler1 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler1 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler1->expects($this->any()) $handler1->expects($this->any())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(true)) ->willReturn(true);
; ;
$handler1->expects($this->never()) $handler1->expects($this->never())
->method('handle') ->method('handle')
@@ -459,11 +460,11 @@ class LoggerTest extends TestCase
$handler2 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler2 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler2->expects($this->any()) $handler2->expects($this->any())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(true)) ->willReturn(true);
; ;
$handler2->expects($this->once()) $handler2->expects($this->once())
->method('handle') ->method('handle')
->will($this->returnValue(true)) ->willReturn(true);
; ;
$logger->pushHandler($handler2); $logger->pushHandler($handler2);
@@ -480,7 +481,7 @@ class LoggerTest extends TestCase
$handler1 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler1 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler1->expects($this->any()) $handler1->expects($this->any())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(false)) ->willReturn(false);
; ;
$logger->pushHandler($handler1); $logger->pushHandler($handler1);
@@ -489,7 +490,7 @@ class LoggerTest extends TestCase
$handler2 = $this->createMock('Monolog\Handler\HandlerInterface'); $handler2 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler2->expects($this->any()) $handler2->expects($this->any())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(true)) ->willReturn(true);
; ;
$logger->pushHandler($handler2); $logger->pushHandler($handler2);
@@ -497,7 +498,6 @@ class LoggerTest extends TestCase
} }
/** /**
* @dataProvider logMethodProvider
* @covers Level::Debug * @covers Level::Debug
* @covers Level::Info * @covers Level::Info
* @covers Level::Notice * @covers Level::Notice
@@ -507,6 +507,7 @@ class LoggerTest extends TestCase
* @covers Level::Alert * @covers Level::Alert
* @covers Level::Emergency * @covers Level::Emergency
*/ */
#[DataProvider('logMethodProvider')]
public function testLogMethods(string $method, Level $expectedLevel) public function testLogMethods(string $method, Level $expectedLevel)
{ {
$logger = new Logger('foo'); $logger = new Logger('foo');
@@ -533,9 +534,9 @@ class LoggerTest extends TestCase
} }
/** /**
* @dataProvider setTimezoneProvider
* @covers Logger::setTimezone * @covers Logger::setTimezone
*/ */
#[DataProvider('setTimezoneProvider')]
public function testSetTimezone($tz) public function testSetTimezone($tz)
{ {
$logger = new Logger('foo'); $logger = new Logger('foo');
@@ -608,10 +609,10 @@ class LoggerTest extends TestCase
} }
/** /**
* @dataProvider useMicrosecondTimestampsProvider
* @covers Logger::useMicrosecondTimestamps * @covers Logger::useMicrosecondTimestamps
* @covers Logger::addRecord * @covers Logger::addRecord
*/ */
#[DataProvider('useMicrosecondTimestampsProvider')]
public function testUseMicrosecondTimestamps($micro, $assert, $assertFormat) public function testUseMicrosecondTimestamps($micro, $assert, $assertFormat)
{ {
if (PHP_VERSION_ID === 70103) { if (PHP_VERSION_ID === 70103) {
@@ -675,7 +676,7 @@ class LoggerTest extends TestCase
$handler = $this->getMockBuilder('Monolog\Handler\HandlerInterface')->getMock(); $handler = $this->getMockBuilder('Monolog\Handler\HandlerInterface')->getMock();
$handler->expects($this->any()) $handler->expects($this->any())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(true)) ->willReturn(true);
; ;
$handler->expects($this->any()) $handler->expects($this->any())
->method('handle') ->method('handle')
@@ -704,7 +705,7 @@ class LoggerTest extends TestCase
$handler = $this->getMockBuilder('Monolog\Handler\HandlerInterface')->getMock(); $handler = $this->getMockBuilder('Monolog\Handler\HandlerInterface')->getMock();
$handler->expects($this->any()) $handler->expects($this->any())
->method('isHandling') ->method('isHandling')
->will($this->returnValue(true)) ->willReturn(true);
; ;
$handler->expects($this->any()) $handler->expects($this->any())
->method('handle') ->method('handle')

View File

@@ -12,6 +12,7 @@
namespace Monolog\Processor; namespace Monolog\Processor;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
class ClosureContextProcessorTest extends TestCase class ClosureContextProcessorTest extends TestCase
{ {
@@ -24,9 +25,7 @@ class ClosureContextProcessorTest extends TestCase
$this->assertSame($context, $record->context); $this->assertSame($context, $record->context);
} }
/** #[DataProvider('getContexts')]
* @dataProvider getContexts
*/
public function testSkip(array $context) public function testSkip(array $context)
{ {
$processor = new ClosureContextProcessor(); $processor = new ClosureContextProcessor();

View File

@@ -13,12 +13,11 @@ namespace Monolog\Processor;
use Monolog\Level; use Monolog\Level;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
class PsrLogMessageProcessorTest extends TestCase class PsrLogMessageProcessorTest extends TestCase
{ {
/** #[DataProvider('getPairs')]
* @dataProvider getPairs
*/
public function testReplacement($val, $expected) public function testReplacement($val, $expected)
{ {
$proc = new PsrLogMessageProcessor; $proc = new PsrLogMessageProcessor;

View File

@@ -15,6 +15,7 @@ use DateTimeZone;
use Monolog\Handler\TestHandler; use Monolog\Handler\TestHandler;
use Monolog\Formatter\LineFormatter; use Monolog\Formatter\LineFormatter;
use Monolog\Processor\PsrLogMessageProcessor; use Monolog\Processor\PsrLogMessageProcessor;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Psr\Log\InvalidArgumentException; use Psr\Log\InvalidArgumentException;
@@ -63,9 +64,7 @@ class PsrLogCompatTest extends TestCase
$this->assertInstanceOf(LoggerInterface::class, $this->getLogger()); $this->assertInstanceOf(LoggerInterface::class, $this->getLogger());
} }
/** #[DataProvider('provideLevelsAndMessages')]
* @dataProvider provideLevelsAndMessages
*/
public function testLogsAtAllLevels($level, $message) public function testLogsAtAllLevels($level, $message)
{ {
$logger = $this->getLogger(); $logger = $this->getLogger();
@@ -170,7 +169,7 @@ class PsrLogCompatTest extends TestCase
->getMock(); ->getMock();
$mock->method('__toString') $mock->method('__toString')
->will($this->returnValue($string)); ->willReturn($string);
return $mock; return $mock;
} }

View File

@@ -11,6 +11,8 @@
namespace Monolog; namespace Monolog;
use PHPUnit\Framework\Attributes\DataProvider;
class RegistryTest extends \PHPUnit\Framework\TestCase class RegistryTest extends \PHPUnit\Framework\TestCase
{ {
protected function setUp(): void protected function setUp(): void
@@ -19,9 +21,9 @@ class RegistryTest extends \PHPUnit\Framework\TestCase
} }
/** /**
* @dataProvider hasLoggerProvider
* @covers Monolog\Registry::hasLogger * @covers Monolog\Registry::hasLogger
*/ */
#[DataProvider('hasLoggerProvider')]
public function testHasLogger(array $loggersToAdd, array $loggersToCheck, array $expectedResult) public function testHasLogger(array $loggersToAdd, array $loggersToCheck, array $expectedResult)
{ {
foreach ($loggersToAdd as $loggerToAdd) { foreach ($loggersToAdd as $loggerToAdd) {
@@ -73,10 +75,10 @@ class RegistryTest extends \PHPUnit\Framework\TestCase
} }
/** /**
* @dataProvider removedLoggerProvider
* @covers Monolog\Registry::addLogger * @covers Monolog\Registry::addLogger
* @covers Monolog\Registry::removeLogger * @covers Monolog\Registry::removeLogger
*/ */
#[DataProvider('removedLoggerProvider')]
public function testRemovesLogger($loggerToAdd, $remove) public function testRemovesLogger($loggerToAdd, $remove)
{ {
Registry::addLogger($loggerToAdd); Registry::addLogger($loggerToAdd);

View File

@@ -13,6 +13,7 @@ namespace Monolog;
use Monolog\Handler\StreamHandler; use Monolog\Handler\StreamHandler;
use Monolog\Handler\TestHandler; use Monolog\Handler\TestHandler;
use PHPUnit\Framework\Attributes\DataProvider;
use Psr\Log\LogLevel; use Psr\Log\LogLevel;
use Monolog\Test\TestCase; use Monolog\Test\TestCase;
@@ -122,12 +123,12 @@ class SignalHandlerTest extends TestCase
} }
/** /**
* @dataProvider defaultPreviousProvider
* @depends testRegisterSignalHandler * @depends testRegisterSignalHandler
* @requires function pcntl_fork * @requires function pcntl_fork
* @requires function pcntl_sigprocmask * @requires function pcntl_sigprocmask
* @requires function pcntl_waitpid * @requires function pcntl_waitpid
*/ */
#[DataProvider('defaultPreviousProvider')]
public function testRegisterDefaultPreviousSignalHandler($signo, $callPrevious, $expected) public function testRegisterDefaultPreviousSignalHandler($signo, $callPrevious, $expected)
{ {
$this->setSignalHandler($signo, SIG_DFL); $this->setSignalHandler($signo, SIG_DFL);
@@ -174,10 +175,10 @@ class SignalHandlerTest extends TestCase
} }
/** /**
* @dataProvider callablePreviousProvider
* @depends testRegisterSignalHandler * @depends testRegisterSignalHandler
* @requires function pcntl_signal_get_handler * @requires function pcntl_signal_get_handler
*/ */
#[DataProvider('callablePreviousProvider')]
public function testRegisterCallablePreviousSignalHandler($callPrevious) public function testRegisterCallablePreviousSignalHandler($callPrevious)
{ {
$this->setSignalHandler(SIGURG, SIG_IGN); $this->setSignalHandler(SIGURG, SIG_IGN);
@@ -205,11 +206,11 @@ class SignalHandlerTest extends TestCase
} }
/** /**
* @dataProvider restartSyscallsProvider
* @depends testRegisterDefaultPreviousSignalHandler * @depends testRegisterDefaultPreviousSignalHandler
* @requires function pcntl_fork * @requires function pcntl_fork
* @requires function pcntl_waitpid * @requires function pcntl_waitpid
*/ */
#[DataProvider('restartSyscallsProvider')]
public function testRegisterSyscallRestartingSignalHandler($restartSyscalls) public function testRegisterSyscallRestartingSignalHandler($restartSyscalls)
{ {
$this->setSignalHandler(SIGURG, SIG_IGN); $this->setSignalHandler(SIGURG, SIG_IGN);
@@ -259,10 +260,10 @@ class SignalHandlerTest extends TestCase
} }
/** /**
* @dataProvider asyncProvider
* @depends testRegisterDefaultPreviousSignalHandler * @depends testRegisterDefaultPreviousSignalHandler
* @requires function pcntl_async_signals * @requires function pcntl_async_signals
*/ */
#[DataProvider('asyncProvider')]
public function testRegisterAsyncSignalHandler($initialAsync, $desiredAsync, $expectedBefore, $expectedAfter) public function testRegisterAsyncSignalHandler($initialAsync, $desiredAsync, $expectedBefore, $expectedAfter)
{ {
$this->setSignalHandler(SIGURG, SIG_IGN); $this->setSignalHandler(SIGURG, SIG_IGN);

View File

@@ -11,11 +11,11 @@
namespace Monolog; namespace Monolog;
use PHPUnit\Framework\Attributes\DataProvider;
class UtilsTest extends \PHPUnit_Framework_TestCase class UtilsTest extends \PHPUnit_Framework_TestCase
{ {
/** #[DataProvider('provideObjects')]
* @dataProvider provideObjects
*/
public function testGetClass(string $expected, object $object) public function testGetClass(string $expected, object $object)
{ {
$this->assertSame($expected, Utils::getClass($object)); $this->assertSame($expected, Utils::getClass($object));
@@ -32,9 +32,7 @@ class UtilsTest extends \PHPUnit_Framework_TestCase
]; ];
} }
/** #[DataProvider('providePathsToCanonicalize')]
* @dataProvider providePathsToCanonicalize
*/
public function testCanonicalizePath(string $expected, string $input) public function testCanonicalizePath(string $expected, string $input)
{ {
$this->assertSame($expected, Utils::canonicalizePath($input)); $this->assertSame($expected, Utils::canonicalizePath($input));
@@ -53,9 +51,7 @@ class UtilsTest extends \PHPUnit_Framework_TestCase
]; ];
} }
/** #[DataProvider('providesHandleJsonErrorFailure')]
* @dataProvider providesHandleJsonErrorFailure
*/
public function testHandleJsonErrorFailure(int $code, string $msg) public function testHandleJsonErrorFailure(int $code, string $msg)
{ {
$this->expectException('RuntimeException', $msg); $this->expectException('RuntimeException', $msg);
@@ -76,8 +72,8 @@ class UtilsTest extends \PHPUnit_Framework_TestCase
* @param mixed $in Input * @param mixed $in Input
* @param mixed $expect Expected output * @param mixed $expect Expected output
* @covers Monolog\Formatter\NormalizerFormatter::detectAndCleanUtf8 * @covers Monolog\Formatter\NormalizerFormatter::detectAndCleanUtf8
* @dataProvider providesDetectAndCleanUtf8
*/ */
#[DataProvider('providesDetectAndCleanUtf8')]
public function testDetectAndCleanUtf8($in, $expect) public function testDetectAndCleanUtf8($in, $expect)
{ {
$reflMethod = new \ReflectionMethod(Utils::class, 'detectAndCleanUtf8'); $reflMethod = new \ReflectionMethod(Utils::class, 'detectAndCleanUtf8');
@@ -106,9 +102,7 @@ class UtilsTest extends \PHPUnit_Framework_TestCase
]; ];
} }
/** #[DataProvider('providesPcreLastErrorMessage')]
* @dataProvider providesPcreLastErrorMessage
*/
public function testPcreLastErrorMessage(int $code, string $msg) public function testPcreLastErrorMessage(int $code, string $msg)
{ {
if (PHP_VERSION_ID >= 80000) { if (PHP_VERSION_ID >= 80000) {
@@ -171,12 +165,8 @@ class UtilsTest extends \PHPUnit_Framework_TestCase
]; ];
} }
/** #[DataProvider('provideIniValuesToConvertToBytes')]
* @dataProvider provideIniValuesToConvertToBytes public function testExpandIniShorthandBytes(string|null|bool $input, int|false $expected)
* @param mixed $input
* @param int|false $expected
*/
public function testExpandIniShorthandBytes($input, $expected)
{ {
$result = Utils::expandIniShorthandBytes($input); $result = Utils::expandIniShorthandBytes($input);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);