Assert   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 16
dl 0
loc 34
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A assertConnectionWasUsed() 0 13 1
A __construct() 0 9 1
1
<?php
2
3
namespace PhpWinTools\WmiScripting\Testing\Support;
4
5
use PHPUnit\Framework\TestCase;
6
use PhpWinTools\WmiScripting\Configuration\Config;
7
use PhpWinTools\WmiScripting\Testing\CallStacks\ComCall;
8
use function PhpWinTools\WmiScripting\Support\connection;
9
use PhpWinTools\WmiScripting\Support\ApiObjects\SWbemLocator;
10
use PhpWinTools\WmiScripting\Testing\CallStacks\ComCallStack;
11
use PhpWinTools\WmiScripting\Testing\CallStacks\ComTraceSubject;
12
use PhpWinTools\WmiScripting\Testing\CallStacks\ApiObjectCallStack;
13
14
class Assert
15
{
16
    protected $testCase;
17
18
    protected $callStack;
19
20
    protected $apiCallStack;
21
22
    protected $config;
23
24 2
    public function __construct(TestCase $testCase)
25
    {
26 2
        $this->testCase = $testCase;
27
28 2
        $this->callStack = ComCallStack::instance();
29
30 2
        $this->apiCallStack = ApiObjectCallStack::instance();
31
32 2
        $this->config = Config::testInstance();
33 2
    }
34
35 2
    public function assertConnectionWasUsed($connection, string $message = null)
36
    {
37 2
        $connection = connection($connection, null, $this->config);
38
39
        /** @var ComTraceSubject $caller */
40
        $caller = $this->callStack->getStackCollection()->first(function (ComCall $call) {
41 2
            return $call->getCaller()->getClass() === SWbemLocator::class;
42 2
        })->getCaller();
43
44 2
        $this->testCase::assertEquals(
45 2
            $connection,
46 2
            $caller->getArguments()[0],
47 2
            $message ?? 'Expected connection was not used.'
48
        );
49 2
    }
50
}
51