4
4
5
5
use PhpSchool \CliMenu \MenuItem \SelectableItem ;
6
6
use PhpSchool \CliMenu \MenuStyle ;
7
+ use PhpSchool \Terminal \Terminal ;
7
8
use PHPUnit \Framework \TestCase ;
8
9
9
10
/**
@@ -46,35 +47,35 @@ public function testGetText() : void
46
47
47
48
public function testGetRows () : void
48
49
{
49
- $ menuStyle = $ this ->createMock (MenuStyle::class);
50
+ $ terminal = $ this ->createMock (Terminal::class);
51
+ $ terminal ->expects ($ this ->any ())->method ('getWidth ' )->willReturn (100 );
50
52
51
- $ menuStyle
52
- ->expects ($ this ->any ())
53
- ->method ('getContentWidth ' )
54
- ->will ($ this ->returnValue (10 ));
53
+ $ menuStyle = new MenuStyle ($ terminal );
54
+ $ menuStyle ->setPaddingLeftRight (0 );
55
+ $ menuStyle ->setWidth (10 );
55
56
56
57
$ item = new SelectableItem ('Item ' , function () {
57
58
});
58
- $ this ->assertEquals ([' Item ' ], $ item ->getRows ($ menuStyle ));
59
- $ this ->assertEquals ([' Item ' ], $ item ->getRows ($ menuStyle , false ));
60
- $ this ->assertEquals ([' Item ' ], $ item ->getRows ($ menuStyle , true ));
59
+ $ this ->assertEquals (['○ Item ' ], $ item ->getRows ($ menuStyle ));
60
+ $ this ->assertEquals (['○ Item ' ], $ item ->getRows ($ menuStyle , false ));
61
+ $ this ->assertEquals (['● Item ' ], $ item ->getRows ($ menuStyle , true ));
61
62
}
62
63
63
64
public function testSetText () : void
64
65
{
65
- $ menuStyle = $ this ->createMock (MenuStyle::class);
66
+ $ terminal = $ this ->createMock (Terminal::class);
67
+ $ terminal ->expects ($ this ->any ())->method ('getWidth ' )->willReturn (100 );
68
+
69
+ $ menuStyle = new MenuStyle ($ terminal );
70
+ $ menuStyle ->setPaddingLeftRight (0 );
71
+ $ menuStyle ->setWidth (10 );
66
72
67
- $ menuStyle
68
- ->expects ($ this ->any ())
69
- ->method ('getContentWidth ' )
70
- ->will ($ this ->returnValue (10 ));
71
-
72
73
$ item = new SelectableItem ('Item ' , function () {
73
74
});
74
75
$ item ->setText ('New Text ' );
75
- $ this ->assertEquals ([' New Text ' ], $ item ->getRows ($ menuStyle ));
76
- $ this ->assertEquals ([' New Text ' ], $ item ->getRows ($ menuStyle , false ));
77
- $ this ->assertEquals ([' New Text ' ], $ item ->getRows ($ menuStyle , true ));
76
+ $ this ->assertEquals (['○ New Text ' ], $ item ->getRows ($ menuStyle ));
77
+ $ this ->assertEquals (['○ New Text ' ], $ item ->getRows ($ menuStyle , false ));
78
+ $ this ->assertEquals (['● New Text ' ], $ item ->getRows ($ menuStyle , true ));
78
79
}
79
80
80
81
public function testGetRowsWithUnSelectedMarker () : void
@@ -90,7 +91,7 @@ public function testGetRowsWithUnSelectedMarker() : void
90
91
->expects ($ this ->exactly (2 ))
91
92
->method ('getMarker ' )
92
93
->with (false )
93
- ->will ($ this ->returnValue ('* ' ));
94
+ ->will ($ this ->returnValue ('* ' ));
94
95
95
96
$ item = new SelectableItem ('Item ' , function () {
96
97
});
@@ -111,7 +112,7 @@ public function testGetRowsWithSelectedMarker() : void
111
112
->expects ($ this ->once ())
112
113
->method ('getMarker ' )
113
114
->with (true )
114
- ->will ($ this ->returnValue ('= ' ));
115
+ ->will ($ this ->returnValue ('= ' ));
115
116
116
117
$ item = new SelectableItem ('Item ' , function () {
117
118
});
@@ -120,43 +121,39 @@ public function testGetRowsWithSelectedMarker() : void
120
121
121
122
public function testGetRowsWithItemExtra () : void
122
123
{
123
- $ menuStyle = $ this ->createMock (MenuStyle::class);
124
-
125
- $ menuStyle
126
- ->expects ($ this ->any ())
127
- ->method ('getContentWidth ' )
128
- ->will ($ this ->returnValue (10 ));
124
+ $ terminal = $ this ->createMock (Terminal::class);
125
+ $ terminal ->expects ($ this ->any ())->method ('getWidth ' )->willReturn (100 );
129
126
130
- $ menuStyle
131
- ->expects ($ this ->once ())
132
- ->method ('getItemExtra ' )
133
- ->will ($ this ->returnValue ('[EXTRA] ' ));
127
+ $ menuStyle = new MenuStyle ($ terminal );
128
+ $ menuStyle ->setPaddingLeftRight (0 );
129
+ $ menuStyle ->setWidth (20 );
130
+ $ menuStyle ->setItemExtra ('[EXTRA] ' );
131
+ $ menuStyle ->setDisplaysExtra (true );
132
+ $ menuStyle ->setUnselectedMarker ('* ' );
134
133
135
134
$ item = new SelectableItem ('Item ' , function () {
136
135
}, true );
137
- $ this ->assertEquals ([' Item [EXTRA] ' ], $ item ->getRows ($ menuStyle ));
136
+ $ this ->assertEquals (['* Item [EXTRA] ' ], $ item ->getRows ($ menuStyle ));
138
137
}
139
138
140
139
public function testGetRowsWithMultipleLinesWithItemExtra () : void
141
140
{
142
- $ menuStyle = $ this ->createMock (MenuStyle::class);
141
+ $ terminal = $ this ->createMock (Terminal::class);
142
+ $ terminal ->expects ($ this ->any ())->method ('getWidth ' )->willReturn (100 );
143
143
144
- $ menuStyle
145
- ->expects ($ this ->any ())
146
- ->method ('getContentWidth ' )
147
- ->will ($ this ->returnValue (10 ));
148
-
149
- $ menuStyle
150
- ->expects ($ this ->once ())
151
- ->method ('getItemExtra ' )
152
- ->will ($ this ->returnValue ('[EXTRA] ' ));
144
+ $ menuStyle = new MenuStyle ($ terminal );
145
+ $ menuStyle ->setPaddingLeftRight (0 );
146
+ $ menuStyle ->setWidth (20 );
147
+ $ menuStyle ->setItemExtra ('[EXTRA] ' );
148
+ $ menuStyle ->setDisplaysExtra (true );
149
+ $ menuStyle ->setUnselectedMarker ('* ' );
153
150
154
151
$ item = new SelectableItem ('LONG ITEM LINE ' , function () {
155
152
}, true );
156
153
$ this ->assertEquals (
157
154
[
158
- " LONG ITEM [EXTRA] " ,
159
- " LINE " ,
155
+ "* LONG ITEM [EXTRA] " ,
156
+ " LINE " ,
160
157
],
161
158
$ item ->getRows ($ menuStyle )
162
159
);
0 commit comments