laravel模块之view

view

1
2
3
4
5
6
7
8
9
"require": {
"php": "^7.1.3",
"illuminate/container": "5.7.*",
"illuminate/contracts": "5.7.*",
"illuminate/events": "5.7.*",
"illuminate/filesystem": "5.7.*",
"illuminate/support": "5.7.*",
"symfony/debug": "^4.1"
},

测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Created by PhpStorm.
* User: 小粽子
* Date: 2018/6/25
* Time: 15:36
*/

namespace Tests\View;

use Mockery as m;
use Illuminate\View\View;
use PHPUnit\Framework\TestCase;

class ViewTest extends TestCase
{
public function tearDown()
{
m::close();
}

public function testDataCanBeSetOnView()
{
$view = $this->getView();
$view->with('foo', 'bar')->with(['baz' => 'boom']);
$this->assertEquals(['foo' => 'bar', 'baz' => 'boom'], $view->getData());

$view = $this->getView();
$view->withFoo('bar')->withBaz('boom');
$this->assertEquals(['foo' => 'bar', 'baz' => 'boom'], $view->getData());

}

public function testRenderProperlyRendersView()
{
$view = $this->getView(['foo' => 'bar']);
$view->getFactory()->shouldReceive('incrementRender')->once()->ordered();
$view->getFactory()->shouldReceive('callComposer')->once()->ordered()->with($view);
$view->getFactory()->shouldReceive('getShared')->once()->andReturn(['shared' => 'foo']);
$view->getEngine()->shouldReceive('get')->once()->with('path', ['foo' => 'bar', 'shared' => 'foo'])->andReturn('contents');
$view->getFactory()->shouldReceive('decrementRender')->once()->ordered();
$view->getFactory()->shouldReceive('flushStateIfDoneRendering')->once();

$callback = function (View $rendered, $contents) use ($view) {
$this->assertEquals($view, $rendered);
$this->assertEquals('contents', $contents);
};

$this->assertEquals('contents', $view->render($callback));
}


protected function getView($data = [])
{
return new View(
m::mock('Illuminate\View\Factory'),
m::mock(\Illuminate\Contracts\View\Engine::class),
'view',
'path',
$data
);
}
}