Skip to content

Commit 6d892d6

Browse files
Add unit tests for PythonTarget and PhpTarget classes.
These tests ensure correct exception handling, property access, and default values for PythonTarget, alongside basic property access and conversion functionality for PhpTarget. This commit increases test coverage and reliability for these target classes.
1 parent 37bbda8 commit 6d892d6

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use UnitPhpSdk\Config\Application\Targets\PhpTarget;
4+
5+
it('sets and gets the script correctly', function () {
6+
$data = ['root' => '/var/www', 'script' => 'main.php'];
7+
$phpTarget = new PhpTarget($data);
8+
9+
expect($phpTarget->getScript())->toBe('main.php');
10+
});
11+
12+
it('sets and gets the index correctly', function () {
13+
$data = ['root' => '/var/www', 'index' => 'home.php'];
14+
$phpTarget = new PhpTarget($data);
15+
16+
expect($phpTarget->getIndex())->toBe('home.php');
17+
});
18+
19+
it('sets and gets the root correctly', function () {
20+
$data = ['root' => '/var/www'];
21+
$phpTarget = new PhpTarget($data);
22+
23+
expect($phpTarget->getRoot())->toBe('/var/www');
24+
});
25+
26+
it('converts the object to array correctly', function () {
27+
$data = ['root' => '/var/www', 'script' => 'main.php', 'index' => 'home.php'];
28+
$phpTarget = new PhpTarget($data);
29+
30+
expect($phpTarget->toArray())->toBe($data);
31+
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
use UnitPhpSdk\Config\Application\Targets\PythonTarget;
4+
use UnitPhpSdk\Exceptions\RequiredKeyException;
5+
6+
it('throws RequiredKeyException when module is not provided', function () {
7+
$data = ['callable' => 'main'];
8+
$this->expectException(RequiredKeyException::class);
9+
$this->expectExceptionMessage('module');
10+
11+
new PythonTarget($data);
12+
});
13+
14+
it('sets and gets the module correctly', function () {
15+
$data = ['module' => 'app.module'];
16+
$pythonTarget = new PythonTarget($data);
17+
18+
expect($pythonTarget->getModule())->toBe('app.module');
19+
});
20+
21+
it('sets and gets the callable correctly', function () {
22+
$data = ['module' => 'app.module', 'callable' => 'main'];
23+
$pythonTarget = new PythonTarget($data);
24+
25+
expect($pythonTarget->getCallable())->toBe('main');
26+
});
27+
28+
it('uses default callable when not provided', function () {
29+
$data = ['module' => 'app.module'];
30+
$pythonTarget = new PythonTarget($data);
31+
32+
expect($pythonTarget->getCallable())->toBe('application');
33+
});
34+
35+
it('converts the object to array correctly', function () {
36+
$data = ['module' => 'app.module', 'callable' => 'main'];
37+
$pythonTarget = new PythonTarget($data);
38+
39+
expect($pythonTarget->toArray())->toBe($data);
40+
});

0 commit comments

Comments
 (0)