File tree Expand file tree Collapse file tree 4 files changed +32
-4
lines changed Expand file tree Collapse file tree 4 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ $rendererOptions = [
9292 // internally, ops (tags) are all int type but this is not good for human reading.
9393 // set this to "true" to convert them into string form before outputting.
9494 'outputTagAsString' => true,
95- // change this value to a non-null one as the the returned diff
95+ // change this value to a string as the the returned diff
9696 // if the two input strings are identical
9797 'resultForIdenticals' => null,
9898 // extra HTML classes added to the DOM of the diff container
Original file line number Diff line number Diff line change 4848 // internally, ops (tags) are all int type but this is not good for human reading.
4949 // set this to "true" to convert them into string form before outputting.
5050 'outputTagAsString ' => false ,
51- // change this value to a non-null one as the the returned diff
51+ // change this value to a string as the the returned diff
5252 // if the two input strings are identical
5353 'resultForIdenticals ' => null ,
5454 // extra HTML classes added to the DOM of the diff container
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ abstract class AbstractRenderer implements RendererInterface
4949 // internally, ops (tags) are all int type but this is not good for human reading.
5050 // set this to "true" to convert them into string form before outputting.
5151 'outputTagAsString ' => false ,
52- // change this value to a non-null one as the the returned diff
52+ // change this value to a string as the the returned diff
5353 // if the two input strings are identical
5454 'resultForIdenticals ' => null ,
5555 // extra HTML classes added to the DOM of the diff container
@@ -111,10 +111,20 @@ public function getOptions(): array
111111 * @final
112112 *
113113 * @todo mark this method with "final" in the next major release
114+ *
115+ * @throws \InvalidArgumentException
114116 */
115117 public function getResultForIdenticals (): string
116118 {
117- return $ this ->options ['resultForIdenticals ' ] ?? $ this ->getResultForIdenticalsDefault ();
119+ $ custom = $ this ->options ['resultForIdenticals ' ];
120+
121+ if (isset ($ custom ) && !\is_string ($ custom )) {
122+ throw new \InvalidArgumentException (
123+ 'renderer option `resultForIdenticals` must be null or string. '
124+ );
125+ }
126+
127+ return $ custom ?? $ this ->getResultForIdenticalsDefault ();
118128 }
119129
120130 /**
Original file line number Diff line number Diff line change @@ -68,4 +68,22 @@ public function testSetOptionsWithResultForIdenticals(): void
6868 'Rederer options: result for identicals should work. '
6969 );
7070 }
71+
72+ /**
73+ * Test the AbstractRenderer::setOptions with an invalid result for identicals.
74+ *
75+ * @covers \Jfcherng\Diff\Renderer\AbstractRenderer::setOptions
76+ */
77+ public function testSetOptionsWithInvalidResultForIdenticals (): void
78+ {
79+ static ::expectException (\InvalidArgumentException::class);
80+
81+ $ diffResult = DiffHelper::calculate (
82+ 'we are the same ' ,
83+ 'we are the same ' ,
84+ 'Inline ' ,
85+ [],
86+ ['resultForIdenticals ' => 50 ]
87+ );
88+ }
7189}
You can’t perform that action at this time.
0 commit comments