Php script that loads relational data from tab delimited files, and returns some queries against the loaded data.
Docker provides a portable and predictable build environment for the Php script. It provides Php 7.1.10 with Sqlite and Composer.
Although this library does not require any external dependencies to run, Composer is still used for it's standard PSR-4 compliant autoloader. It also is used to install phpunit.
The included data files are small enough where the answers could be derived quickly without an external database. Sqlite is included as an in-memory database because it makes the intent of the code more clear and concise.
# Build base image
docker build --rm --tag local .
# Run unit tests
docker run local php vendor/bin/phpunit --configuration tests/phpunit.config.xml
# Run program
docker run local
Provided that you've already got Php 7 and Sqlite installed, you can run this package without Docker.
# Build
php composer.phar install
# Run tests
run local php vendor/bin/phpunit --configuration tests/phpunit.config.xml
# Run script
php index.php
The coding exercise solution is also provided in a single, dependency-less script: the-quick-and-dirty-way.php
. All you need is php5.4 (or greater).
php the-quick-and-dirty-way.php
Given the checked in data files, this program will output the following.
$ docker run local
What category has the highest average sales price? (Please include the average sale price)?
Category: Frozen Foods
Price: 97.61760473
What is the minimum and maximum sale in the category 'Breakfast'?
Min: 5.706340914
Max: 97.71513391