-
-
Notifications
You must be signed in to change notification settings - Fork 289
Add quickstarts for slim php framework with mongodb, mysql and postgresql #784
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
Open
swastikiscoding
wants to merge
4
commits into
keploy:main
Choose a base branch
from
swastikiscoding:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
10e598d
add PHP Slim` + MySQL quickstart documentation
swastikiscoding ce8d1c0
add documentation for PHP Slim with PostgreSQL and MongoDB quickstart…
swastikiscoding 218e850
fix(docs): update Docker Compose commands for MongoDB, MySQL, and Pos…
swastikiscoding ce5fa18
Merge branch 'main' into main
swastikiscoding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
239 changes: 239 additions & 0 deletions
239
versioned_docs/version-4.0.0/quickstart/php-slim-mongodb.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,239 @@ | ||
| --- | ||
| id: samples-php-mongodb | ||
| title: PHP Sample Application (MongoDB) | ||
| sidebar_label: PHP - Slim + MongoDB | ||
| description: The following sample app showcases how to use PHP Slim framework with MongoDB and the Keploy Platform. | ||
| tags: | ||
| - php | ||
| - quickstart | ||
| - samples | ||
| - examples | ||
| - tutorial | ||
| keyword: | ||
| - PHP Framework | ||
| - MongoDB | ||
| - Slim | ||
| - API Test generator | ||
| - Auto Testcase generation | ||
| --- | ||
|
|
||
| import InstallReminder from '@site/src/components/InstallReminder'; | ||
|
|
||
| import SectionDivider from '@site/src/components/SectionDivider'; | ||
|
|
||
| ## Using Docker Compose 🐳 | ||
|
|
||
| A simple sample CRUD Books API application and see how seamlessly Keploy integrates with PHP Slim and MongoDB. Buckle up, it's gonna be a fun ride! 🎢 | ||
|
|
||
| <InstallReminder /> | ||
|
|
||
| ### Get Started! 🎬 | ||
|
|
||
| Clone the repository and move to slim-mongodb folder | ||
|
|
||
| ```bash | ||
| git clone https://github.com/swastikiscoding/samples-php.git && cd samples-php/slim-mongodb | ||
| ``` | ||
|
|
||
| We will be using Docker compose to run the application as well as MongoDB on Docker container. | ||
|
|
||
| ### Lights, Camera, Record! 🎥 | ||
|
|
||
| First, let's set up the environment and start recording. Keep an eye on the key flags: | ||
| `-c`: Command to run the app (e.g., `docker compose up`). | ||
|
|
||
| `--container-name`: The container name in the `docker-compose.yml` for traffic interception. | ||
|
|
||
| ```bash | ||
| # Create network | ||
| docker network create keploy-network | ||
|
|
||
| # Start MongoDB database | ||
| docker compose up mongodb -d | ||
|
|
||
| # Build the application | ||
| docker compose build app | ||
|
|
||
| # Start recording with Keploy | ||
| keploy record -c "docker compose up app" --container-name "slim-mongodb-app-1" -n keploy-network | ||
| ``` | ||
|
|
||
| 🔥 Challenge time! Generate some test cases. How? Just **make some API calls**. Postman, Hoppscotch or even curl - take your pick! | ||
|
|
||
| #### Let's generate the testcases. | ||
|
|
||
| Make API Calls using Postman or cURL command. Keploy will capture those calls to generate the test-suites containing testcases and data mocks. | ||
|
|
||
| ```bash | ||
| curl -X POST http://localhost:8080/api/books \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"title": "The Go Programming Language", "author": "Alan Donovan", "price": 44.99}' | ||
| ``` | ||
|
|
||
| Here's a peek of what you get: | ||
|
|
||
| ```json | ||
| {"title":"The Go Programming Language","author":"Alan Donovan","price":44.99,"id":"507f1f77bcf86cd799439011"} | ||
| ``` | ||
|
|
||
| > **Note**: MongoDB uses ObjectId format for IDs (e.g., `507f1f77bcf86cd799439011`). Copy the `id` from the POST response to use in subsequent requests. | ||
|
|
||
| 🎉 Woohoo! With a simple API call, you've crafted a test case with a mock! Dive into the Keploy directory and feast your eyes on the newly minted `test-1.yml` and `mocks.yml` | ||
|
|
||
| _Time to perform more API magic!_ | ||
| Follow the breadcrumbs... or Make more API Calls | ||
|
|
||
| ```bash | ||
| # Create more books | ||
| curl -X POST http://localhost:8080/api/books \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"title": "Clean Code", "author": "Robert C. Martin", "price": 39.99}' | ||
|
|
||
| # Get all books | ||
| curl http://localhost:8080/api/books | ||
|
|
||
| # Get a specific book (replace <BOOK_ID> with actual ID from previous response) | ||
| curl http://localhost:8080/api/books/<BOOK_ID> | ||
|
|
||
| # Update a book (replace <BOOK_ID> with actual ID) | ||
| curl -X PUT http://localhost:8080/api/books/<BOOK_ID> \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"title": "The Go Programming Language", "author": "Alan Donovan & Brian Kernighan", "price": 49.99}' | ||
|
|
||
| # Delete a book (replace <BOOK_ID> with actual ID) | ||
| curl -X DELETE http://localhost:8080/api/books/<BOOK_ID> | ||
| ``` | ||
|
|
||
| Did you spot the new test and mock scrolls in your project library? Awesome! 👏 | ||
|
|
||
| ### Run Tests | ||
|
|
||
| Time to put things to the test 🧪 | ||
|
|
||
| ```bash | ||
| # Stop any running containers | ||
| docker compose down | ||
|
|
||
| # Run Keploy tests | ||
| keploy test -c "docker compose up app" --container-name "slim-mongodb-app-1" -n keploy-network --delay 10 | ||
| ``` | ||
|
|
||
| > The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking. | ||
|
|
||
| ### Wrapping it up 🎉 | ||
|
|
||
| Congrats on the journey so far! You've seen Keploy's power, flexed your coding muscles, and had a bit of fun too! Now, go out there and keep exploring, innovating, and creating! Remember, with the right tools and a sprinkle of fun, anything's possible.😊🚀 | ||
|
|
||
| Happy coding! ✨👩💻👨💻✨ | ||
|
|
||
| <SectionDivider /> | ||
|
|
||
| ## Running App Locally on Linux/WSL 🐧 | ||
|
|
||
| A simple sample CRUD Books API application and see how seamlessly Keploy integrates with PHP Slim and MongoDB. Buckle up, it's gonna be a fun ride! 🎢 | ||
|
|
||
| <InstallReminder /> | ||
|
|
||
| ### Get Started! 🎬 | ||
|
|
||
| Clone the repository and move to slim-mongodb folder | ||
|
|
||
| ```bash | ||
| git clone https://github.com/swastikiscoding/samples-php.git && cd samples-php/slim-mongodb | ||
|
|
||
| # Install the dependencies | ||
| composer install | ||
| ``` | ||
|
|
||
| We'll be running our sample application right on Linux, but just to make things a tad more thrilling, we'll have the database (MongoDB) chill on Docker. Ready? Let's get the party started!🎉 | ||
|
|
||
| If you are using WSL on windows then use below to start wsl in the user's home directory: | ||
|
|
||
| ```bash | ||
| wsl ~ | ||
| ``` | ||
|
|
||
| #### 🍃 Kickstart MongoDB | ||
|
|
||
| We are going to run a MongoDB docker container which requires an existing docker network. We need to run the following command to create the required docker network: | ||
|
|
||
| ```bash | ||
| docker network create keploy-network | ||
| ``` | ||
|
|
||
| Now, let's breathe life into your MongoDB container. A simple spell should do the trick: | ||
|
|
||
| ```bash | ||
| docker compose up mongodb -d | ||
|
||
| ``` | ||
|
|
||
| #### Configure Environment | ||
|
|
||
| Set up the database connection environment variables: | ||
|
|
||
| ```bash | ||
| export MONGO_URI=mongodb://localhost:27017 | ||
| export DB_NAME=booksdb | ||
| ``` | ||
|
|
||
| ### 📼 Roll the Tape - Recording Time! | ||
|
|
||
| Ready, set, record! Here's how: | ||
|
|
||
| ```bash | ||
| sudo -E env PATH=$PATH keploy record -c 'php -S localhost:8080 -t public' | ||
| ``` | ||
|
|
||
| Keep an eye out for the `-c` flag! It's the command charm to run the app. | ||
|
|
||
| Alright, magician! With the app alive and kicking, let's weave some test cases. The spell? Making some API calls! Postman, Hoppscotch, or the classic curl - pick your wand. | ||
|
|
||
| #### Let's generate the testcases. | ||
|
|
||
| Make API Calls using Postman or cURL command. Keploy will capture those calls to generate the test-suites containing testcases and data mocks. | ||
|
|
||
| ```bash | ||
| curl -X POST http://localhost:8080/api/books \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"title": "The Go Programming Language", "author": "Alan Donovan", "price": 44.99}' | ||
| ``` | ||
|
|
||
| Here's a peek of what you get: | ||
|
|
||
| ```json | ||
| {"title":"The Go Programming Language","author":"Alan Donovan","price":44.99,"id":"507f1f77bcf86cd799439011"} | ||
| ``` | ||
|
|
||
| 🎉 Woohoo! Give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **Keploy directory** and you'll discover your handiwork in `test-1.yml` and `mocks.yml`. | ||
|
|
||
| Now, the real fun begins. Let's weave more spells! | ||
|
|
||
| 🚀 Follow the URL road...! | ||
|
|
||
| ```bash | ||
| # Get all books | ||
| curl http://localhost:8080/api/books | ||
|
|
||
| # Create another book | ||
| curl -X POST http://localhost:8080/api/books \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{"title": "Clean Code", "author": "Robert C. Martin", "price": 39.99}' | ||
| ``` | ||
|
|
||
| Or simply wander over to your browser and visit `http://localhost:8080/api/books`. | ||
|
|
||
| Did you spot the new test and mock scrolls in your project library? Awesome! 👏 | ||
|
|
||
| ### Run Tests 🏁 | ||
|
|
||
| Ready to put your spells to the test? | ||
|
|
||
| ```bash | ||
| sudo -E env PATH=$PATH keploy test -c "php -S localhost:8080 -t public" --delay 10 | ||
| ``` | ||
|
|
||
| ### Wrapping it up 🎉 | ||
|
|
||
| Congrats on the journey so far! You've seen Keploy's power, flexed your coding muscles, and had a bit of fun too! Now, go out there and keep exploring, innovating, and creating! Remember, with the right tools and a sprinkle of fun, anything's possible.😊🚀 | ||
|
|
||
| Happy coding! ✨👩💻👨💻✨ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with other quickstarts in this repo, consider using the more common Compose flag ordering (
docker compose up -d <service>). The current form (docker compose up <service> -d) is inconsistent with the rest of the docs; please update this and the other occurrence later in the page as well.