-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial.txt
90 lines (89 loc) · 4.73 KB
/
tutorial.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
How to Run
php artisan test
php artisan test --testsuite=Feature
php artisan test .\tests\Feature\CategoryTest.php
php artisan test --filter=CategoryTest => ClassName ! FileName
php artisan test --filter=test_example => SpecificFunction
Another Commands:
php artisan migrate --env=testing // change to another env
------------------------------------------------------------------------------------------------
U Can Create your custom testsuite
1- Create your folder in test
2- add folder name in phpunit.xml
<testsuites>
<testsuite name="Smoke">
<directory>tests/Smoke</directory>
</testsuite>
</testsuites>
------------------------------------------------------------------------------------------------
NameConvension [mandatory]
1- NameTest
-> should suffix with (Test)
-> To Run It
=> ex: CategoryTest
2- FunctionName
-> should prefix with (test)
-> snake_case //snake_case,camelCase (allowed) - PascalCase,Kabab-Case (not allowed)
=> ex: test_any_name
------------------------------------------------------------------------------------------------
3A Rule In Testing
- Arrange => Prepare Vars
- Act => Simulate Request
- Assert => Take Output From PHPUnit
------------------------------------------------------------------------------------------------
Create vs. Make
- Make : create users without storing in database => User::factory()->make();
- Create : create users & store in database => User::factory()->create();
------------------------------------------------------------------------------------------------
*********************** Category Test Cases ************************
How to think about test cases: (ex: categories)
- Category Retrieval ( all - pagination - show ) - Categories page
Test That Categories page open successfully
Test That all categories can be retrieved successfully
Test pagination work successfully
- Category Creation & Validation
Test category create page rendered successfully
Test category can be created successfully
Test category name is required
Test category name must be at least 3 characters long
Test category name must be at most 255 characters long
Test category description is optional
Test category description must be at most 1000 characters long
- Category Updating
Test category update page rendered successfully
Test category can be updated successfully
Test category name is required
Test category name must be at least 3 characters long
Test category name must be at most 255 characters long
Test category description is optional
Test category description must be at most 1000 characters long
- Category Deleting
Test that category can be deleted successfully and removed from DB
- Category Permission
Test guest cannot access categories page
Test guest cannot access category creation page test guest cannot store a new category
Test guest cannot access category edit page
Test guest cannot access category show page
Test guest cannot update a category
Test guest cannot delete a category
------------------------------------------------------------------------------------------------
Test Coverage:
how much test cases cover the source code program (ex: 100% test cover 30% project )
------------------------------------------------------------------------------------------------
Test Coverage Tool:
Xdebug:
1- download tool (xdebug.dll)
2- move xdebug.dll file to your php folder "\php-8.3.8-Win32-vs16-x64\ext\xdebug.dll"
3- in your php folder go to php.ini "\php-8.3.8-Win32-vs16-x64\php.ini" at the end of file // relative path => Z://laragon/php/php-8.3.8-Win32-vs16-x64/php.ini
- zend_extension="/php-8.3.8-Win32-vs16-x64/ext/xdebug.dll" // put extension relative path
- xdebug.mode=debug,coverage
- xdebug.start_with_request=yes
- xdebug.client_host=127.0.0.1
- xdebug.client_port=9009
To make sure U install correctly: use in terminal
- php -v
- U will see in last line (with Xdebug v3.4.2, Copyright (c) 2002-2025, by Derick Rethans)
------------------------------------------------------------------------------------------------
Test Coverage Run:
- php artisan test --coverage
- php artisan test --coverage --min=80