Test Failed
Push — master ( 322b96...cb950d )
by Nelson
03:16
created

testPerformsConversionToString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP: Nelson Martell Library file
4
 *
5
 * Copyright © 2019 Nelson Martell (http://nelson6e65.github.io)
6
 *
7
 * Licensed under The MIT License (MIT)
8
 * For full copyright and license information, please see the LICENSE
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @copyright 2019 Nelson Martell
12
 * @link      http://nelson6e65.github.io/php_nml/
13
 * @since     1.0.0
14
 * @license   http://www.opensource.org/licenses/mit-license.php The MIT License (MIT)
15
 * */
16
17
namespace NelsonMartell\Test\Helpers;
18
19
use ReflectionClass;
20
21
use NelsonMartell\Extensions\Text;
22
23
use NelsonMartell\IConvertibleToString;
24
25
/**
26
 * Test helper for classes implementing {@see IConvertibleToString} interface.
27
 *
28
 * @author Nelson Martell <[email protected]>
29
 * @since 1.0.0
30
 * */
31
trait ImplementsIConvertibleToString
32
{
33
    /**
34
     * @return string
35
     */
36
    abstract public function getTargetClassName() : string;
37
38
    /**
39
     * @return array
40
     */
41
    abstract public function toStringProvider() : array;
42
43
    /**
44
     *
45
     */
46
    public function testImplementsIConvertibleToString() : void
47
    {
48
        $class = new ReflectionClass($this->getTargetClassName());
49
50
        $message = Text::format(
51
            '"{0}" do not implements "{1}" interface.',
52
            $this->getTargetClassName(),
53
            IConvertibleToString::class
54
        );
55
56
        $this->assertContains(
0 ignored issues
show
Bug introduced by
It seems like assertContains() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        $this->/** @scrutinizer ignore-call */ 
57
               assertContains(
Loading history...
57
            IConvertibleToString::class,
58
            $class->getInterfaceNames(),
59
            $message
60
        );
61
    }
62
63
    /**
64
     * @covers ::toString
65
     * @covers ::__toString
66
     * @dataProvider toStringProvider
67
     *
68
     * @param string                $expected
69
     * @param IConvertibleToString  $obj
70
     *
71
     * @see IConvertibleToString::toString()
72
     * @see IConvertibleToString::__toString()
73
     */
74
    public function testPerformsConversionToString(string $expected, IConvertibleToString $obj): void
75
    {
76
        $this->assertSame($expected, $obj->toString(), 'Failed explicit conversion to string');
0 ignored issues
show
Bug introduced by
It seems like assertSame() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

76
        $this->/** @scrutinizer ignore-call */ 
77
               assertSame($expected, $obj->toString(), 'Failed explicit conversion to string');
Loading history...
77
78
        $this->assertSame($expected, $obj.'', 'Failed implicit conversion to string');
79
    }
80
}
81