-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathTaskTest.php
More file actions
76 lines (59 loc) · 1.72 KB
/
TaskTest.php
File metadata and controls
76 lines (59 loc) · 1.72 KB
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
<?php
namespace Utopia\Tests;
use PHPUnit\Framework\TestCase;
use Utopia\CLI\Task;
use Utopia\Validator\Text;
class TaskTest extends TestCase
{
/**
* @var Task
*/
protected $task;
public function setUp(): void
{
$this->task = new Task('test');
}
public function tearDown(): void
{
$this->task = null;
}
public function testName()
{
$this->assertEquals('test', $this->task->getName());
}
public function testDescription()
{
$this->task->desc('test task');
$this->assertEquals('test task', $this->task->getDesc());
}
public function testAction()
{
$this->task->action(function () {
return 'result';
});
$this->assertEquals('result', $this->task->getAction()());
}
public function testLabel()
{
$this->task->label('key', 'value');
$this->assertEquals('value', $this->task->getLabel('key', 'default'));
$this->assertEquals('default', $this->task->getLabel('unknown', 'default'));
}
public function testParam()
{
$this->task->param('email', 'me@example.com', new Text(0), 'Param with valid email address', false);
$this->assertCount(1, $this->task->getParams());
}
public function testResources()
{
$this->assertEquals([], $this->task->getInjections());
$this->task
->inject('user')
->inject('time')
->action(function () {
});
$this->assertCount(2, $this->task->getInjections());
$this->assertEquals('user', $this->task->getInjections()['user']['name']);
$this->assertEquals('time', $this->task->getInjections()['time']['name']);
}
}