6
6
use Illuminate \Foundation \Testing \DatabaseMigrations ;
7
7
use Illuminate \Support \Facades \Log ;
8
8
use Mockery \Mock ;
9
+ use Softonic \LaravelIntelligentScraper \Scraper \Events \ConfigurationScraped ;
9
10
use Softonic \LaravelIntelligentScraper \Scraper \Exceptions \ConfigurationException ;
10
11
use Softonic \LaravelIntelligentScraper \Scraper \Models \Configuration as ConfigurationModel ;
11
12
use Softonic \LaravelIntelligentScraper \Scraper \Models \ScrapedDataset ;
@@ -150,18 +151,18 @@ public function whenTryToFindNewXpathButNotFoundItShouldLogItAndResetVariant()
150
151
$ this ->variantGenerator ->shouldReceive ('fieldNotFound ' )
151
152
->once ();
152
153
$ this ->variantGenerator ->shouldReceive ('getId ' )
153
- ->andReturnNull ( );
154
+ ->andReturn ( '' );
154
155
155
156
Log::shouldReceive ('warning ' )
156
157
->with ("Field 'author' with value 'My author' not found for 'https://test.c/123456789012'. " );
157
158
159
+ $ this ->expectsEvents (ConfigurationScraped::class);
160
+
158
161
try {
159
162
$ this ->configurator ->configureFromDataset ($ posts );
160
163
} catch (ConfigurationException $ e ) {
161
164
$ this ->assertEquals ('Field(s) "author" not found. ' , $ e ->getMessage ());
162
165
}
163
-
164
- $ this ->assertNull ($ posts [0 ]['variant ' ]);
165
166
}
166
167
167
168
/**
@@ -225,18 +226,18 @@ public function whenUseSomeOldXpathButNotFoundNewsItShouldLogItAndResetVariant()
225
226
$ this ->variantGenerator ->shouldReceive ('fieldNotFound ' )
226
227
->once ();
227
228
$ this ->variantGenerator ->shouldReceive ('getId ' )
228
- ->andReturnNull ( );
229
+ ->andReturn ( '' );
229
230
230
231
Log::shouldReceive ('warning ' )
231
232
->with ("Field 'author' with value 'My author' not found for 'https://test.c/123456789012'. " );
232
233
234
+ $ this ->expectsEvents (ConfigurationScraped::class);
235
+
233
236
try {
234
237
$ this ->configurator ->configureFromDataset ($ posts );
235
238
} catch (ConfigurationException $ e ) {
236
239
$ this ->assertEquals ('Field(s) "author" not found. ' , $ e ->getMessage ());
237
240
}
238
-
239
- $ this ->assertNull ($ posts [0 ]['variant ' ]);
240
241
}
241
242
242
243
/**
@@ -306,22 +307,21 @@ public function whenTryToFindXpathInMultiplepostsAndNotFoundInAnyItShouldThrowAn
306
307
$ this ->variantGenerator ->shouldReceive ('fieldNotFound ' )
307
308
->times (4 );
308
309
$ this ->variantGenerator ->shouldReceive ('getId ' )
309
- ->andReturnNull ( );
310
+ ->andReturn ( '' );
310
311
311
312
Log::shouldReceive ('warning ' )
312
313
->with ("Field 'title' with value 'My Title' not found for 'https://test.c/123456789012'. " );
313
314
314
315
Log::shouldReceive ('warning ' )
315
316
->with ("Field 'author' with value 'My author' not found for 'https://test.c/123456789012'. " );
316
317
318
+ $ this ->expectsEvents (ConfigurationScraped::class);
319
+
317
320
try {
318
321
$ this ->configurator ->configureFromDataset ($ posts );
319
322
} catch (ConfigurationException $ e ) {
320
323
$ this ->assertEquals ('Field(s) "title,author" not found. ' , $ e ->getMessage ());
321
324
}
322
-
323
- $ this ->assertNull ($ posts [0 ]['variant ' ]);
324
- $ this ->assertNull ($ posts [1 ]['variant ' ]);
325
325
}
326
326
327
327
/**
@@ -413,6 +413,8 @@ public function whenDiscoverDifferentXpathItShouldGetAllOfThemAndUpdateTheVarian
413
413
$ this ->variantGenerator ->shouldReceive ('getId ' )
414
414
->andReturn (10 , 20 , 30 );
415
415
416
+ $ this ->expectsEvents (ConfigurationScraped::class);
417
+
416
418
$ configurations = $ this ->configurator ->configureFromDataset ($ posts );
417
419
418
420
$ this ->assertInstanceOf (ConfigurationModel::class, $ configurations [0 ]);
@@ -436,9 +438,5 @@ public function whenDiscoverDifferentXpathItShouldGetAllOfThemAndUpdateTheVarian
436
438
],
437
439
array_values ($ configurations [1 ]['xpaths ' ])
438
440
);
439
-
440
- $ this ->assertEquals ($ posts [0 ]['variant ' ], 10 );
441
- $ this ->assertEquals ($ posts [1 ]['variant ' ], 20 );
442
- $ this ->assertEquals ($ posts [2 ]['variant ' ], 30 );
443
441
}
444
442
}
0 commit comments