Skip to content

Commit 91d0514

Browse files
committed
Added tests
1 parent 2f833d6 commit 91d0514

2 files changed

Lines changed: 40 additions & 8 deletions

File tree

test/Unit/Network/RouterTest.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,50 @@ public function testGet()
5959
/**
6060
* @covers OpCacheGUI\Network\Router::__construct
6161
* @covers OpCacheGUI\Network\Router::run
62+
* @covers OpCacheGUI\Network\Router::getMainPage
6263
*/
63-
public function testRunNoMatch()
64+
public function testRunNoMatchFirstMatchMain()
6465
{
6566
$requestMock = $this->getMock('\\OpCacheGUI\\Network\\RequestData');
6667
$requestMock->method('getVerb')->willReturn('GET');
6768
$requestMock->method('path')->willReturn('somepath');
6869

70+
$routeMock = $this->getMockBuilder('\\OpCacheGUI\\Network\\Route')->disableOriginalConstructor()->getMock();
71+
$routeMock->method('matchesRequest')->will($this->onConsecutiveCalls(false, true));
72+
$routeMock->method('run')->willReturn('main route');
73+
74+
$factoryMock = $this->getMock('\\OpCacheGUI\\Network\\RouteBuilder');
75+
$factoryMock->method('build')->willReturn($routeMock);
76+
77+
$router = new Router($requestMock, $factoryMock);
78+
$router->get('id', function () {});
79+
80+
$this->assertSame('main route', $router->run());
81+
}
82+
83+
/**
84+
* @covers OpCacheGUI\Network\Router::__construct
85+
* @covers OpCacheGUI\Network\Router::run
86+
* @covers OpCacheGUI\Network\Router::getMainPage
87+
*/
88+
public function testRunNoMatchSecondMatchMain()
89+
{
90+
$requestMock = $this->getMock('\\OpCacheGUI\\Network\\RequestData');
91+
$requestMock->method('getVerb')->willReturn('GET');
92+
$requestMock->method('path')->willReturn('somepath');
93+
94+
$routeMock = $this->getMockBuilder('\\OpCacheGUI\\Network\\Route')->disableOriginalConstructor()->getMock();
95+
$routeMock->method('matchesRequest')->will($this->onConsecutiveCalls(false, false, false, true));
96+
$routeMock->method('run')->willReturn('main route');
97+
6998
$factoryMock = $this->getMock('\\OpCacheGUI\\Network\\RouteBuilder');
99+
$factoryMock->method('build')->willReturn($routeMock);
70100

71101
$router = new Router($requestMock, $factoryMock);
102+
$router->get('id', function () {});
103+
$router->post('id', function () {});
72104

73-
$this->assertSame('No route matches', $router->run());
105+
$this->assertSame('main route', $router->run());
74106
}
75107

76108
/**

test/Unit/OpCache/StatusTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function testGetGraphMemoryInfo()
152152
$data = [
153153
[
154154
'value' => $this->statusData['memory_usage']['used_memory'],
155-
'color' => '#e74c3c',
155+
'color' => '#16a085',
156156
'label' => 'Used',
157157
],
158158
[
@@ -162,7 +162,7 @@ public function testGetGraphMemoryInfo()
162162
],
163163
[
164164
'value' => $this->statusData['memory_usage']['wasted_memory'],
165-
'color' => '#16a085',
165+
'color' => '#e74c3c',
166166
'label' => 'Wasted',
167167
],
168168
];
@@ -280,7 +280,7 @@ public function testGetGraphKeyStatsInfo()
280280
$data = [
281281
[
282282
'value' => 38,
283-
'color' => '#e74c3c',
283+
'color' => '#16a085',
284284
'label' => 'Used',
285285
],
286286
[
@@ -290,7 +290,7 @@ public function testGetGraphKeyStatsInfo()
290290
],
291291
[
292292
'value' => 14,
293-
'color' => '#16a085',
293+
'color' => '#e74c3c',
294294
'label' => 'Wasted',
295295
],
296296
];
@@ -312,12 +312,12 @@ public function testGetGraphHitStatsInfo()
312312
$data = [
313313
[
314314
'value' => 1160,
315-
'color' => '#e74c3c',
315+
'color' => '#2ecc71',
316316
'label' => 'Hits',
317317
],
318318
[
319319
'value' => 59,
320-
'color' => '#2ecc71',
320+
'color' => '#e74c3c',
321321
'label' => 'Misses',
322322
],
323323
[

0 commit comments

Comments
 (0)