git clone https://github.com/Shaykhnazar/olx-price-monitor.git
In the root directory of the project, create a .env
file and set the following environment variables:
cp .env.example .env
And set the following environment variables in the .env
file:
DB_HOST=db
DB_NAME=olx_price_monitor
DB_USER=olx_user
DB_PASS=olx_secret
SMTP_HOST=sandbox.smtp.mailtrap.io
SMTP_PORT=2525
SMTP_USER=user
SMTP_PASS=password
[email protected]
SMTP_NAME="OLX Price Monitor"
[email protected]
docker-compose up -d
docker-compose exec db bash
mysql -u root -p
Enter the password you set in MYSQL_ROOT_PASSWORD (e.g., "secret").
List databases:
SHOW DATABASES;
You should see olx_price_monitor in the list.
List tables:
SHOW TABLES;
List subscriptions:
SELECT * FROM subscriptions;
Example:
$ mysql -u root -p
Enter password: ********
mysql> USE olx_price_monitor;
Database changed
mysql> SHOW TABLES;
+---------------------+
| Tables_in_database |
+---------------------+
| subscriptions |
+---------------------+
1 row in set (0.00 sec)
mysql> exit;
Bye
The Postman collection is available at olx-price-monitor.postman_collection.json.
- Import the collection into Postman.
- Open the collection in Postman.
- Subscribe to an ad using the "Subscribe" endpoint.
/subscribe
- Confirm your subscription using the "Confirm" endpoint.
/confirm?token={token}
Execute the entire test suite:
vendor/bin/phpunit
To run tests from a specific file, provide the path:
vendor/bin/phpunit tests/SubscriptionTest.php
To run a specific test method (e.g., testCreateSubscription), use the --filter option:
vendor/bin/phpunit --filter testCreateSubscription tests/SubscriptionTest.php
Use --testdox for a more human-readable output:
vendor/bin/phpunit --testdox
Result:
The price checking is done via cron job, so it should work as expected.
Every 1 hour
, the cron job will check the price of the ad and send an email notification if the price has changed.
Using voku/simple_html_dom
package. We can get the price from the web page.
And we get the price of the ad via the parser like this. This is to display for testing purpose only.