- All Unit Tests MUST be placed inside the
tests/Unit
folder - All Integration Test MUST be placed inside the
tests\Feature
folder - Contents of the
Unit
andFeature
folders MUST have the same structure with the mainapp
folder. For example, unit tests for fileapp/Models/User.php
MUST be written intests/Unit/Models/UserTest.php
- Each test file MUST have a specific namespace. The namespace MUST start with
Tests\
(orASampleProjectTests\
), then followed by the folder structure. For example, namespace fortests/Unit/Models/UserTest.php
file MUST beTests\Unit\Models\UserTest
(orASampleProjectTests\Unit\Models\UserTest
) - For better readability, use
snake_case
for test function's name. A test function has to start withtest
, so here is an example:
public function test_it_throws_an_exception_when_email_is_too_long()
{
}
- Non-test function can stick with PSR-2 rule, that uses
camelCase
for function name.
- Controllers: with disabled events handling. All external components MUST be mocked.
- Requests (if present): test validation
- Models: getters, setters, additional features
- Transformers / Presenters (if present): test output results for different source sets
- Repositories (if present): test each method for creating correct SQL queries OR correct calls to mocked query builder
- Event listeners
- Queue jobs
- Auth policies
- And any additional project-specific classes
- Routes: test input/output with integration in a whole system
- Route authentication
- Code Coverage for Model SHOULD be greater than
95%
- Code Coverage for the entire project SHOULD be greater than
80%