Completed
Push — master ( ecffef...7362a8 )
by Derek
02:15
created

Assertions::assertSameAsToString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 2
1
<?php
2
namespace Subreality\Dilmun\Anshar\PhpUnit;
3
4
use PHPUnit_Framework_TestCase as TestCase;
5
6
/**
7
 * Class Assertions
8
 * @package Subreality\Dilmun\Anshar\PhpUnit
9
 */
10
class Assertions
11
{
12
    /** @var  TestCase */
13
    public static $test_case;
14
15
    /**
16
     * Asserts that the given expected string is the same as the string returned by an object instance's __toString
17
     * magic method.
18
     *
19
     * @throws \PHPUnit_Framework_ExpectationFailedException provided an instance of an object with no __toString
20
     * method.
21
     *
22
     * @param string $expected
23
     * @param object $test_instance
24
     */
25 10
    public static function assertSameAsToString($expected, $test_instance)
26
    {
27
        try {
28 10
            $actual = (string) $test_instance;
29 9
            TestCase::assertSame($expected, $actual);
30 10
        } catch (\PHPUnit_Framework_Error $error) {
31 1
            throw new \PHPUnit_Framework_ExpectationFailedException("Cannot convert object to string");
32
        }
33 8
    }
34
}
35