Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API testing and JSON validator setup #224

Merged
merged 54 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d23f407
move model tests to models folder
creme332 May 22, 2024
c6b26d8
install guzzle
creme332 May 22, 2024
9fd5f71
add Review model table property, getAll, getAllReviewsForProduct, upd…
Divyeshhhh May 20, 2024
88d6237
rewrite logic for the API to make errors clearer and to reduce code d…
creme332 May 21, 2024
4f404fc
add new API endpoint to retrieve all reviews for a product by ID and …
Divyeshhhh May 21, 2024
c2cccaa
ensure that getAll() and getAllReviewsForProduct() always return array
creme332 May 22, 2024
ee4e111
add getReviewByID, send appropriate errors when review attributes are…
creme332 May 22, 2024
619030c
make $routes relative to API_BASE_URI
creme332 May 22, 2024
c9c6dca
use testing database when request contains X-Test-Env in header
creme332 May 23, 2024
a174e1e
merge changes from main
creme332 May 24, 2024
b6f7e17
change namespace to Steamy\Tests\Model
creme332 May 24, 2024
1e570f3
replace test suite with 2 new ones: models, api
creme332 May 24, 2024
8b9df8e
add namespace for tests, add new scripts for testing testsuites
creme332 May 24, 2024
255912a
add tests for product endpoint of api
creme332 May 24, 2024
b9b0b02
remove unnecessary call to parent setUp in setUp since class has no p…
creme332 May 24, 2024
33ecd02
use 2 separate env files for production and testing
creme332 May 24, 2024
9020c00
update docs based on new tests structure
creme332 May 24, 2024
c8a64b0
rename folder to schemas
creme332 May 25, 2024
dc43848
disallow additional properties
creme332 May 25, 2024
3074f9e
use json validation in createProduct
creme332 May 25, 2024
826bcb4
new schema structure
creme332 May 25, 2024
ff15818
merge creme332:main and fix merge conflicts
creme332 Jun 2, 2024
b99a556
remove incorrectly merged file
creme332 Jun 2, 2024
310b6c6
fix empty array bug in getAll
creme332 Jun 2, 2024
d61d650
move faker to dev dependency
creme332 Jun 2, 2024
6469c91
update versions so that php 8.1 is enough
creme332 Jun 2, 2024
c98a341
create a test helper trait
creme332 Jun 2, 2024
702c0d8
use new test helper
creme332 Jun 2, 2024
5309764
add new methods and make tests more random
creme332 Jun 2, 2024
ff2b58d
add note on modifying css/js files
creme332 Jun 2, 2024
e41bf27
use helper functions from TestHelper
creme332 Jun 2, 2024
ed5e71c
remove transaction from resetDatabase
creme332 Jun 2, 2024
97ebdd8
create an APIHelper trait
creme332 Jun 2, 2024
45b1acc
use test helpers
creme332 Jun 2, 2024
3656517
remove getAllReviewsForProduct since it is already present in product…
creme332 Jun 2, 2024
c2fd70a
remove irrelevant todo
creme332 Jun 2, 2024
bb32665
fix issues
creme332 Jun 5, 2024
5633717
update acceptable img extensions in validate
creme332 Jun 5, 2024
b75f50e
add log_json
creme332 Jun 5, 2024
6691f61
remove unused import
creme332 Jun 5, 2024
91fcb41
fix bug in createProduct
creme332 Jun 5, 2024
5239abd
complete testCreateValidProduct and testDeleteProductById
creme332 Jun 5, 2024
93a15b2
create and use a helper method to validate data against schema
creme332 Jun 5, 2024
0ad6027
complete updateProduct and getAllReviewsForProduct
creme332 Jun 5, 2024
2c8974d
fix file path bug in validateAgainstSchema
creme332 Jun 5, 2024
c01adc1
add schema for updating products
creme332 Jun 5, 2024
063ddff
reset database both before and after test suite
creme332 Jun 5, 2024
6e2e57e
complete testUpdateProductById
creme332 Jun 5, 2024
ef51a85
add option to not save fake product and client to database
creme332 Jun 5, 2024
c1ae17c
rework testGetById
creme332 Jun 5, 2024
6087356
add better tests for updateProductById
creme332 Jun 6, 2024
4fb5fcd
fix bug where latitude=0 or longitude=0 caused error
creme332 Jun 6, 2024
61fcf48
run only model test suite
creme332 Jun 6, 2024
bbebed9
create .env.testing file
creme332 Jun 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,17 @@ jobs:
mysql -u$DB_USER -p$DB_PASSWORD -hlocalhost -P3306 -Dcafe_test < "resources/database/cafe_test_data.sql"
mysql -e "USE cafe_test; SHOW TABLES;" -u$DB_USER -p$DB_PASSWORD

- name: Create .env file
- name: Create .env.testing file
env:
ENV: |
PUBLIC_ROOT="http://localhost/steamy-sips/public"
DB_HOST="localhost"
DB_USERNAME="root"
DB_PASSWORD="root"
TEST_DB_NAME="cafe_test"
BUSINESS_GMAIL=""
BUSINESS_GMAIL_PASSWORD=""
ENV: |
DB_HOST="localhost"
DB_USERNAME="root"
DB_PASSWORD="root"
DB_NAME="cafe_test"
API_BASE_URI="http://steamy.localhost/api/v1/"
run: |
echo "$ENV" > .env
cat .env
echo "$ENV" > .env.testing
cat .env.testing

- name: Validate composer.json and composer.lock
run: composer validate --strict
Expand All @@ -66,5 +64,5 @@ jobs:
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: composer test
- name: Run model test suite
run: composer modeltest
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/vendor/
.vscode
.idea
.env
node_modules
.phpunit.result.cache
public/js

.env
.env.testing
16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,4 @@ Attribution-ShareAlike
- https://youtu.be/q0JhJBYi4sw?si=cTdEzzGijlG41ix8
- https://github.com/kevinisaac/php-mvc
4. The filesystem was inspired by https://github.com/php-pds/sklseleton
5. Additional references are included within the code itself.

# Todo

Add `X-TEST-ENV` to the header of your request and set its value to `testing` if you want to use the testing database.
This is required when running tests for API. Without this key-value pair, the production database will be used.

USE DOCKER PHP

- read guzzle documentation. read base_uri
- test database is being used
- add variable to .env

line 18 in Reviews API is redundant
use correct namespace
5. Additional references are included within the code itself.
16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,28 @@
"vlucas/phpdotenv": "^5.6",
"phpmailer/phpmailer": "^6.9",
"opis/json-schema": "^2.3",
"nesbot/carbon": "^3.3",
"fakerphp/faker": "^1.23"
"nesbot/carbon": "^3.3"
},
"scripts": {
"test": "phpunit tests"
"test": "phpunit tests",
"modeltest": "phpunit --testsuite models",
"apitest": "phpunit --testsuite api"
},
"autoload": {
"psr-4": {
"Steamy\\": "src/",
"Steamy\\Core\\": "src/core/",
"Steamy\\Controller\\": "src/controllers/",
"Steamy\\Controller\\API\\": "src/controllers/api/",
"Steamy\\Model\\": "src/models/"
"Steamy\\Model\\": "src/models/",
"Steamy\\Tests\\": "tests/",
"Steamy\\Tests\\Model\\": "tests/models/",
"Steamy\\Tests\\Api\\": "tests/api/"
}
},
"require-dev": {
"phpunit/phpunit": "^10.5"
"phpunit/phpunit": "^10.5",
"guzzlehttp/guzzle": "^7.0",
"fakerphp/faker": "^1.23"
}
}
Loading