PaymentServiceMapTest::testEnabledForSend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12
ccs 11
cts 11
cp 1
crap 1
rs 9.9332
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/money-interop project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
 namespace Daikon\Tests\Money\Service;
10
11
use Daikon\Money\Service\PaymentServiceInterface;
12
use Daikon\Money\Service\PaymentServiceMap;
13
use Daikon\Money\ValueObject\Money;
14
use PHPUnit\Framework\TestCase;
15
16
final class PaymentServiceMapTest extends TestCase
17
{
18 1
    public function testConstruct(): void
19
    {
20 1
        $service = $this->createMock(PaymentServiceInterface::class);
21 1
        $unwrappedMap = (new PaymentServiceMap(['a' => $service]))->unwrap();
22 1
        $this->assertNotSame($service, $unwrappedMap['a']);
23 1
        $this->assertEquals($service, $unwrappedMap['a']);
24 1
    }
25
26 1
    public function testEnabledForRequest(): void
27
    {
28 1
        $unavailable = $this->createMock(PaymentServiceInterface::class);
29 1
        $unavailable->expects($this->once())->method('canRequest')->willReturn(false);
30 1
        $availableService = $this->createMock(PaymentServiceInterface::class);
31 1
        $availableService->expects($this->once())->method('canRequest')->willReturn(true);
32 1
        $filteredMap = (new PaymentServiceMap(['a' => $unavailable, 'b' => $availableService]))
33 1
            ->availableForRequest(Money::zero('X'));
34 1
        $unwrappedMap = $filteredMap->unwrap();
35 1
        $this->assertCount(1, $filteredMap);
36 1
        $this->assertNotSame($availableService, $unwrappedMap['b']);
37 1
        $this->assertEquals($availableService, $unwrappedMap['b']);
38 1
    }
39
40 1
    public function testEnabledForSend(): void
41
    {
42 1
        $unavailable = $this->createMock(PaymentServiceInterface::class);
43 1
        $unavailable->expects($this->once())->method('canSend')->willReturn(false);
44 1
        $availableService = $this->createMock(PaymentServiceInterface::class);
45 1
        $availableService->expects($this->once())->method('canSend')->willReturn(true);
46 1
        $filteredMap = (new PaymentServiceMap(['a' => $unavailable, 'b' => $availableService]))
47 1
            ->availableForSend(Money::zero('X'));
48 1
        $unwrappedMap = $filteredMap->unwrap();
49 1
        $this->assertCount(1, $filteredMap);
50 1
        $this->assertNotSame($availableService, $unwrappedMap['b']);
51 1
        $this->assertEquals($availableService, $unwrappedMap['b']);
52 1
    }
53
}
54