-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathManagerTest.php
More file actions
91 lines (73 loc) · 3.01 KB
/
Copy pathManagerTest.php
File metadata and controls
91 lines (73 loc) · 3.01 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace SplitIO\Test;
use SplitIO\ThinSdk\Manager;
use SplitIO\ThinSdk\SplitView;
use SplitIO\ThinSdk\Link\Consumer\Manager as LinkManager;
use Psr\Log\LoggerInterface;
use PHPUnit\Framework\TestCase;
class ManagerTest extends TestCase
{
private $logger;
public function setUp(): void
{
$this->logger = $this->createStub(LoggerInterface::class);
}
public function testSplitNamesOk()
{
$lm = $this->createMock(LinkManager::class);
$lm->expects($this->once())->method('splitNames')
->with()
->willReturn(['s1', 's2']);
$manager = new Manager($lm, $this->logger);
$this->assertEquals(['s1', 's2'], $manager->splitNames());
}
public function testSplitNamesReturnsEmptyOnException()
{
$lm = $this->createMock(LinkManager::class);
$lm->expects($this->once())->method('splitNames')
->will($this->throwException(new \Exception('sarasa')));
$manager = new Manager($lm, $this->logger);
$this->assertEquals([], $manager->splitNames());
}
public function testSplitOk()
{
$lm = $this->createMock(LinkManager::class);
$lm->expects($this->once())->method('split')
->with('s1')
->willReturn(new SplitView('s1', 'tt', true, ['on', 'off'], 123, 'on', ['set_1', 'set_2'], ['on' => 'frula']));
$manager = new Manager($lm, $this->logger);
$this->assertEquals(new SplitView('s1', 'tt', true, ['on', 'off'], 123, 'on', ['set_1', 'set_2'], ['on' => 'frula']), $manager->split('s1'));
}
public function testSplitReturnNullOnException()
{
$lm = $this->createMock(LinkManager::class);
$lm->expects($this->once())->method('split')
->with('s1')
->will($this->throwException(new \Exception('sarasa')));
$manager = new Manager($lm, $this->logger);
$this->assertEquals(null, $manager->split('s1'));
}
public function testSplitsOk()
{
$lm = $this->createMock(LinkManager::class);
$lm->expects($this->once())->method('splits')
->with()
->willReturn([
new SplitView('s1', 'tt', true, ['on', 'off'], 123, 'on', ['set_1', 'set_2'], ['on' => 'frula']),
new SplitView('s2', 'tt', false, ['on', 'off'], 124, 'off', [], ['on' => 'frula']),
]);
$manager = new Manager($lm, $this->logger);
$this->assertEquals([
new SplitView('s1', 'tt', true, ['on', 'off'], 123, 'on', ['set_1', 'set_2'], ['on' => 'frula']),
new SplitView('s2', 'tt', false, ['on', 'off'], 124, 'off',[], ['on' => 'frula']),
], $manager->splits());
}
public function testSplitsReturnsEmptyOnException()
{
$lm = $this->createMock(LinkManager::class);
$lm->expects($this->once())->method('splits')
->will($this->throwException(new \Exception('sarasa')));
$manager = new Manager($lm, $this->logger);
$this->assertEquals([], $manager->splits());
}
}