1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Renderers; |
4
|
|
|
|
5
|
|
|
use Maslosoft\MiniView\MiniView; |
6
|
|
|
use Maslosoft\MiniView\Renderers\PhpRenderer; |
7
|
|
|
use UnitTester; |
8
|
|
|
|
9
|
|
|
class PhpTest extends \Codeception\TestCase\Test |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var UnitTester |
14
|
|
|
*/ |
15
|
|
|
protected $tester; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* NOTE: Do not remove, part of test |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
public $value = 'property value'; |
22
|
|
|
|
23
|
|
|
// tests |
24
|
|
View Code Duplication |
public function testIfWillPassVariableToView() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$var = 'New Variable'; |
27
|
|
|
|
28
|
|
|
$view = new MiniView($this); |
29
|
|
|
|
30
|
|
|
$result = $view->render('passVariable', ['var' => $var], true); |
31
|
|
|
|
32
|
|
|
$this->assertSame($var, $result); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
// tests |
36
|
|
View Code Duplication |
public function testIfWillPassVariableToViewWithRendererDetection() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$var = 'New Variable'; |
39
|
|
|
|
40
|
|
|
$view = new MiniView($this); |
41
|
|
|
$view->setRenderer(new PhpRenderer()); |
42
|
|
|
$result = $view->render('passVariable.php', ['var' => $var], true); |
43
|
|
|
|
44
|
|
|
$this->assertSame($var, $result); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testIfWillForwardMethodToOwner() |
48
|
|
|
{ |
49
|
|
|
$view = new MiniView($this); |
50
|
|
|
|
51
|
|
|
$result = $view->render('forwardMethod', [], true); |
52
|
|
|
|
53
|
|
|
$this->assertSame($this->getValue(), $result); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testIfWillForwardPropertyToOwner() |
57
|
|
|
{ |
58
|
|
|
$view = new MiniView($this); |
59
|
|
|
|
60
|
|
|
$result = $view->render('forwardProperty', [], true); |
61
|
|
|
|
62
|
|
|
$this->assertSame($this->value, $result); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getValue() |
66
|
|
|
{ |
67
|
|
|
return 'my value from method'; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.