@@ -49,14 +49,17 @@ final class EngineTest extends IntegrationTestCase
49
49
50
50
private FakeClock $ clock ;
51
51
52
+ private ArrayRequestScheduler $ scheduler ;
53
+
52
54
protected function setUp (): void
53
55
{
54
56
parent ::setUp ();
55
57
56
58
$ dispatcher = new EventDispatcher ();
57
59
$ this ->clock = new FakeClock ();
60
+ $ this ->scheduler = new ArrayRequestScheduler ($ this ->clock );
58
61
$ this ->engine = new Engine (
59
- new ArrayRequestScheduler ( $ this ->clock ) ,
62
+ $ this ->scheduler ,
60
63
new Downloader (new Client (), $ dispatcher ),
61
64
new ItemPipeline ($ dispatcher ),
62
65
new Processor ($ dispatcher ),
@@ -72,14 +75,32 @@ public function testCrawlsStartUrls(): void
72
75
$ this ->makeRequest ('http://localhost:8000/test1 ' ),
73
76
$ this ->makeRequest ('http://localhost:8000/test2 ' ),
74
77
];
75
- $ run = new Run ($ startRequests );
78
+ $ run = new Run ($ startRequests, ' ::namespace:: ' );
76
79
77
80
$ this ->engine ->start ($ run );
78
81
79
82
$ this ->assertRouteWasCrawledTimes ('/test1 ' , 1 );
80
83
$ this ->assertRouteWasCrawledTimes ('/test2 ' , 1 );
81
84
}
82
85
86
+ public function testDoesntCrawlStartUrlsWithExistingRequestsInScheduler (): void
87
+ {
88
+ $ startRequests = [
89
+ $ this ->makeRequest ('http://localhost:8000/test1 ' ),
90
+ $ this ->makeRequest ('http://localhost:8000/test2 ' ),
91
+ ];
92
+
93
+ $ run = new Run ($ startRequests , '::namespace:: ' );
94
+
95
+ $ this ->scheduler ->schedule ($ this ->makeRequest ('http://localhost:8000/test3 ' ));
96
+
97
+ $ this ->engine ->start ($ run );
98
+
99
+ $ this ->assertRouteWasNotCrawled ('/test1 ' );
100
+ $ this ->assertRouteWasNotCrawled ('/test2 ' );
101
+ $ this ->assertRouteWasCrawledTimes ('/test3 ' , 1 );
102
+ }
103
+
83
104
public function testCrawlUrlsReturnedFromParseCallback (): void
84
105
{
85
106
$ parseFunction = static function (Response $ response ) {
@@ -89,6 +110,7 @@ public function testCrawlUrlsReturnedFromParseCallback(): void
89
110
};
90
111
$ run = new Run (
91
112
[$ this ->makeRequest ('http://localhost:8000/test2 ' , $ parseFunction )],
113
+ '::namespace:: ' ,
92
114
);
93
115
94
116
$ this ->engine ->start ($ run );
@@ -108,6 +130,7 @@ public function testCallCorrectParseCallbackForRequest(): void
108
130
};
109
131
$ run = new Run (
110
132
[$ this ->makeRequest ('http://localhost:8000/test1 ' , $ parseCallback )],
133
+ '::namespace:: ' ,
111
134
);
112
135
113
136
$ this ->engine ->start ($ run );
@@ -127,6 +150,7 @@ public function testSendItemsThroughItemPipeline(): void
127
150
];
128
151
$ run = new Run (
129
152
$ startRequests ,
153
+ '::namespace:: ' ,
130
154
itemProcessors: [$ processor ],
131
155
);
132
156
@@ -145,6 +169,7 @@ public function testHandleBothRequestAndItemEmittedFromSameParseCallback(): void
145
169
};
146
170
$ run = new Run (
147
171
[$ this ->makeRequest ('http://localhost:8000/test1 ' , $ parseCallback )],
172
+ '::namespace:: ' ,
148
173
itemProcessors: [$ processor ],
149
174
);
150
175
@@ -163,6 +188,7 @@ public function testRegisterExtensions(): void
163
188
};
164
189
$ run = new Run (
165
190
[$ this ->makeRequest ('http://localhost:8000/test1 ' , $ parseCallback )],
191
+ '::namespace:: ' ,
166
192
extensions: [
167
193
new StatsCollectorExtension ($ logger , new FakeClock ()),
168
194
new LoggerExtension ($ logger ),
@@ -197,6 +223,7 @@ public function testCollectAndReturnScrapedItems(): void
197
223
};
198
224
$ run = new Run (
199
225
[$ this ->makeRequest ('http://localhost:8000/test1 ' , $ parseCallback )],
226
+ '::namespace:: ' ,
200
227
);
201
228
202
229
$ result = $ this ->engine ->collect ($ run );
@@ -228,6 +255,7 @@ public function handleRequest(Request $request): Request
228
255
$ this ->makeRequest ('http://localhost:8000/test3 ' ),
229
256
$ this ->makeRequest ('http://localhost:8000/robots ' ),
230
257
],
258
+ '::namespace:: ' ,
231
259
downloaderMiddleware: [DownloaderMiddlewareAdapter::fromMiddleware ($ middleware )],
232
260
concurrency: 1 ,
233
261
requestDelay: 5 ,
0 commit comments