diff --git a/src/Gelf/Publisher.php b/src/Gelf/Publisher.php index 92e2766..e548744 100644 --- a/src/Gelf/Publisher.php +++ b/src/Gelf/Publisher.php @@ -1,4 +1,5 @@ transports = new Set(); $this->messageValidator = $messageValidator @@ -54,11 +45,9 @@ public function __construct( } /** - * Publish a message over all defined transports - * - * @param MessageInterface $message + * @inheritDoc */ - public function publish(MessageInterface $message) + public function publish(MessageInterface $message): void { if (count($this->transports) == 0) { throw new RuntimeException( @@ -78,11 +67,9 @@ public function publish(MessageInterface $message) } /** - * Adds a transport to the publisher. - * - * @param TransportInterface $transport + * Adds a transport object to the publisher. */ - public function addTransport(TransportInterface $transport) + public function addTransport(TransportInterface $transport): void { $this->transports->attach($transport); } @@ -92,17 +79,15 @@ public function addTransport(TransportInterface $transport) * * @return TransportInterface[] */ - public function getTransports() + public function getTransports(): array { return iterator_to_array($this->transports); } /** * Returns the current message validator. - * - * @return MessageValidatorInterface */ - public function getMessageValidator() + public function getMessageValidator(): MessageValidatorInterface { return $this->messageValidator; } diff --git a/src/Gelf/PublisherInterface.php b/src/Gelf/PublisherInterface.php index 4a68818..17a67d8 100644 --- a/src/Gelf/PublisherInterface.php +++ b/src/Gelf/PublisherInterface.php @@ -1,4 +1,5 @@ transportA = $this->createMock('Gelf\Transport\TransportInterface'); - $this->transportB = $this->createMock('Gelf\Transport\TransportInterface'); + $this->transportA = $this->createMock(TransportInterface::class); + $this->transportB = $this->createMock(TransportInterface::class); $this->messageValidator = - $this->createMock('Gelf\MessageValidatorInterface'); - $this->message = $this->createMock('Gelf\MessageInterface'); + $this->createMock(MessageValidatorInterface::class); + $this->message = $this->createMock(MessageInterface::class); $this->publisher = new Publisher( $this->transportA, @@ -37,7 +42,7 @@ public function setUp() ); } - public function testPublish() + public function testPublish(): void { $this->transportA->expects($this->once()) ->method('send') @@ -50,11 +55,9 @@ public function testPublish() $this->publisher->publish($this->message); } - /** - * @expectedException RuntimeException - */ - public function testPublishErrorOnInvalid() + public function testPublishErrorOnInvalid(): void { + self::expectException(RuntimeException::class); $this->messageValidator->expects($this->once()) ->method('validate') ->will($this->returnValue(false)); @@ -62,18 +65,16 @@ public function testPublishErrorOnInvalid() $this->publisher->publish($this->message); } - /** - * @expectedException RuntimeException - */ - public function testMissingTransport() + public function testMissingTransport(): void { + self::expectException(RuntimeException::class); $publisher = new Publisher(null, $this->messageValidator); - $this->assertCount(0, $publisher->getTransports()); + self::assertCount(0, $publisher->getTransports()); $publisher->publish($this->message); } - public function testMultipleTransports() + public function testMultipleTransports(): void { $pub = $this->publisher; $pub->addTransport($this->transportB); @@ -92,27 +93,18 @@ public function testMultipleTransports() $pub->publish($this->message); } - public function testGetTransports() + public function testGetTransports(): void { $pub = new Publisher(null, $this->messageValidator); - $this->assertCount(0, $pub->getTransports()); + self::assertCount(0, $pub->getTransports()); $pub->addTransport($this->transportA); - $this->assertCount(1, $pub->getTransports()); + self::assertCount(1, $pub->getTransports()); $pub->addTransport($this->transportB); - $this->assertCount(2, $pub->getTransports()); + self::assertCount(2, $pub->getTransports()); $pub->addTransport($this->transportA); - $this->assertCount(2, $pub->getTransports()); - } - - public function testInitWithDefaultValidator() - { - $pub = new Publisher(); - $this->assertInstanceOf( - 'Gelf\MessageValidatorInterface', - $pub->getMessageValidator() - ); + self::assertCount(2, $pub->getTransports()); } }