63 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
declare(strict_types=1);
 | 
						|
 | 
						|
namespace App\Tests\Unit\Service\Remote;
 | 
						|
 | 
						|
use App\Service\Remote\RetryingClientTrait;
 | 
						|
use App\Service\Remote\RetryingFailClientTrait;
 | 
						|
use App\Tests\Common\LoggerTrait;
 | 
						|
use PHPUnit\Framework\TestCase;
 | 
						|
 | 
						|
class RetryingClientTraitTest extends TestCase
 | 
						|
{
 | 
						|
    use LoggerTrait;
 | 
						|
 | 
						|
    private int $callCount = 0;
 | 
						|
 | 
						|
    protected function setUp(): void
 | 
						|
    {
 | 
						|
        parent::setUp(); // TODO: Change the autogenerated stub
 | 
						|
        $this->callCount = 0;
 | 
						|
    }
 | 
						|
 | 
						|
    public function testSuccess(): void
 | 
						|
    {
 | 
						|
        $trait = new class {
 | 
						|
            use RetryingClientTrait {
 | 
						|
                retryingFailRequest as public; // make the method public
 | 
						|
            }
 | 
						|
        };
 | 
						|
 | 
						|
 | 
						|
        $result = $trait->retryingFailRequest(2, 0, [\RuntimeException::class], $this->getLogger(), function () {
 | 
						|
            $this->callCount = $this->callCount + 1;
 | 
						|
            return 'foo';
 | 
						|
        });
 | 
						|
 | 
						|
        $this->assertEquals(1, $this->callCount);
 | 
						|
        $this->assertEquals('foo', $result);
 | 
						|
    }
 | 
						|
    public function testRetyingFail(): void
 | 
						|
    {
 | 
						|
        $trait = new class {
 | 
						|
            use RetryingClientTrait {
 | 
						|
                retryingFailRequest as public; // make the method public
 | 
						|
            }
 | 
						|
        };
 | 
						|
 | 
						|
 | 
						|
        try {
 | 
						|
            $trait->retryingFailRequest(2, 0, [\RuntimeException::class], $this->getLogger(), function () {
 | 
						|
                $this->callCount = $this->callCount + 1;
 | 
						|
                throw new \RuntimeException("test");
 | 
						|
            });
 | 
						|
        } catch (\RuntimeException) {
 | 
						|
            // do nothing
 | 
						|
        }
 | 
						|
 | 
						|
        $this->assertEquals(3, $this->callCount);
 | 
						|
    }
 | 
						|
    // extra attributes muzeme safe ignorovat
 | 
						|
}
 |