Completed
Push — master ( 0cba44...be5c0d )
by Jorge
01:37
created

FactoryTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A it_creates_a_default_circuit_breaker() 0 22 1
1
<?php
2
3
namespace JVelasco\CircuitBreaker;
4
5
use PHPUnit\Framework\Assert;
6
use PHPUnit\Framework\TestCase;
7
8
final class FactoryTest extends TestCase
9
{
10
    /** @test */
11
    public function it_creates_a_default_circuit_breaker()
12
    {
13
        $maxFailures = 1;
14
        $circuitBreaker = Factory::default($maxFailures);
15
16
        $this->assertTrue(
17
            $circuitBreaker->isAvailable("host:port"),
18
            "service is available until reach the number of failures"
19
        );
20
21
        $circuitBreaker->reportFailure("host:port");
22
23
        $this->assertFalse(
24
            $circuitBreaker->isAvailable("host:port"),
25
            "after reach the number of failures, the service is not available"
26
        );
27
28
        $circuitBreaker->reportSuccess("host:port");
29
30
        $this->assertTrue(
31
            $circuitBreaker->isAvailable("host:port"),
32
            "successes decrease the number of failures, eventually closing the circuit"
33
        );
34
35
    }
36
}
37