@@ -107,22 +107,54 @@ public function testLogsWarningIfOcrMyPdfSucceedsWithWarningOutput() {
107
107
->willReturn (true );
108
108
$ this ->command ->expects ($ this ->once ())
109
109
->method ('getError ' )
110
- ->willReturn ('error ' );
110
+ ->willReturn ('getErrorOutput ' );
111
111
$ this ->command ->expects ($ this ->once ())
112
112
->method ('getStdErr ' )
113
- ->willReturn ('stdErr ' );
113
+ ->willReturn ('stdErrOutput ' );
114
+ $ this ->command ->expects ($ this ->once ())
115
+ ->method ('getOutput ' )
116
+ ->willReturn ('someOcrFileContent ' );
114
117
$ this ->logger ->expects ($ this ->once ())
115
118
->method ('warning ' )
116
119
->with (
117
- $ this -> stringStartsWith ( 'OCRmyPDF succeeded with warning(s): ' ) ,
120
+ 'OCRmyPDF succeeded with warning(s): {stdErr}, {errorOutput} ' ,
118
121
$ this ->callback (function ($ paramsArray ) {
119
122
return is_array ($ paramsArray ) &&
120
123
count ($ paramsArray ) === 2 &&
121
- $ paramsArray [0 ] === 'stdErr ' &&
122
- $ paramsArray [1 ] === 'error ' ;
124
+ $ paramsArray [' stdErr ' ] === 'stdErrOutput ' &&
125
+ $ paramsArray [' errorOutput ' ] === 'getErrorOutput ' ;
123
126
}));
124
127
125
128
$ processor = new PdfOcrProcessor ($ this ->command , $ this ->logger );
126
129
$ processor ->ocrFile ('someContent ' );
127
130
}
131
+
132
+ public function testThrowsErrorIfOcrFileWasEmpty () {
133
+ $ this ->command ->expects ($ this ->once ())
134
+ ->method ('execute ' )
135
+ ->willReturn (true );
136
+ $ this ->command ->expects ($ this ->once ())
137
+ ->method ('getError ' )
138
+ ->willReturn ('error ' );
139
+ $ this ->command ->expects ($ this ->once ())
140
+ ->method ('getStdErr ' )
141
+ ->willReturn ('stdErr ' );
142
+ $ this ->command ->expects ($ this ->once ())
143
+ ->method ('getOutput ' )
144
+ ->willReturn ('' );
145
+
146
+
147
+ $ thrown = false ;
148
+ $ processor = new PdfOcrProcessor ($ this ->command , $ this ->logger );
149
+
150
+ try {
151
+ $ processor ->ocrFile ('someContent ' );
152
+ } catch (\Throwable $ t ) {
153
+ $ thrown = true ;
154
+ $ this ->assertInstanceOf (OcrNotPossibleException::class, $ t );
155
+ $ this ->assertEquals ('OCRmyPDF did not produce any output ' , $ t ->getMessage ());
156
+ }
157
+
158
+ $ this ->assertTrue ($ thrown );
159
+ }
128
160
}
0 commit comments