Please ensure you have composer installed and are running PHP 7.0+
php composer-setup.php
Then install the dependencies:
./composer.phar install
Alternatively, if you have docker installed, build and run the container
docker build -t scraper . && docker run --rm scraper
Unit tests:
./bin/phpspec run
php scraper.php
Is a facade with a single static method for building a version of the app with dependencies already injected.
The GroceryApp depends on two interfaces, the ProductPageParser
and the ProductCollectionSerializer
Is responsible for taking a product listing page url, reading the contents and returning a ProductCollection
model.
The implementation ProductPageDomCrawler
has a dependency on the HttpClient
interface which it uses to fetch
the listing page and subsequent product pages. Page contents are parsed using the Symfony DomCrawler component.
Is responsible for fetching a URL and returning the page body as a string.
The implementation GuzzleHttpClient
wraps the Guzzle library to do this.
Is responsible for taking a ProductCollection
model and converting it to the desired output format.
The implementation ProductCollectionToJson
wraps PHP's built in json_encode
function to generate
JSON output for this task.