Completed
Push — 6.0 ( bb666d...c1d13c )
by yun
05:54
created

TestTemplate::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace think\tests;
4
5
use Mockery\MockInterface;
6
use PHPUnit\Framework\TestCase;
7
use think\App;
8
use think\Config;
9
use think\Container;
10
use think\contract\TemplateHandlerInterface;
11
use think\View;
12
use Mockery as m;
13
14
class ViewTest extends TestCase
15
{
16
    /** @var App|MockInterface */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
17
    protected $app;
18
19
    /** @var View|MockInterface */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
20
    protected $view;
21
22
    /** @var Config|MockInterface */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
23
    protected $config;
24
25
    protected function tearDown(): void
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function tearDown()
Loading history...
26
    {
27
        m::close();
28
    }
29
30
    protected function setUp()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function setUp()
Loading history...
31
    {
32
        $this->app = m::mock(App::class)->makePartial();
33
        Container::setInstance($this->app);
34
35
        $this->app->shouldReceive('make')->with(App::class)->andReturn($this->app);
36
        $this->config = m::mock(Config::class)->makePartial();
37
        $this->app->shouldReceive('get')->with('config')->andReturn($this->config);
38
39
        $this->view = new View($this->app);
0 ignored issues
show
Bug introduced by
$this->app of type Mockery\Mock is incompatible with the type think\App expected by parameter $app of think\View::__construct(). ( Ignorable by Annotation )

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

39
        $this->view = new View(/** @scrutinizer ignore-type */ $this->app);
Loading history...
40
    }
41
42
    public function testAssignData()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function testAssignData()
Loading history...
43
    {
44
        $this->view->assign('foo', 'bar');
45
        $this->view->assign(['baz' => 'boom']);
46
        $this->view->qux = "corge";
0 ignored issues
show
Bug Best Practice introduced by
The property qux does not exist on think\View. Since you implemented __set, consider adding a @property annotation.
Loading history...
47
48
        $this->assertEquals('bar', $this->view->foo);
0 ignored issues
show
Bug Best Practice introduced by
The property foo does not exist on think\View. Since you implemented __get, consider adding a @property annotation.
Loading history...
49
        $this->assertEquals('boom', $this->view->baz);
0 ignored issues
show
Bug Best Practice introduced by
The property baz does not exist on think\View. Since you implemented __get, consider adding a @property annotation.
Loading history...
50
        $this->assertEquals('corge', $this->view->qux);
0 ignored issues
show
Bug Best Practice introduced by
The property qux does not exist on think\View. Since you implemented __get, consider adding a @property annotation.
Loading history...
51
        $this->assertTrue(isset($this->view->qux));
52
    }
53
54
    public function testRender()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function testRender()
Loading history...
55
    {
56
        $this->config->shouldReceive("get")->with("view.type", 'php')->andReturn(TestTemplate::class);
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on think\Config. ( 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->config->/** @scrutinizer ignore-call */ 
57
                       shouldReceive("get")->with("view.type", 'php')->andReturn(TestTemplate::class);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
58
        $this->view->filter(function ($content) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
59
            return $content;
60
        });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
61
62
        $this->assertEquals("fetch", $this->view->fetch('foo'));
63
        $this->assertEquals("display", $this->view->display('foo'));
64
    }
65
66
}
67
68
class TestTemplate implements TemplateHandlerInterface
69
{
70
71
    /**
72
     * 检测是否存在模板文件
73
     * @access public
74
     * @param string $template 模板文件或者模板规则
75
     * @return bool
76
     */
77
    public function exists(string $template): bool
78
    {
79
        return true;
80
    }
81
82
    /**
83
     * 渲染模板文件
84
     * @access public
85
     * @param string $template 模板文件
86
     * @param array  $data     模板变量
87
     * @return void
88
     */
89
    public function fetch(string $template, array $data = []): void
90
    {
91
        echo "fetch";
92
    }
93
94
    /**
95
     * 渲染模板内容
96
     * @access public
97
     * @param string $content 模板内容
98
     * @param array  $data    模板变量
99
     * @return void
100
     */
101
    public function display(string $content, array $data = []): void
102
    {
103
        echo "display";
104
    }
105
106
    /**
107
     * 配置模板引擎
108
     * @access private
109
     * @param array $config 参数
110
     * @return void
111
     */
112
    public function config(array $config): void
113
    {
114
        // TODO: Implement config() method.
115
    }
116
117
    /**
118
     * 获取模板引擎配置
119
     * @access public
120
     * @param string $name 参数名
121
     * @return void
122
     */
123
    public function getConfig(string $name)
124
    {
125
        // TODO: Implement getConfig() method.
126
    }
127
}
128