3
3
namespace Softonic \LaravelIntelligentScraper \Scraper \Repositories ;
4
4
5
5
use Illuminate \Foundation \Testing \DatabaseMigrations ;
6
+ use Illuminate \Support \Facades \App ;
6
7
use Illuminate \Support \Facades \Cache ;
7
8
use Softonic \LaravelIntelligentScraper \Scraper \Application \Configurator ;
8
9
use Softonic \LaravelIntelligentScraper \Scraper \Models \Configuration as ConfigurationModel ;
@@ -34,9 +35,7 @@ public function whenRetrieveAllConfigurationItShouldReturnIt()
34
35
'xpaths ' => '//*[@id="author"] ' ,
35
36
]);
36
37
37
- $ configurator = \Mockery::mock (Configurator::class);
38
-
39
- $ configuration = new Configuration ($ configurator );
38
+ $ configuration = new Configuration ();
40
39
$ data = $ configuration ->findByType ('post ' );
41
40
42
41
$ this ->assertCount (2 , $ data );
@@ -51,8 +50,9 @@ public function whenRecalculateButThereIsNotApostDatasetItShouldThrowAnException
51
50
$ this ->expectExceptionMessage ('A dataset example is needed to recalculate xpaths for type post. ' );
52
51
53
52
$ configurator = \Mockery::mock (Configurator::class);
53
+ App::instance (Configurator::class, $ configurator );
54
54
55
- $ configuration = new Configuration ($ configurator );
55
+ $ configuration = new Configuration ();
56
56
$ configuration ->calculate ('post ' );
57
57
}
58
58
@@ -109,13 +109,14 @@ public function whenRecalculateItShouldStoreTheNewXpaths()
109
109
->with (Configuration::class . '-config-post ' , $ config , Configuration::CACHE_TTL );
110
110
111
111
$ configurator = \Mockery::mock (Configurator::class);
112
+ App::instance (Configurator::class, $ configurator );
112
113
$ configurator ->shouldReceive ('configureFromDataset ' )
113
114
->withArgs (function ($ posts ) {
114
115
return 2 == $ posts ->count ();
115
116
})
116
117
->andReturn ($ config );
117
118
118
- $ configuration = new Configuration ($ configurator );
119
+ $ configuration = new Configuration ();
119
120
$ configs = $ configuration ->calculate ('post ' );
120
121
121
122
$ this ->assertEquals ($ configs [0 ]['name ' ], 'title ' );
@@ -164,6 +165,7 @@ public function whenRecalculateFailsItShouldThrowAnException()
164
165
->andReturnNull ();
165
166
166
167
$ configurator = \Mockery::mock (Configurator::class);
168
+ App::instance (Configurator::class, $ configurator );
167
169
$ configurator ->shouldReceive ('configureFromDataset ' )
168
170
->withArgs (function ($ posts ) {
169
171
return 2 == $ posts ->count ();
@@ -173,7 +175,7 @@ public function whenRecalculateFailsItShouldThrowAnException()
173
175
$ this ->expectException (\UnexpectedValueException::class);
174
176
$ this ->expectExceptionMessage ('Recalculate fail ' );
175
177
176
- $ configuration = new Configuration ($ configurator );
178
+ $ configuration = new Configuration ();
177
179
$ configuration ->calculate ('post ' );
178
180
}
179
181
@@ -183,6 +185,7 @@ public function whenRecalculateFailsItShouldThrowAnException()
183
185
public function whenCalculateAfterAnotherCalculateItShouldUseThePrecalclatedConfig ()
184
186
{
185
187
$ configurator = \Mockery::mock (Configurator::class);
188
+ App::instance (Configurator::class, $ configurator );
186
189
$ configurator ->shouldReceive ('configureFromDataset ' )
187
190
->never ();
188
191
@@ -192,7 +195,7 @@ public function whenCalculateAfterAnotherCalculateItShouldUseThePrecalclatedConf
192
195
->with (Configuration::class . '-config-post ' )
193
196
->andReturn ($ config );
194
197
195
- $ configuration = new Configuration ($ configurator );
198
+ $ configuration = new Configuration ();
196
199
$ this ->assertEquals (
197
200
$ config ,
198
201
$ configuration ->calculate ('post ' )
0 commit comments