UnitTester   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dumpFile() 0 5 1
A assertException() 0 29 5
1
<?php
2
3
use PHPUnit\Framework\Assert;
4
use PHPUnit\Framework\Constraint\Exception as ConstraintException;
5
use PHPUnit\Framework\Constraint\ExceptionMessage as ConstraintExceptionMessage;
6
7
/**
8
 * Inherited Methods
9
 * @method void wantToTest($text)
10
 * @method void wantTo($text)
11
 * @method void execute($callable)
12
 * @method void expectTo($prediction)
13
 * @method void expect($prediction)
14
 * @method void amGoingTo($argumentation)
15
 * @method void am($role)
16
 * @method void lookForwardTo($achieveValue)
17
 * @method void comment($description)
18
 * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
19
 *
20
 * @SuppressWarnings(PHPMD)
21
 */
22
class UnitTester extends \Codeception\Actor
23
{
24
    use _generated\UnitTesterActions;
0 ignored issues
show
Bug introduced by
The type _generated\UnitTesterActions was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
26
    /**
27
     * @param string $contents
28
     */
29
    public function dumpFile($contents)
30
    {
31
        $name = preg_replace('/[^\w\d]/s', '-', $this->scenario->getFeature());
32
33
        file_put_contents(dirname(__DIR__) . "/_output/mail.{$name}.txt", $contents);
34
    }
35
36
    /**
37
     * @param string          $type
38
     * @param string|callable $message_or_function
39
     * @param callable|null   $function
40
     */
41
    public function assertException(string $type, $message_or_function, ?callable $function = null)
42
    {
43
        if (func_num_args() === 3) {
44
            $message = $message_or_function;
45
        } else { // 2 args
46
            $message = null;
47
            $function = $message_or_function;
48
        }
49
50
        $exception = null;
51
52
        try {
53
            call_user_func($function);
0 ignored issues
show
Bug introduced by
It seems like $function can also be of type null; however, parameter $callback of call_user_func() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

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

53
            call_user_func(/** @scrutinizer ignore-type */ $function);
Loading history...
54
        } catch (Exception $e) {
55
            $exception = $e;
56
        }
57
58
        $exception_type = $exception ? get_class($exception) : 'null';
59
60
        Assert::assertThat(
61
            $exception,
62
            new ConstraintException($type),
63
            $exception_type . " NOT EQUAL TO " . $type
64
        );
65
66
        if ($message !== null) {
67
            Assert::assertThat(
68
                $exception,
69
                new ConstraintExceptionMessage($message)
70
            );
71
        }
72
    }
73
}
74