4343
4444namespace SebastianBergmann \Diff ;
4545
46- class DifferTest extends \PHPUnit_Framework_TestCase
46+ use PHPUnit_Framework_TestCase ;
47+
48+ class DifferTest extends PHPUnit_Framework_TestCase
4749{
4850 const REMOVED = 2 ;
4951 const ADDED = 1 ;
@@ -60,205 +62,155 @@ protected function setUp()
6062 }
6163
6264 /**
63- * @covers SebastianBergmann\Diff\Differ::diff
64- */
65- public function testComparisonErrorMessage ()
66- {
67- $ this ->assertEquals (
68- "--- Original \n+++ New \n@@ @@ \n-a \n+b \n" ,
69- $ this ->differ ->diff ('a ' , 'b ' )
70- );
71- }
72-
73- /**
74- * @covers SebastianBergmann\Diff\Differ::diffToArray
75- */
76- public function testComparisonErrorMessage_toArray ()
77- {
78- $ expected = array ();
79- $ expected [] = array ('a ' , self ::REMOVED );
80- $ expected [] = array ('b ' , self ::ADDED );
81-
82- $ this ->assertEquals ($ expected , $ this ->differ ->diffToArray ('a ' , 'b ' ));
83- }
84-
85- /**
86- * @covers SebastianBergmann\Diff\Differ::diff
87- */
88- public function testComparisonErrorStartSame ()
89- {
90- $ this ->assertEquals (
91- "--- Original \n+++ New \n@@ @@ \n-ba \n+bc \n" ,
92- $ this ->differ ->diff ('ba ' , 'bc ' )
93- );
94- }
95-
96- /**
97- * @covers SebastianBergmann\Diff\Differ::diffToArray
98- */
99- public function testComparisonErrorStartSame_toArray ()
100- {
101- $ expected = array ();
102- $ expected [] = array ('ba ' , self ::REMOVED );
103- $ expected [] = array ('bc ' , self ::ADDED );
104-
105- $ this ->assertEquals ($ expected , $ this ->differ ->diffToArray ('ba ' , 'bc ' ));
106- }
107-
108- /**
109- * @covers SebastianBergmann\Diff\Differ::diff
110- */
111- public function testComparisonErrorEndSame ()
112- {
113- $ this ->assertEquals (
114- "--- Original \n+++ New \n@@ @@ \n-ab \n+cb \n" ,
115- $ this ->differ ->diff ('ab ' , 'cb ' )
116- );
117- }
118-
119- /**
120- * @covers SebastianBergmann\Diff\Differ::diffToArray
121- */
122- public function testComparisonErrorEndSame_toArray ()
123- {
124- $ expected = array ();
125- $ expected [] = array ('ab ' , self ::REMOVED );
126- $ expected [] = array ('cb ' , self ::ADDED );
127-
128- $ this ->assertEquals ($ expected , $ this ->differ ->diffToArray ('ab ' , 'cb ' ));
129- }
130-
131- /**
132- * @covers SebastianBergmann\Diff\Differ::diff
133- */
134- public function testComparisonErrorStartAndEndSame ()
135- {
136- $ this ->assertEquals (
137- "--- Original \n+++ New \n@@ @@ \n-abc \n+adc \n" ,
138- $ this ->differ ->diff ('abc ' , 'adc ' )
139- );
140- }
141-
142- /**
143- * @covers SebastianBergmann\Diff\Differ::diffToArray
144- */
145- public function testComparisonErrorStartAndEndSame_toArray ()
146- {
147- $ expected = array ();
148- $ expected [] = array ('abc ' , self ::REMOVED );
149- $ expected [] = array ('adc ' , self ::ADDED );
150-
151- $ this ->assertEquals (
152- $ expected , $ this ->differ ->diffToArray ('abc ' , 'adc ' )
153- );
154- }
155-
156- /**
157- * @covers SebastianBergmann\Diff\Differ::diff
158- */
159- public function testComparisonErrorStartSameComplete ()
160- {
161- $ this ->assertEquals (
162- "--- Original \n+++ New \n@@ @@ \n-ab \n+abc \n" ,
163- $ this ->differ ->diff ('ab ' , 'abc ' )
164- );
165- }
166-
167- /**
168- * @covers SebastianBergmann\Diff\Differ::diffToArray
169- */
170- public function testComparisonErrorStartSameComplete_toArray ()
171- {
172- $ expected = array ();
173- $ expected [] = array ('ab ' , self ::REMOVED );
174- $ expected [] = array ('abc ' , self ::ADDED );
175-
176- $ this ->assertEquals ($ expected , $ this ->differ ->diffToArray ('ab ' , 'abc ' ));
177- }
178-
179- /**
180- * @covers SebastianBergmann\Diff\Differ::diff
181- */
182- public function testComparisonErrorEndSameComplete ()
183- {
184- $ this ->assertEquals (
185- "--- Original \n+++ New \n@@ @@ \n-bc \n+abc \n" ,
186- $ this ->differ ->diff ('bc ' , 'abc ' )
187- );
188- }
189-
190- /**
191- * @covers SebastianBergmann\Diff\Differ::diffToArray
192- */
193- public function testComparisonErrorEndSameComplete_toArray ()
194- {
195- $ expected = array ();
196- $ expected [] = array ('bc ' , self ::REMOVED );
197- $ expected [] = array ('abc ' , self ::ADDED );
198-
199- $ this ->assertEquals ($ expected , $ this ->differ ->diffToArray ('bc ' , 'abc ' ));
200- }
201-
202- /**
203- * @covers SebastianBergmann\Diff\Differ::diff
204- */
205- public function testComparisonErrorOverlapingMatches ()
206- {
207- $ this ->assertEquals (
208- "--- Original \n+++ New \n@@ @@ \n-abc \n+abbc \n" ,
209- $ this ->differ ->diff ('abc ' , 'abbc ' )
210- );
211- }
212-
213- /**
214- * @covers SebastianBergmann\Diff\Differ::diffToArray
215- */
216- public function testComparisonErrorOverlapingMatches_toArray ()
217- {
218- $ expected = array ();
219- $ expected [] = array ('abc ' , self ::REMOVED );
220- $ expected [] = array ('abbc ' , self ::ADDED );
221-
222- $ this ->assertEquals (
223- $ expected , $ this ->differ ->diffToArray ('abc ' , 'abbc ' )
224- );
225- }
226-
227- /**
228- * @covers SebastianBergmann\Diff\Differ::diff
229- */
230- public function testComparisonErrorOverlapingMatches2 ()
231- {
232- $ this ->assertEquals (
233- "--- Original \n+++ New \n@@ @@ \n-abcdde \n+abcde \n" ,
234- $ this ->differ ->diff ('abcdde ' , 'abcde ' )
65+ * @param array $expected
66+ * @param string $from
67+ * @param string $to
68+ * @dataProvider arrayProvider
69+ * @covers SebastianBergmann\Diff\Differ::diffToArray
70+ */
71+ public function testArrayRepresentationOfDiffCanBeRendered (array $ expected , $ from , $ to )
72+ {
73+ $ this ->assertEquals ($ expected , $ this ->differ ->diffToArray ($ from , $ to ));
74+ }
75+
76+ /**
77+ * @param string $expected
78+ * @param string $from
79+ * @param string $to
80+ * @dataProvider textProvider
81+ * @covers SebastianBergmann\Diff\Differ::diff
82+ */
83+ public function testTextRepresentationOfDiffCanBeRendered ($ expected , $ from , $ to )
84+ {
85+ $ this ->assertEquals ($ expected , $ this ->differ ->diff ($ from , $ to ));
86+ }
87+
88+ public function arrayProvider ()
89+ {
90+ return array (
91+ array (
92+ array (
93+ array ('a ' , self ::REMOVED ),
94+ array ('b ' , self ::ADDED )
95+ ),
96+ 'a ' ,
97+ 'b '
98+ ),
99+ array (
100+ array (
101+ array ('ba ' , self ::REMOVED ),
102+ array ('bc ' , self ::ADDED )
103+ ),
104+ 'ba ' ,
105+ 'bc '
106+ ),
107+ array (
108+ array (
109+ array ('ab ' , self ::REMOVED ),
110+ array ('cb ' , self ::ADDED )
111+ ),
112+ 'ab ' ,
113+ 'cb '
114+ ),
115+ array (
116+ array (
117+ array ('abc ' , self ::REMOVED ),
118+ array ('adc ' , self ::ADDED )
119+ ),
120+ 'abc ' ,
121+ 'adc '
122+ ),
123+ array (
124+ array (
125+ array ('ab ' , self ::REMOVED ),
126+ array ('abc ' , self ::ADDED )
127+ ),
128+ 'ab ' ,
129+ 'abc '
130+ ),
131+ array (
132+ array (
133+ array ('bc ' , self ::REMOVED ),
134+ array ('abc ' , self ::ADDED )
135+ ),
136+ 'bc ' ,
137+ 'abc '
138+ ),
139+ array (
140+ array (
141+ array ('abc ' , self ::REMOVED ),
142+ array ('abbc ' , self ::ADDED )
143+ ),
144+ 'abc ' ,
145+ 'abbc '
146+ ),
147+ array (
148+ array (
149+ array ('abcdde ' , self ::REMOVED ),
150+ array ('abcde ' , self ::ADDED )
151+ ),
152+ 'abcdde ' ,
153+ 'abcde '
154+ )
235155 );
236156 }
237157
238- /**
239- * @covers SebastianBergmann\Diff\Differ::diffToArray
240- */
241- public function testComparisonErrorOverlapingMatches2_toArray ()
242- {
243- $ expected = array ();
244- $ expected [] = array ('abcdde ' , self ::REMOVED );
245- $ expected [] = array ('abcde ' , self ::ADDED );
246-
247- $ this ->assertEquals (
248- $ expected , $ this ->differ ->diffToArray ('abcdde ' , 'abcde ' )
158+ public function textProvider ()
159+ {
160+ return array (
161+ array (
162+ "--- Original \n+++ New \n@@ @@ \n-a \n+b \n" ,
163+ 'a ' ,
164+ 'b '
165+ ),
166+ array (
167+ "--- Original \n+++ New \n@@ @@ \n-ba \n+bc \n" ,
168+ 'ba ' ,
169+ 'bc '
170+ ),
171+ array (
172+ "--- Original \n+++ New \n@@ @@ \n-ab \n+cb \n" ,
173+ 'ab ' ,
174+ 'cb '
175+ ),
176+ array (
177+ "--- Original \n+++ New \n@@ @@ \n-abc \n+adc \n" ,
178+ 'abc ' ,
179+ 'adc '
180+ ),
181+ array (
182+ "--- Original \n+++ New \n@@ @@ \n-ab \n+abc \n" ,
183+ 'ab ' ,
184+ 'abc '
185+ ),
186+ array (
187+ "--- Original \n+++ New \n@@ @@ \n-bc \n+abc \n" ,
188+ 'bc ' ,
189+ 'abc '
190+ ),
191+ array (
192+ "--- Original \n+++ New \n@@ @@ \n-abc \n+abbc \n" ,
193+ 'abc ' ,
194+ 'abbc '
195+ ),
196+ array (
197+ "--- Original \n+++ New \n@@ @@ \n-abcdde \n+abcde \n" ,
198+ 'abcdde ' ,
199+ 'abcde '
200+ ),
249201 );
250202 }
251203
252204 /**
253205 * @covers SebastianBergmann\Diff\Differ::diff
254206 */
255- public function testCustomHeader ()
207+ public function testCustomHeaderCanBeUsed ()
256208 {
257209 $ differ = new Differ ('CUSTOM HEADER ' );
258210
259211 $ this ->assertEquals (
260- "CUSTOM HEADER@@ @@ \n-a \n+b \n" ,
261- $ differ ->diff ('a ' , 'b ' )
212+ "CUSTOM HEADER@@ @@ \n-a \n+b \n" ,
213+ $ differ ->diff ('a ' , 'b ' )
262214 );
263215 }
264216}
0 commit comments