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

it_creates_a_default_circuit_breaker()   A

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\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