8
8
use ArrayObject ;
9
9
use PHPUnit \Framework \Constraint \Constraint ;
10
10
use PHPUnit \Framework \ExpectationFailedException ;
11
- use PHPUnit \SebastianBergmann \Comparator \ComparisonFailure as Phar_ComparisonFailure ;
11
+ use PHPUnit \SebastianBergmann \Comparator \ComparisonFailure as ComparisonFailure_In_Phar_Old ;
12
+ use PHPUnit \SebastianBergmann \Exporter \Exporter as Exporter_In_Phar_Old ;
13
+ use PHPUnitPHAR \SebastianBergmann \Comparator \ComparisonFailure as ComparisonFailure_In_Phar ;
14
+ use PHPUnitPHAR \SebastianBergmann \Exporter \Exporter as Exporter_In_Phar ;
12
15
use SebastianBergmann \Comparator \ComparisonFailure ;
16
+ use SebastianBergmann \Exporter \Exporter ;
13
17
use SebastianBergmann \RecursionContext \InvalidArgumentException ;
14
18
use Traversable ;
15
19
@@ -84,12 +88,7 @@ public function evaluate($other, string $description = '', bool $returnResult =
84
88
return null ;
85
89
}
86
90
87
- // Support use of this library when running PHPUnit as a Phar.
88
- if (class_exists (Phar_ComparisonFailure::class) === true ) {
89
- $ class = Phar_ComparisonFailure::class;
90
- } else {
91
- $ class = ComparisonFailure::class;
92
- }
91
+ $ class = self ::getPHPUnitComparisonFailure ();
93
92
94
93
$ f = new $ class (
95
94
$ patched ,
@@ -107,7 +106,51 @@ public function evaluate($other, string $description = '', bool $returnResult =
107
106
*/
108
107
public function toString (): string
109
108
{
110
- return 'has the subset ' . $ this ->exporter ()->export ($ this ->subset );
109
+ $ exporter = self ::getPHPUnitExporterObject ();
110
+
111
+ return 'has the subset ' . $ exporter ->export ($ this ->subset );
112
+ }
113
+
114
+ /**
115
+ * Helper function to obtain an instance of the Exporter class.
116
+ *
117
+ * @return SebastianBergmann\Exporter\Exporter|PHPUnitPHAR\SebastianBergmann\Exporter\Exporter|PHPUnit\SebastianBergmann\Exporter\Exporter
118
+ */
119
+ private static function getPHPUnitExporterObject ()
120
+ {
121
+ if (class_exists ('SebastianBergmann\Comparator\ComparisonFailure ' )) {
122
+ // Composer install or really old PHAR files.
123
+ return new Exporter ();
124
+ }
125
+
126
+ if (class_exists ('PHPUnitPHAR\SebastianBergmann\Comparator\ComparisonFailure ' )) {
127
+ // PHPUnit PHAR file for 8.5.38+, 9.6.19+, 10.5.17+ and 11.0.10+.
128
+ return new Exporter_In_Phar ();
129
+ }
130
+
131
+ // PHPUnit PHAR file for < 8.5.38, < 9.6.19, < 10.5.17 and < 11.0.10.
132
+ return new Exporter_In_Phar_Old ();
133
+ }
134
+
135
+ /**
136
+ * Helper function to obtain the class name of the ComparisonFailure class.
137
+ *
138
+ * @return string;
139
+ */
140
+ private static function getPHPUnitComparisonFailure ()
141
+ {
142
+ if (class_exists ('SebastianBergmann\Exporter\Exporter ' )) {
143
+ // Composer install or really old PHAR files.
144
+ return ComparisonFailure::class;
145
+ }
146
+
147
+ if (class_exists ('PHPUnitPHAR\SebastianBergmann\Exporter\Exporter ' )) {
148
+ // PHPUnit PHAR file for 8.5.38+, 9.6.19+, 10.5.17+ and 11.0.10+.
149
+ return ComparisonFailure_In_Phar::class;
150
+ }
151
+
152
+ // PHPUnit PHAR file for < 8.5.38, < 9.6.19, < 10.5.17 and < 11.0.10.
153
+ return ComparisonFailure_In_Phar_Old::class;
111
154
}
112
155
113
156
/**
0 commit comments