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

Add property types to all properties where possible

This commit is contained in:
Jordi Boggiano
2022-04-21 21:58:19 +02:00
parent 6634bd9b79
commit 0dac87975c
36 changed files with 201 additions and 250 deletions

View File

@@ -16,7 +16,7 @@ use Monolog\Level;
class BufferHandlerTest extends TestCase
{
private $shutdownCheckHandler;
private TestHandler $shutdownCheckHandler;
/**
* @covers Monolog\Handler\BufferHandler::__construct

View File

@@ -134,7 +134,7 @@ class ChromePHPHandlerTest extends TestCase
class TestChromePHPHandler extends ChromePHPHandler
{
protected $headers = [];
protected array $headers = [];
public static function resetStatic(): void
{

View File

@@ -11,17 +11,19 @@
namespace Monolog\Handler;
use Aws\DynamoDb\DynamoDbClient;
use Monolog\Test\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
class DynamoDbHandlerTest extends TestCase
{
private $client;
private DynamoDbClient&MockObject $client;
private $isV3;
private bool $isV3;
public function setUp(): void
{
if (!class_exists('Aws\DynamoDb\DynamoDbClient')) {
if (!class_exists(DynamoDbClient::class)) {
$this->markTestSkipped('aws/aws-sdk-php not installed');
}
@@ -29,13 +31,13 @@ class DynamoDbHandlerTest extends TestCase
$implementedMethods = ['__call'];
$absentMethods = [];
if (method_exists('Aws\DynamoDb\DynamoDbClient', 'formatAttributes')) {
if (method_exists(DynamoDbClient::class, 'formatAttributes')) {
$implementedMethods[] = 'formatAttributes';
} else {
$absentMethods[] = 'formatAttributes';
}
$clientMockBuilder = $this->getMockBuilder('Aws\DynamoDb\DynamoDbClient')
$clientMockBuilder = $this->getMockBuilder(DynamoDbClient::class)
->onlyMethods($implementedMethods)
->disableOriginalConstructor();
if ($absentMethods) {
@@ -45,16 +47,6 @@ class DynamoDbHandlerTest extends TestCase
$this->client = $clientMockBuilder->getMock();
}
public function testConstruct()
{
$this->assertInstanceOf('Monolog\Handler\DynamoDbHandler', new DynamoDbHandler($this->client, 'foo'));
}
public function testInterface()
{
$this->assertInstanceOf('Monolog\Handler\HandlerInterface', new DynamoDbHandler($this->client, 'foo'));
}
public function testGetFormatter()
{
$handler = new DynamoDbHandler($this->client, 'foo');

View File

@@ -75,7 +75,7 @@ class FirePHPHandlerTest extends TestCase
class TestFirePHPHandler extends FirePHPHandler
{
protected $headers = [];
protected array $headers = [];
public static function resetStatic(): void
{

View File

@@ -12,6 +12,7 @@
namespace Monolog\Handler;
use Monolog\Test\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
/**
* @author Alexey Karapetov <alexey@karapetov.com>
@@ -20,12 +21,12 @@ class HandlerWrapperTest extends TestCase
{
private HandlerWrapper $wrapper;
private $handler;
private HandlerInterface&MockObject $handler;
public function setUp(): void
{
parent::setUp();
$this->handler = $this->createMock('Monolog\\Handler\\HandlerInterface');
$this->handler = $this->createMock(HandlerInterface::class);
$this->wrapper = new HandlerWrapper($this->handler);
}

View File

@@ -28,12 +28,9 @@ use PHPUnit\Framework\MockObject\MockObject;
*/
class PHPConsoleHandlerTest extends TestCase
{
/** @var Connector|MockObject */
protected $connector;
/** @var DebugDispatcher|MockObject */
protected $debugDispatcher;
/** @var ErrorDispatcher|MockObject */
protected $errorDispatcher;
protected Connector&MockObject $connector;
protected DebugDispatcher&MockObject $debugDispatcher;
protected ErrorDispatcher&MockObject $errorDispatcher;
protected function setUp(): void
{

View File

@@ -13,6 +13,7 @@ namespace Monolog\Handler;
use Monolog\Test\TestCase;
use Monolog\Level;
use PHPUnit\Framework\MockObject\MockObject;
/**
* Almost all examples (expected header, titles, messages) taken from
@@ -22,8 +23,9 @@ use Monolog\Level;
*/
class PushoverHandlerTest extends TestCase
{
/** @var resource */
private $res;
private $handler;
private PushoverHandler&MockObject $handler;
public function testWriteHeader()
{
@@ -116,7 +118,7 @@ class PushoverHandlerTest extends TestCase
{
$constructorArgs = [$token, $user, $title];
$this->res = fopen('php://memory', 'a');
$this->handler = $this->getMockBuilder('Monolog\Handler\PushoverHandler')
$this->handler = $this->getMockBuilder(PushoverHandler::class)
->setConstructorArgs($constructorArgs)
->onlyMethods(['fsockopen', 'streamSetTimeout', 'closeSocket'])
->getMock();

View File

@@ -17,13 +17,6 @@ use Monolog\Formatter\LineFormatter;
class RedisHandlerTest extends TestCase
{
public function testConstructorShouldThrowExceptionForInvalidRedis()
{
$this->expectException(\InvalidArgumentException::class);
new RedisHandler(new \stdClass(), 'key');
}
public function testConstructorShouldWorkWithPredis()
{
$redis = $this->createMock('Predis\Client');

View File

@@ -19,13 +19,6 @@ use Monolog\Formatter\LineFormatter;
class RedisPubSubHandlerTest extends TestCase
{
public function testConstructorShouldThrowExceptionForInvalidRedis()
{
$this->expectException(\InvalidArgumentException::class);
new RedisPubSubHandler(new \stdClass(), 'key');
}
public function testConstructorShouldWorkWithPredis()
{
$redis = $this->createMock('Predis\Client');

View File

@@ -19,7 +19,7 @@ use Monolog\Test\TestCase;
*/
class RotatingFileHandlerTest extends TestCase
{
private $lastError;
private array|null $lastError = null;
public function setUp(): void
{

View File

@@ -20,10 +20,7 @@ use PHPUnit\Framework\MockObject\MockObject;
*/
class SocketHandlerTest extends TestCase
{
/**
* @var \Monolog\Handler\SocketHandler|MockObject
*/
private $handler;
private SocketHandler&MockObject $handler;
/**
* @var resource
@@ -34,58 +31,58 @@ class SocketHandlerTest extends TestCase
{
$this->expectException(\UnexpectedValueException::class);
$this->createHandler('garbage://here');
$this->writeRecord('data');
$handler = $this->createHandler('garbage://here');
$handler->handle($this->getRecord(Level::Warning, 'data'));
}
public function testBadConnectionTimeout()
{
$this->expectException(\InvalidArgumentException::class);
$this->createHandler('localhost:1234');
$this->handler->setConnectionTimeout(-1);
$handler = $this->createHandler('localhost:1234');
$handler->setConnectionTimeout(-1);
}
public function testSetConnectionTimeout()
{
$this->createHandler('localhost:1234');
$this->handler->setConnectionTimeout(10.1);
$this->assertEquals(10.1, $this->handler->getConnectionTimeout());
$handler = $this->createHandler('localhost:1234');
$handler->setConnectionTimeout(10.1);
$this->assertEquals(10.1, $handler->getConnectionTimeout());
}
public function testBadTimeout()
{
$this->expectException(\InvalidArgumentException::class);
$this->createHandler('localhost:1234');
$this->handler->setTimeout(-1);
$handler = $this->createHandler('localhost:1234');
$handler->setTimeout(-1);
}
public function testSetTimeout()
{
$this->createHandler('localhost:1234');
$this->handler->setTimeout(10.25);
$this->assertEquals(10.25, $this->handler->getTimeout());
$handler = $this->createHandler('localhost:1234');
$handler->setTimeout(10.25);
$this->assertEquals(10.25, $handler->getTimeout());
}
public function testSetWritingTimeout()
{
$this->createHandler('localhost:1234');
$this->handler->setWritingTimeout(10.25);
$this->assertEquals(10.25, $this->handler->getWritingTimeout());
$handler = $this->createHandler('localhost:1234');
$handler->setWritingTimeout(10.25);
$this->assertEquals(10.25, $handler->getWritingTimeout());
}
public function testSetChunkSize()
{
$this->createHandler('localhost:1234');
$this->handler->setChunkSize(1025);
$this->assertEquals(1025, $this->handler->getChunkSize());
$handler = $this->createHandler('localhost:1234');
$handler->setChunkSize(1025);
$this->assertEquals(1025, $handler->getChunkSize());
}
public function testSetConnectionString()
{
$this->createHandler('tcp://localhost:9090');
$this->assertEquals('tcp://localhost:9090', $this->handler->getConnectionString());
$handler = $this->createHandler('tcp://localhost:9090');
$this->assertEquals('tcp://localhost:9090', $handler->getConnectionString());
}
public function testExceptionIsThrownOnFsockopenError()
@@ -277,10 +274,12 @@ class SocketHandlerTest extends TestCase
$this->writeRecord('Hello world');
}
private function createHandler($connectionString)
private function createHandler(string $connectionString): SocketHandler
{
$this->handler = new SocketHandler($connectionString);
$this->handler->setFormatter($this->getIdentityFormatter());
$handler = new SocketHandler($connectionString);
$handler->setFormatter($this->getIdentityFormatter());
return $handler;
}
private function writeRecord($string)

View File

@@ -15,8 +15,6 @@ use Monolog\Test\TestCase;
class ZendMonitorHandlerTest extends TestCase
{
protected $zendMonitorHandler;
public function setUp(): void
{
if (!function_exists('zend_monitor_custom_event')) {