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.
Hello Mostafa,
Congratulations on your project and your journey. Very good project presentation!
I got to know about you in Laravel Daily and wanted to contribute with your project.
There are some interesting changes on this Pull Request: #1. Do you know how what Pull Requests are and how to manage them? If not, just comment!
My Pull Request is about automated tests.
Tests can be a controversial topic, people have their own opinion about it. Me, myself, I wish I was introduced to testing in my first day, when I started as a developer.
I believe tests save time, headache, improve quality and makes maintenance easier.
It is virtually impossible for you to test different things every time you make a change in your application. How do you know if your new code did not break some other feature? We do not have time to test every single page or rule of our applications when new code is added.
For this, we have automated tests.
My approach is to test whatever is critical to my application. For example, if I have a blog system, I want to make sure a user can create, update, view, and delete a post. I want to guarantee that guests cannot create posts or view admin pages.
These are the tests I would start to write, and I did write some of
These are the tests currently running in your application. I have created the PostTest and RouteTest.
My test framework of choice is Pest PHP.
To run tests, you can type
./vendor/bin/pest
in your Terminal (orcomposer test
).Green tests mean everything is okay, yellow is skipped and red is a failed test.
For example,
This test visits your home page and verifies that it loads.
(Status 200 means OK, page loads)
According to your rule, only the user
MooseS94
can access the Dashboard.As mentioned in the PR #1, this logic could/should be modified, but let's say this is the final objective.
I wrote a test for that:
In the test above, we verified that a user
random1234
will not be able to access the Dashboard.And in the next test, we verified that
MooseS94
can do it.Now, how can you make sure these tests are working?
Just for an exercise, modify your
MustBeAdmin
middleware to:Now, only
dansysanalyst
can access the Dashboard, but the test is written to verify ifMooseS94
can do it.So, it will make your test fail:
You can follow this playlist to see a bit more about tests:
https://www.youtube.com/watch?v=gTU-y6HlmzU&list=PLNXrjfSe7qHncCyQYOqJBTsTbYPotMaZ8&ab_channel=MichaelDyrynda
I wish you the all best,
Greetings
Dan