Skip to content

Commit 96b4e0b

Browse files
committed
Add HitCounterRepositoryTest
1 parent 7d4320c commit 96b4e0b

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
/**
4+
* HitCounterRepositoryTest
5+
*/
6+
7+
namespace tests\unit;
8+
9+
use coderius\hitCounter\repositories\HitCounterRepository;
10+
use coderius\hitCounter\entities\HitCounter;
11+
12+
13+
class HitCounterRepositoryTest extends \tests\TestCase
14+
{
15+
16+
private $hit;
17+
private $repo;
18+
19+
protected function setUp(): void
20+
{
21+
parent::setUp();
22+
23+
$this->repo = new HitCounterRepository();
24+
25+
$this->hit = $this->getMockBuilder(HitCounter::class)
26+
->setMethods(['save', 'attributes'])
27+
->getMock();
28+
29+
// $this->hit->method('save')->willReturn(true);
30+
$this->hit->method('attributes')->willReturn([
31+
'counter_id',
32+
'cookie_mark',
33+
'js_cookei_enabled',
34+
'js_java_enabled',
35+
'js_timezone_offset',
36+
'js_timezone',
37+
'js_connection',
38+
'js_current_url',
39+
'js_referer_url',
40+
'js_screen_width',
41+
'js_screen_height',
42+
'js_color_depth',
43+
'js_browser_language',
44+
'js_history_length',
45+
'js_is_toutch_device',
46+
'js_processor_ram',
47+
'serv_ip',
48+
'serv_user_agent',
49+
'serv_referer_url',
50+
'serv_server_name',
51+
'serv_auth_user_id',
52+
'serv_port',
53+
'serv_cookies',
54+
'serv_os',
55+
'serv_client',
56+
'serv_device',
57+
'serv_brand',
58+
'serv_model',
59+
'serv_bot',
60+
'serv_host_by_ip',
61+
'serv_is_proxy_or_vp'
62+
]);
63+
}
64+
65+
public function testSaveTrowExeption()
66+
{
67+
$this->expectException(\RuntimeException::class);
68+
$this->hit->method('save')->willReturn(false);
69+
$this->repo->save($this->hit);
70+
}
71+
72+
public function testSaveSuccess()
73+
{
74+
$this->hit->method('save')->willReturn(true);
75+
$this->assertNull($this->repo->save($this->hit));
76+
}
77+
78+
}

0 commit comments

Comments
 (0)