Passed
Pull Request — master (#405)
by Kirill
08:21 queued 04:03
created

TestCase   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 9
c 3
b 0
f 0
dl 0
loc 38
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A classNamespace() 0 3 1
A newAnnotation() 0 9 2
A iterableToArray() 0 7 2
1
<?php
2
3
/**
4
 * This file is part of Spiral Framework package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Attributes;
13
14
use PHPUnit\Framework\TestCase as BaseTestCase;
15
16
/**
17
 * @group unit
18
 */
19
abstract class TestCase extends BaseTestCase
20
{
21
    /**
22
     * @param \Traversable|array $iterable
23
     * @return array
24
     */
25
    protected function iterableToArray(iterable $iterable): array
26
    {
27
        if ($iterable instanceof \Traversable) {
28
            return \iterator_to_array($iterable, false);
29
        }
30
31
        return $iterable;
32
    }
33
34
    /**
35
     * @param string $class
36
     * @return string
37
     */
38
    protected function classNamespace(string $class): string
39
    {
40
        return \dirname(\str_replace('\\', \DIRECTORY_SEPARATOR, $class));
41
    }
42
43
    /**
44
     * @param string $class
45
     * @param array $fields
46
     * @return object
47
     */
48
    protected function newAnnotation(string $class, array $fields = []): object
49
    {
50
        $instance = new $class();
51
52
        foreach ($fields as $field => $value) {
53
            $instance->$field = $value;
54
        }
55
56
        return $instance;
57
    }
58
}
59