@@ -368,6 +368,9 @@ public function testBeginTransactionConsecutiveSuccess(): void
368
368
public function testBeginTransactionWithRetriableError (): void
369
369
{
370
370
self ::expectException (KafkaProducerTransactionRetryException::class);
371
+ self ::expectExceptionMessage (
372
+ sprintf (KafkaProducerTransactionRetryException::RETRIABLE_TRANSACTION_EXCEPTION_MESSAGE , '' )
373
+ );
371
374
372
375
$ errorMock = $ this ->createMock (SkcErrorException::class);
373
376
$ errorMock ->expects (self ::once ())->method ('isRetriable ' )->willReturn (true );
@@ -389,6 +392,9 @@ public function testBeginTransactionWithRetriableError(): void
389
392
public function testBeginTransactionWithAbortError (): void
390
393
{
391
394
self ::expectException (KafkaProducerTransactionAbortException::class);
395
+ self ::expectExceptionMessage (
396
+ sprintf (KafkaProducerTransactionAbortException::TRANSACTION_REQUIRES_ABORT_EXCEPTION_MESSAGE , '' )
397
+ );
392
398
393
399
$ errorMock = $ this ->createMock (SkcErrorException::class);
394
400
$ errorMock ->expects (self ::once ())->method ('isRetriable ' )->willReturn (false );
@@ -411,6 +417,9 @@ public function testBeginTransactionWithAbortError(): void
411
417
public function testBeginTransactionWithFatalError (): void
412
418
{
413
419
self ::expectException (KafkaProducerTransactionFatalException::class);
420
+ self ::expectExceptionMessage (
421
+ sprintf (KafkaProducerTransactionFatalException::FATAL_TRANSACTION_EXCEPTION_MESSAGE , '' )
422
+ );
414
423
415
424
$ errorMock = $ this ->createMock (SkcErrorException::class);
416
425
$ errorMock ->expects (self ::once ())->method ('isRetriable ' )->willReturn (false );
@@ -435,6 +444,9 @@ public function testBeginTransactionWithFatalErrorWillTriggerInit(): void
435
444
$ firstExceptionCaught = false ;
436
445
437
446
self ::expectException (KafkaProducerTransactionFatalException::class);
447
+ self ::expectExceptionMessage (
448
+ sprintf (KafkaProducerTransactionFatalException::FATAL_TRANSACTION_EXCEPTION_MESSAGE , '' )
449
+ );
438
450
439
451
$ errorMock = $ this ->createMock (SkcErrorException::class);
440
452
$ errorMock ->expects (self ::exactly (2 ))->method ('isRetriable ' )->willReturn (false );
@@ -476,7 +488,9 @@ public function testAbortTransactionSuccess(): void
476
488
public function testAbortTransactionFailure (): void
477
489
{
478
490
self ::expectException (KafkaProducerTransactionRetryException::class);
479
- self ::expectExceptionMessage (KafkaProducerTransactionRetryException::RETRIABLE_TRANSACTION_EXCEPTION_MESSAGE );
491
+ self ::expectExceptionMessage (
492
+ sprintf (KafkaProducerTransactionRetryException::RETRIABLE_TRANSACTION_EXCEPTION_MESSAGE , 'test ' )
493
+ );
480
494
481
495
$ exception = new SkcErrorException ('test ' , 1 , 'some failure ' , false , true , false );
482
496
@@ -507,7 +521,9 @@ public function testCommitTransactionSuccess(): void
507
521
public function testCommitTransactionFailure (): void
508
522
{
509
523
self ::expectException (KafkaProducerTransactionRetryException::class);
510
- self ::expectExceptionMessage (KafkaProducerTransactionRetryException::RETRIABLE_TRANSACTION_EXCEPTION_MESSAGE );
524
+ self ::expectExceptionMessage (
525
+ sprintf (KafkaProducerTransactionRetryException::RETRIABLE_TRANSACTION_EXCEPTION_MESSAGE , 'test ' )
526
+ );
511
527
512
528
$ exception = new SkcErrorException ('test ' , 1 , 'some failure ' , false , true , false );
513
529
@@ -519,4 +535,25 @@ public function testCommitTransactionFailure(): void
519
535
520
536
$ this ->kafkaProducer ->commitTransaction (10000 );
521
537
}
538
+
539
+ /**
540
+ * @return void
541
+ */
542
+ public function testCommitTransactionFailurePreviousException (): void
543
+ {
544
+ $ exception = new SkcErrorException ('test ' , 1 , 'some failure ' , false , true , false );
545
+
546
+ $ this ->rdKafkaProducerMock
547
+ ->expects (self ::once ())
548
+ ->method ('commitTransaction ' )
549
+ ->with (10000 )
550
+ ->willThrowException ($ exception );
551
+
552
+ try {
553
+ $ this ->kafkaProducer ->commitTransaction (10000 );
554
+ } catch (KafkaProducerTransactionRetryException $ e ) {
555
+ self ::assertSame ($ exception , $ e ->getPrevious ());
556
+ }
557
+
558
+ }
522
559
}
0 commit comments