-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCLITest.php
More file actions
67 lines (50 loc) · 1.54 KB
/
CLITest.php
File metadata and controls
67 lines (50 loc) · 1.54 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
<?php
namespace Utopia\Tests;
use PHPUnit\Framework\TestCase;
use Utopia\CLI\Adapters\Generic;
use Utopia\CLI\CLI;
use Utopia\DI\Container;
use Utopia\Platform\Service;
class CLITest extends TestCase
{
public function setUp(): void
{
}
public function tearDown(): void
{
}
public function testCLISetup()
{
ob_start();
$cli = new CLI(new Generic(), ['test.php', 'build', '--email=me@example.com', '--list=item1', '--list=item2']); // Mock command request
$platform = new TestPlatform();
$platform->setCli($cli);
$platform->init(Service::TYPE_TASK);
$cli = $platform->getCli();
$cli->run();
$result = ob_get_clean();
$this->assertEquals('me@example.com-item1-item2', $result);
$this->assertCount(3, $cli->getTasks());
}
public function testCLISetupWithProvidedContainer()
{
$argv = $_SERVER['argv'] ?? [];
try {
$_SERVER['argv'] = ['test.php', 'inject'];
ob_start();
$container = new Container();
$container->set('test', fn () => 'test-value');
$platform = new TestPlatform();
$platform->init(Service::TYPE_TASK, [
'adapter' => new Generic(),
'container' => $container,
]);
$cli = $platform->getCli();
$cli->run();
$result = ob_get_clean();
} finally {
$_SERVER['argv'] = $argv;
}
$this->assertEquals('test-value', $result);
}
}