This repository was archived by the owner on Oct 23, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +89
-27
lines changed Expand file tree Collapse file tree 7 files changed +89
-27
lines changed Original file line number Diff line number Diff line change
1
+ name : Run Tests
2
+
3
+ on :
4
+ push :
5
+ branches :
6
+ - main
7
+ pull_request :
8
+ branches :
9
+ - main
10
+ jobs :
11
+ test :
12
+ runs-on : ubuntu-latest
13
+
14
+ steps :
15
+ - name : Checkout code
16
+ uses : actions/checkout@v3
17
+
18
+ - name : Set up PHP
19
+ uses : shivammathur/setup-php@v2
20
+ with :
21
+ php-version : 8.2
22
+ extensions : mysqli
23
+
24
+ - name : Install Composer dependencies
25
+ working-directory : ./code
26
+ run : composer install --prefer-dist --no-progress
27
+
28
+ - name : Copy .env.example to .env
29
+ working-directory : ./code
30
+ run : cp .env.example .env
31
+
32
+ - name : Generate app key
33
+ working-directory : ./code
34
+ run : php artisan key:generate
35
+
36
+ - name : Run database migrations
37
+ working-directory : ./code
38
+ run : php artisan migrate
39
+
40
+ - name : Run tests
41
+ working-directory : ./code
42
+ run : vendor/bin/phpunit
Original file line number Diff line number Diff line change @@ -15,8 +15,8 @@ Ensure you have Docker and Docker Compose installed on your machine.
15
15
16
16
1 . Clone the repo
17
17
``` sh
18
- git clone https:// github.com/ bumblecoder/tech-task.git
19
- cd tech-task
18
+ git clone git@ github.com: bumblecoder/tech-task-pay .git
19
+ cd tech-task-pay
20
20
cp code/.env.example code/.env
21
21
```
22
22
2 . Build and start the Docker containers:
Original file line number Diff line number Diff line change 12
12
{
13
13
public function __construct (private int $ deviation )
14
14
{
15
- if ($ deviation < 0 || $ deviation > 100 ) {
16
- throw new InvalidArgumentException ('Deviation must be between 0 and 100. ' );
17
- }
18
15
}
19
16
20
17
public function validate (Request $ request , Transaction $ transaction ): bool
21
18
{
19
+ if (!filter_var (
20
+ $ this ->deviation ,
21
+ FILTER_VALIDATE_INT ,
22
+ ['options ' => ['min_range ' => 0 , 'max_range ' => 100 ]]
23
+ )) {
24
+ throw new InvalidArgumentException ('Deviation must be between 0 and 100. ' );
25
+ }
26
+
22
27
if ($ request ->getCurrency () !== $ transaction ->getCurrency ()) {
23
28
return false ;
24
29
}
Original file line number Diff line number Diff line change 123
123
'store ' => env ('APP_MAINTENANCE_STORE ' , 'database ' ),
124
124
],
125
125
126
- 'transaction_deviation ' => env ('TRANSACTION_DEVIATION ' , 5 ),
126
+ 'transaction_deviation ' => ( int ) env ('TRANSACTION_DEVIATION ' , 5 ),
127
127
];
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Tests \Feature ;
6
+
7
+ use Tests \TestCase ;
8
+
9
+ class TransactionControllerTest extends TestCase
10
+ {
11
+ public function test_validate_transaction_success (): void
12
+ {
13
+ $ response = $ this ->getJson ('/validate-transaction ' );
14
+
15
+ $ response ->assertStatus (200 )
16
+ ->assertJson (['isValid ' => false ]);
17
+ }
18
+
19
+ public function test_validate_transaction_invalid_deviation (): void
20
+ {
21
+ config (['app.transaction_deviation ' => 150 ]);
22
+
23
+ $ response = $ this ->getJson ('/validate-transaction ' );
24
+
25
+ $ response ->assertStatus (400 )
26
+ ->assertJson ([
27
+ 'error ' => 'Validation failed ' ,
28
+ 'message ' => 'Deviation must be between 0 and 100. '
29
+ ]);
30
+ }
31
+ }
Original file line number Diff line number Diff line change @@ -45,8 +45,7 @@ public function test_validate_exact_amount(): void
45
45
{
46
46
$ request = Request::create (10000 , 'USD ' );
47
47
$ transaction = Transaction::create (10000 , 'USD ' );
48
-
49
- $ validator = new RequestMoneyValidator (0 );
48
+ $ validator = new RequestMoneyValidator (10 );
50
49
51
50
$ this ->assertTrue ($ validator ->validate ($ request , $ transaction ));
52
51
}
@@ -66,6 +65,10 @@ public function test_negative_deviation_throws_exception(): void
66
65
$ this ->expectException (InvalidArgumentException::class);
67
66
$ this ->expectExceptionMessage ('Deviation must be between 0 and 100. ' );
68
67
68
+ $ request = Request::create (10000 , 'USD ' );
69
+ $ transaction = Transaction::create (9000 , 'USD ' );
69
70
$ validator = new RequestMoneyValidator (-5 );
71
+
72
+ $ validator ->validate ($ request , $ transaction );
70
73
}
71
74
}
You can’t perform that action at this time.
0 commit comments