@@ -27,6 +27,7 @@ class SessionStatisticsTest extends TestCase {
2727 private ITimeFactory &MockObject $ timeFactory ;
2828 private IDBConnection $ connection ;
2929 private SessionStatistics $ instance ;
30+ private int $ currentTime ;
3031 private const TABLE = 'preferences ' ;
3132 private const OFFSET_5MIN = 300 ;
3233 private const OFFSET_1HOUR = 3600 ;
@@ -35,7 +36,6 @@ class SessionStatisticsTest extends TestCase {
3536 private const OFFSET_3MONTHS = 7776000 ;
3637 private const OFFSET_6MONTHS = 15552000 ;
3738 private const OFFSET_1YEAR = 31536000 ;
38- private const CURRENT_TIME = 100000000 ;
3939
4040
4141 protected function setUp (): void {
@@ -47,6 +47,10 @@ protected function setUp(): void {
4747
4848 $ this ->instance = new SessionStatistics ($ this ->connection , $ this ->timeFactory );
4949
50+ // when running the tests locally, you may have other lastLogin values in the database.
51+ // using a timestamp in the future to workaround.
52+ $ this ->currentTime = time () + (400 * 24 * 60 * 60 );
53+
5054 $ this ->removeDummyValues ();
5155 $ this ->addDummyValues ();
5256 }
@@ -65,18 +69,18 @@ protected function removeDummyValues(): void {
6569 }
6670
6771 private function addDummyValues (): void {
68- $ this ->addDummyValuesWithLastLogin (self :: CURRENT_TIME - self ::OFFSET_5MIN + 1 , 10 );
69- $ this ->addDummyValuesWithLastLogin (self :: CURRENT_TIME - self ::OFFSET_5MIN + 1 , 11 );
70- $ this ->addDummyValuesWithLastLogin (self :: CURRENT_TIME - self ::OFFSET_1HOUR + 1 , 20 );
71- $ this ->addDummyValuesWithLastLogin (self :: CURRENT_TIME - self ::OFFSET_1HOUR + 1 , 21 );
72- $ this ->addDummyValuesWithLastLogin (self :: CURRENT_TIME - self ::OFFSET_1HOUR + 1 , 22 );
73- $ this ->addDummyValuesWithLastLogin (self :: CURRENT_TIME - self ::OFFSET_1DAY + 1 , 30 );
74- $ this ->addDummyValuesWithLastLogin (self :: CURRENT_TIME - self ::OFFSET_1MONTH + 1 , 50 );
75- $ this ->addDummyValuesWithLastLogin (self :: CURRENT_TIME - self ::OFFSET_3MONTHS + 1 , 60 );
76- $ this ->addDummyValuesWithLastLogin (self :: CURRENT_TIME - self ::OFFSET_6MONTHS + 1 , 70 );
77- $ this ->addDummyValuesWithLastLogin (self :: CURRENT_TIME - self ::OFFSET_1YEAR + 1 , 80 );
78- $ this ->addDummyValuesWithLastLogin (self :: CURRENT_TIME - self ::OFFSET_1YEAR + 1 , 81 );
79- $ this ->addDummyValuesWithLastLogin (self :: CURRENT_TIME - self ::OFFSET_1YEAR + 1 , 82 );
72+ $ this ->addDummyValuesWithLastLogin ($ this -> currentTime - self ::OFFSET_5MIN + 1 , 10 );
73+ $ this ->addDummyValuesWithLastLogin ($ this -> currentTime - self ::OFFSET_5MIN + 1 , 11 );
74+ $ this ->addDummyValuesWithLastLogin ($ this -> currentTime - self ::OFFSET_1HOUR + 1 , 20 );
75+ $ this ->addDummyValuesWithLastLogin ($ this -> currentTime - self ::OFFSET_1HOUR + 1 , 21 );
76+ $ this ->addDummyValuesWithLastLogin ($ this -> currentTime - self ::OFFSET_1HOUR + 1 , 22 );
77+ $ this ->addDummyValuesWithLastLogin ($ this -> currentTime - self ::OFFSET_1DAY + 1 , 30 );
78+ $ this ->addDummyValuesWithLastLogin ($ this -> currentTime - self ::OFFSET_1MONTH + 1 , 50 );
79+ $ this ->addDummyValuesWithLastLogin ($ this -> currentTime - self ::OFFSET_3MONTHS + 1 , 60 );
80+ $ this ->addDummyValuesWithLastLogin ($ this -> currentTime - self ::OFFSET_6MONTHS + 1 , 70 );
81+ $ this ->addDummyValuesWithLastLogin ($ this -> currentTime - self ::OFFSET_1YEAR + 1 , 80 );
82+ $ this ->addDummyValuesWithLastLogin ($ this -> currentTime - self ::OFFSET_1YEAR + 1 , 81 );
83+ $ this ->addDummyValuesWithLastLogin ($ this -> currentTime - self ::OFFSET_1YEAR + 1 , 82 );
8084 }
8185
8286 private function addDummyValuesWithLastLogin ($ lastActivity , $ id ): void {
@@ -98,7 +102,7 @@ private function addDummyValuesWithLastLogin($lastActivity, $id): void {
98102
99103 public function testGetSessionStatistics () {
100104 $ this ->timeFactory ->expects ($ this ->any ())->method ('getTime ' )
101- ->willReturn (self :: CURRENT_TIME );
105+ ->willReturn ($ this -> currentTime );
102106
103107 $ result = $ this ->instance ->getSessionStatistics ();
104108
0 commit comments