File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ public function makeFromRequest(IncomingRequest $request): Visit
7272 public function findSimilar (Visit $ visit ): ?Visit
7373 {
7474 $ config = config ('Visits ' );
75- $ tracking = $ visit ->{ $ config ->trackingMethod } ;
75+ $ tracking = $ visit ->toRawArray ()[ $ config ->trackingMethod ] ?? null ;
7676
7777 // Required fields
7878 if (empty ($ tracking ) || empty ($ visit ->host ) || empty ($ visit ->path )) {
Original file line number Diff line number Diff line change @@ -27,7 +27,21 @@ public function testRecords(): void
2727 $ this ->seeInDatabase ('visits ' , ['path ' => '/index.php ' ]);
2828 }
2929
30- public function testIncrements (): void
30+ public function testIpAddressIncrements (): void
31+ {
32+ config ('Visits ' )->trackingMethod = 'ip_address ' ;
33+ $ _SERVER ['REMOTE_ADDR ' ] = '192.168.0.1 ' ;
34+ $ this ->request = single_service ('request ' );
35+
36+ $ this ->call ();
37+ $ this ->call ();
38+
39+ $ this ->seeInDatabase ('visits ' , ['views ' => 2 ]);
40+
41+ unset($ _SERVER ['REMOTE_ADDR ' ]);
42+ }
43+
44+ public function testUserIdIncrements (): void
3145 {
3246 config ('Visits ' )->trackingMethod = 'user_id ' ;
3347 service ('auth ' )->login (42 );
@@ -38,6 +52,19 @@ public function testIncrements(): void
3852 $ this ->seeInDatabase ('visits ' , ['views ' => 2 ]);
3953 }
4054
55+ /**
56+ * @runInSeparateProcess
57+ */
58+ public function testSessionIdIncrements (): void
59+ {
60+ config ('Visits ' )->trackingMethod = 'session_id ' ;
61+ session_id ('abc123 ' );
62+ $ this ->call ();
63+ $ this ->call ();
64+
65+ $ this ->seeInDatabase ('visits ' , ['views ' => 2 ]);
66+ }
67+
4168 public function testBeforeRecords (): void
4269 {
4370 $ this ->call ('before ' );
Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ public function testMakeFromRequestConvertsIp(): void
125125 $ result = $ this ->model ->makeFromRequest (single_service ('request ' ));
126126
127127 $ this ->assertSame ($ expected , $ result ->ipAddress );
128+ $ this ->assertSame (ip2long ($ expected ), $ result ->toRawArray ()['ip_address ' ]);
128129
129130 unset($ _SERVER ['REMOTE_ADDR ' ]);
130131 }
You can’t perform that action at this time.
0 commit comments