FactoryTest   A
last analyzed

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