25 use Wikimedia\TestingAccessWrapper;
33 if ( !class_exists(
'Monolog\Handler\AbstractProcessingHandler' )
34 || !class_exists(
'Kafka\Produce' )
36 $this->markTestSkipped(
'Monolog and Kafka are required for the KafkaHandlerTest' );
44 [ [],
'monolog_foo' ],
45 [ [
'alias' => [
'foo' =>
'bar' ] ],
'bar' ]
53 $produce = $this->getMockBuilder(
'Kafka\Produce' )
54 ->disableOriginalConstructor()
56 $produce->expects( $this->
any() )
57 ->method(
'getAvailablePartitions' )
58 ->will( $this->returnValue( [
'A' ] ) );
59 $produce->expects( $this->once() )
60 ->method(
'setMessages' )
62 $produce->expects( $this->
any() )
64 ->will( $this->returnValue(
true ) );
69 'level' => Logger::EMERGENCY,
80 [ [
'swallowExceptions' =>
false ],
true ],
82 [ [
'swallowExceptions' =>
true ],
false ],
90 $produce = $this->getMockBuilder(
'Kafka\Produce' )
91 ->disableOriginalConstructor()
93 $produce->expects( $this->
any() )
94 ->method(
'getAvailablePartitions' )
95 ->will( $this->throwException(
new \Kafka\Exception ) );
96 $produce->expects( $this->
any() )
98 ->will( $this->returnValue(
true ) );
100 if ( $expectException ) {
101 $this->setExpectedException(
'Kafka\Exception' );
107 'level' => Logger::EMERGENCY,
112 if ( !$expectException ) {
113 $this->assertTrue(
true,
'no exception was thrown' );
121 $produce = $this->getMockBuilder(
'Kafka\Produce' )
122 ->disableOriginalConstructor()
124 $produce->expects( $this->
any() )
125 ->method(
'getAvailablePartitions' )
126 ->will( $this->returnValue( [
'A' ] ) );
127 $produce->expects( $this->
any() )
129 ->will( $this->throwException(
new \Kafka\Exception ) );
131 if ( $expectException ) {
132 $this->setExpectedException(
'Kafka\Exception' );
138 'level' => Logger::EMERGENCY,
143 if ( !$expectException ) {
144 $this->assertTrue(
true,
'no exception was thrown' );
149 $produce = $this->getMockBuilder(
'Kafka\Produce' )
150 ->disableOriginalConstructor()
152 $produce->expects( $this->
any() )
153 ->method(
'getAvailablePartitions' )
154 ->will( $this->returnValue( [
'A' ] ) );
155 $mockMethod = $produce->expects( $this->exactly( 2 ) )
156 ->method(
'setMessages' );
157 $produce->expects( $this->
any() )
159 ->will( $this->returnValue(
true ) );
161 $matcher = TestingAccessWrapper::newFromObject( $mockMethod )->matcher;
162 TestingAccessWrapper::newFromObject( $matcher )->parametersMatcher =
163 new \PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters( [
169 $formatter->expects( $this->
any() )
171 ->will( $this->onConsecutiveCalls(
'words',
null,
'lines' ) );
174 $handler->setFormatter( $formatter );
175 for ( $i = 0; $i < 3; ++$i ) {
178 'level' => Logger::EMERGENCY,
186 $produce = $this->getMockBuilder(
'Kafka\Produce' )
187 ->disableOriginalConstructor()
189 $produce->expects( $this->
any() )
190 ->method(
'getAvailablePartitions' )
191 ->will( $this->returnValue( [
'A' ] ) );
192 $produce->expects( $this->once() )
193 ->method(
'setMessages' )
195 $produce->expects( $this->
any() )
197 ->will( $this->returnValue(
true ) );
200 $formatter->expects( $this->
any() )
202 ->will( $this->onConsecutiveCalls(
'words',
null,
'lines' ) );
205 $handler->setFormatter( $formatter );
209 'level' => Logger::EMERGENCY,
215 'level' => Logger::EMERGENCY,
221 'level' => Logger::EMERGENCY,