1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-08 14:16:42 +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

@@ -25,7 +25,7 @@ class AbstractHandlerTest extends TestCase
*/
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(false, $handler->getBubble());
@@ -40,7 +40,7 @@ class AbstractHandlerTest extends TestCase
*/
public function testHandleBatch()
{
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
$handler = $this->createPartialMock('Monolog\Handler\AbstractHandler', ['handle']);
$handler->expects($this->exactly(2))
->method('handle');
$handler->handleBatch([$this->getRecord(), $this->getRecord()]);
@@ -51,7 +51,7 @@ class AbstractHandlerTest extends TestCase
*/
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->assertFalse($handler->isHandling($this->getRecord(Level::Debug)));
}
@@ -61,7 +61,7 @@ class AbstractHandlerTest extends TestCase
*/
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)));
$handler->setLevel('debug');
$this->assertTrue($handler->isHandling($this->getRecord(Level::Debug)));

View File

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

View File

@@ -39,9 +39,9 @@ class AmqpHandlerTest extends TestCase
$exchange->expects($this->any())
->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];
}))
})
;
$handler = new AmqpHandler($exchange);
@@ -96,9 +96,9 @@ class AmqpHandlerTest extends TestCase
$exchange->expects($this->any())
->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];
}))
})
;
$handler = new AmqpHandler($exchange, 'log');

View File

@@ -13,6 +13,7 @@ namespace Monolog\Handler;
use Monolog\Test\TestCase;
use Monolog\Level;
use PHPUnit\Framework\Attributes\DataProvider;
/**
* @covers Monolog\Handler\ChromePHPHandler
@@ -25,9 +26,7 @@ class ChromePHPHandlerTest extends TestCase
$_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; Chrome/1.0';
}
/**
* @dataProvider agentsProvider
*/
#[DataProvider('agentsProvider')]
public function testHeaders($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', '>=');
$implementedMethods = ['__call'];
$absentMethods = [];
if (method_exists(DynamoDbClient::class, 'formatAttributes')) {
$implementedMethods[] = 'formatAttributes';
} else {
$absentMethods[] = 'formatAttributes';
}
$clientMockBuilder = $this->getMockBuilder(DynamoDbClient::class)
->onlyMethods($implementedMethods)
->disableOriginalConstructor();
if ($absentMethods) {
$clientMockBuilder->addMethods($absentMethods);
}
$this->client = $clientMockBuilder->getMock();
}
@@ -78,12 +69,7 @@ class DynamoDbHandlerTest extends TestCase
->expects($this->once())
->method('format')
->with($record)
->will($this->returnValue($formatted));
$this->client
->expects($this->isV3 ? $this->never() : $this->once())
->method('formatAttributes')
->with($this->isType('array'))
->will($this->returnValue($formatted));
->willReturn($formatted);
$this->client
->expects($this->once())
->method('__call')

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -78,19 +78,19 @@ class RedisHandlerTest extends TestCase
// Redis uses multi
$redis->expects($this->once())
->method('multi')
->will($this->returnSelf());
->willReturnSelf();
$redis->expects($this->once())
->method('rPush')
->will($this->returnSelf());
->willReturnSelf();
$redis->expects($this->once())
->method('lTrim')
->will($this->returnSelf());
->willReturnSelf();
$redis->expects($this->once())
->method('exec')
->will($this->returnSelf());
->willReturnSelf();
$record = $this->getRecord(Level::Warning, 'test', ['data' => new \stdClass, 'foo' => 34]);
@@ -101,32 +101,32 @@ class RedisHandlerTest extends TestCase
public function testPredisHandleCapped()
{
$redis = $this->createPartialMock('Predis\Client', ['transaction']);
$redisTransaction = $this->getMockBuilder('Predis\Client')
->disableOriginalConstructor()
->addMethods(['rPush', 'lTrim'])
->getMock();
$redisTransaction->expects($this->once())
->method('rPush')
->will($this->returnSelf());
$redisTransaction->expects($this->once())
->method('lTrim')
->will($this->returnSelf());
// Redis uses multi
$redis->expects($this->once())
->method('transaction')
->will($this->returnCallback(function ($cb) use ($redisTransaction) {
$cb($redisTransaction);
}));
$redis = new class extends \Predis\Client {
public array $testResults = [];
public function rpush(...$args) {
$this->testResults[] = ['rpush', ...$args];
return $this;
}
public function ltrim(...$args) {
$this->testResults[] = ['ltrim', ...$args];
return $this;
}
public function transaction(...$args) {
$this->testResults[] = ['transaction start'];
return ($args[0])($this);
}
};
$record = $this->getRecord(Level::Warning, 'test', ['data' => new \stdClass, 'foo' => 34]);
$handler = new RedisHandler($redis, 'key', Level::Debug, true, 10);
$handler->setFormatter(new LineFormatter("%message%"));
$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 Monolog\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
/**
* @covers Monolog\Handler\RotatingFileHandler
@@ -106,9 +107,7 @@ class RotatingFileHandlerTest extends TestCase
$this->assertEquals('test', file_get_contents($log));
}
/**
* @dataProvider rotationTests
*/
#[DataProvider('rotationTests')]
public function testRotation($createFile, $dateFormat, $timeCallback)
{
touch($old1 = __DIR__.'/Fixtures/foo-'.date($dateFormat, $timeCallback(-1)).'.rot');
@@ -176,9 +175,7 @@ class RotatingFileHandlerTest extends TestCase
return $file;
}
/**
* @dataProvider rotationWithFolderByDateTests
*/
#[DataProvider('rotationWithFolderByDateTests')]
public function testRotationWithFolderByDate($createFile, $dateFormat, $timeCallback)
{
$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)
{
$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)
{
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2);
@@ -307,9 +300,7 @@ class RotatingFileHandlerTest extends TestCase
];
}
/**
* @dataProvider rotationWhenSimilarFilesExistTests
*/
#[DataProvider('rotationWhenSimilarFilesExistTests')]
public function testRotationWhenSimilarFileNamesExist($dateFormat)
{
touch($old1 = __DIR__.'/Fixtures/foo-foo-'.date($dateFormat).'.rot');

View File

@@ -13,10 +13,10 @@ namespace Monolog\Handler\Slack;
use Monolog\Level;
use Monolog\Test\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
/**
* @coversDefaultClass Monolog\Handler\Slack\SlackRecord
*/
#[CoversClass(SlackRecord::class)]
class SlackRecordTest extends TestCase
{
public static function dataGetAttachmentColor()
@@ -33,10 +33,7 @@ class SlackRecordTest extends TestCase
];
}
/**
* @dataProvider dataGetAttachmentColor
* @covers ::getAttachmentColor
*/
#[DataProvider('dataGetAttachmentColor')]
public function testGetAttachmentColor(Level $logLevel, string $expectedColour)
{
$slackRecord = new SlackRecord();
@@ -78,9 +75,7 @@ class SlackRecordTest extends TestCase
];
}
/**
* @dataProvider dataStringify
*/
#[DataProvider('dataStringify')]
public function testStringify($fields, $expectedResult)
{
$slackRecord = new SlackRecord(
@@ -162,17 +157,17 @@ class SlackRecordTest extends TestCase
$formatter
->expects($this->any())
->method('format')
->will($this->returnCallback(function ($record) {
->willReturnCallback(function ($record) {
return $record->message . 'test';
}));
});
$formatter2 = $this->createMock('Monolog\\Formatter\\FormatterInterface');
$formatter2
->expects($this->any())
->method('format')
->will($this->returnCallback(function ($record) {
->willReturnCallback(function ($record) {
return $record->message . 'test1';
}));
});
$message = 'Test message';
$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\Formatter\LineFormatter;
use Monolog\Handler\Slack\SlackRecord;
use PHPUnit\Framework\Attributes\DataProvider;
/**
* @author Greg Kedzierski <greg@gregkedzierski.com>
@@ -93,9 +94,7 @@ class SlackHandlerTest extends TestCase
$this->assertMatchesRegularExpression('/icon_emoji=%3Aalien%3A/', $content);
}
/**
* @dataProvider provideLevelColors
*/
#[DataProvider('provideLevelColors')]
public function testWriteContentWithColors($level, $expectedColor)
{
$this->createHandler();
@@ -145,13 +144,12 @@ class SlackHandlerTest extends TestCase
$this->handler->expects($this->any())
->method('fsockopen')
->will($this->returnValue($this->res));
->willReturn($this->res);
$this->handler->expects($this->any())
->method('streamSetTimeout')
->will($this->returnValue(true));
->willReturn(true);
$this->handler->expects($this->any())
->method('closeSocket')
->will($this->returnValue(true));
->method('closeSocket');
$this->handler->setFormatter($this->getIdentityFormatter());
}

View File

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

View File

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

View File

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

View File

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