it_creates_a_default_circuit_breaker()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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