Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of PHPUnit.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PHPUnit\Framework\MockObject;
11
 
12
use function call_user_func;
13
use function class_exists;
14
 
15
/**
16
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
17
 */
18
final class MockClass implements MockType
19
{
20
    /**
21
     * @var string
22
     */
23
    private $classCode;
24
 
25
    /**
26
     * @var class-string
27
     */
28
    private $mockName;
29
 
30
    /**
31
     * @var ConfigurableMethod[]
32
     */
33
    private $configurableMethods;
34
 
35
    /**
36
     * @psalm-param class-string $mockName
37
     */
38
    public function __construct(string $classCode, string $mockName, array $configurableMethods)
39
    {
40
        $this->classCode           = $classCode;
41
        $this->mockName            = $mockName;
42
        $this->configurableMethods = $configurableMethods;
43
    }
44
 
45
    /**
46
     * @psalm-return class-string
47
     */
48
    public function generate(): string
49
    {
50
        if (!class_exists($this->mockName, false)) {
51
            eval($this->classCode);
52
 
53
            call_user_func(
54
                [
55
                    $this->mockName,
56
                    '__phpunit_initConfigurableMethods',
57
                ],
58
                ...$this->configurableMethods
59
            );
60
        }
61
 
62
        return $this->mockName;
63
    }
64
 
65
    public function getClassCode(): string
66
    {
67
        return $this->classCode;
68
    }
69
}