Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace assertEquals by assertSame #14

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Biigle\Modules\Kpis;

use Brick\Math\BigInteger;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;

Expand All @@ -22,14 +23,14 @@ public static function getActions($year, $month)
$end = $start->copy()->addMonth();
$res = DB::table('kpis_actions')->whereBetween('date', [$start, $end])->sum('value');

return $res;
return BigInteger::of($res);
}
public static function getVisits($year, $month)
{
$start = Carbon::createFromDate($year, $month)->startOfMonth();
$end = $start->copy()->addMonth();
$res = DB::table('kpis_visits')->whereBetween('date', [$start, $end])->sum('value');

return $res;
return BigInteger::of($res);
}
}
3 changes: 2 additions & 1 deletion src/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Biigle\Modules\Kpis;

use Brick\Math\BigInteger;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;

Expand All @@ -12,6 +13,6 @@ public static function getStorageUsage($year, $month)
$date = Carbon::createFromDate($year, $month, 1)->endOfMonth();
$res = DB::table('kpis_storage_usage')->where('date', '=', $date)->sum('value');

return $res;
return BigInteger::of($res);
}
}
7 changes: 5 additions & 2 deletions src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Biigle\Modules\Kpis;

use Brick\Math\BigInteger;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;

Expand All @@ -12,16 +13,18 @@ public static function getUser($year, $month)
$first = Carbon::createFromDate($year, $month)->startOfMonth();
$last = $first->copy()->addMonth();

return DB::table('kpis_users')
$res = DB::table('kpis_users')
->whereBetween('date', [$first, $last])
->sum('value');

return BigInteger::of($res);
}

public static function getUniqueUser($year, $month)
{
$date = Carbon::createFromDate($year, $month, 1)->endOfMonth();
$res = DB::table('kpis_unique_users')->where('date', '=', $date)->sum('value');

return $res;
return BigInteger::of($res);
}
}
4 changes: 2 additions & 2 deletions tests/Console/Commands/CountUniqueUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testHandle()
->where('date', '=', $now->subMonth()->endOfMonth())->pluck('value');

$this->assertCount(1, $uniqueUsers);
$this->assertEquals(3, $uniqueUsers[0]);
$this->assertSame(3, $uniqueUsers[0]);


}
Expand All @@ -39,6 +39,6 @@ public function testLoginWasNotLastMonth()
->where('date', '=', $now->subMonth()->endOfMonth())->pluck('value');

$this->assertCount(1, $uniqueUsers);
$this->assertEquals(1, $uniqueUsers[0]);
$this->assertSame(1, $uniqueUsers[0]);
}
}
4 changes: 2 additions & 2 deletions tests/Console/Commands/CountUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testHandle()
$users = DB::table('kpis_users')->where('date', '=', $yesterday->toDateString())->pluck('value');

$this->assertCount(1, $users);
$this->assertEquals(2, $users[0]);
$this->assertSame(2, $users[0]);

}

Expand All @@ -38,6 +38,6 @@ public function testDifferentLogInDates()
$users = DB::table('kpis_users')->where('date', '=', $yesterday->toDateString())->pluck('value');

$this->assertCount(1, $users);
$this->assertEquals(1, $users[0]);
$this->assertSame(1, $users[0]);
}
}
4 changes: 2 additions & 2 deletions tests/Console/Commands/DetermineStorageUsageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testHandle()
->pluck('value');

$this->assertCount(1, $users);
$this->assertEquals(2, $users[0]);
$this->assertSame(2, $users[0]);

}

Expand All @@ -59,6 +59,6 @@ public function testEmptyAttributeArrays()
->pluck('value');

$this->assertCount(1, $users);
$this->assertEquals(0, $users[0]);
$this->assertSame(0, $users[0]);
}
}
4 changes: 2 additions & 2 deletions tests/Http/Controllers/RequestControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function testStore()
$actions = DB::table('kpis_actions')->where('date', '=', $date)->first()->value;
$visits = DB::table('kpis_visits')->where('date', '=', $date)->first()->value;

$this->assertEquals(94556, $visits);
$this->assertEquals(21602, $actions);
$this->assertSame(94556, $visits);
$this->assertSame(21602, $actions);
}

public function testStoreMissingToken()
Expand Down
15 changes: 8 additions & 7 deletions tests/RequestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Carbon\Carbon;
use Biigle\Modules\Kpis\Requests;
use Illuminate\Support\Facades\DB;
use Brick\Math\BigInteger;

class RequestsTest extends TestCase
{
Expand All @@ -21,12 +22,12 @@ public function testSave()
$this->assertCount(1, $actions);
$this->assertCount(1, $visits);

$this->assertEquals(50, $actions[0]);
$this->assertEquals(100, $visits[0]);
$this->assertSame(50, $actions[0]);
$this->assertSame(100, $visits[0]);
}

public function testSaveBigInt(){
$maxBigInt = "9223372036854775807";
$maxBigInt = 9223372036854775807;

Requests::save($maxBigInt, $maxBigInt);

Expand All @@ -38,8 +39,8 @@ public function testSaveBigInt(){
$this->assertCount(1, $actions);
$this->assertCount(1, $visits);

$this->assertEquals($maxBigInt, $actions[0]);
$this->assertEquals($maxBigInt, $visits[0]);
$this->assertSame($maxBigInt, $actions[0]);
$this->assertSame($maxBigInt, $visits[0]);
}

public function testGetActions()
Expand All @@ -53,7 +54,7 @@ public function testGetActions()

$count = Requests::getActions($date->year, $date->month);

$this->assertEquals(10, $count);
$this->assertEquals(BigInteger::of(10), $count);
}

public function testGetVisits()
Expand All @@ -67,6 +68,6 @@ public function testGetVisits()

$count = Requests::getVisits($date->year, $date->month);

$this->assertEquals(10, $count);
$this->assertEquals(BigInteger::of(10), $count);
}
}
5 changes: 3 additions & 2 deletions tests/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Carbon\Carbon;
use Biigle\Modules\Kpis\Storage;
use Illuminate\Support\Facades\DB;
use Brick\Math\BigInteger;

class StorageTest extends TestCase
{
Expand All @@ -23,7 +24,7 @@ public function testGetStorage()

$size = Storage::getStorageUsage($date->year, $date->month);

$this->assertEquals(0, $noFiles);
$this->assertEquals(100, $size);
$this->assertEquals(BigInteger::of(0), $noFiles);
$this->assertEquals(BigInteger::of(100), $size);
}
}
9 changes: 5 additions & 4 deletions tests/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Carbon\Carbon;
use Biigle\Modules\Kpis\User;
use Illuminate\Support\Facades\DB;
use Brick\Math\BigInteger;

class UserTest extends TestCase
{
Expand All @@ -23,8 +24,8 @@ public function testGetUser()

$count = User::getUser($first->year, $first->month);

$this->assertEquals(0, $noUserCounted);
$this->assertEquals(20, $count);
$this->assertEquals(BigInteger::of(0), $noUserCounted);
$this->assertEquals(BigInteger::of(20), $count);
}

public function testGetUniqueUser(){
Expand All @@ -39,8 +40,8 @@ public function testGetUniqueUser(){

$count = User::getUniqueUser($date->year, $date->month);

$this->assertEquals(0, $noUserCounted);
$this->assertEquals(10, $count);
$this->assertEquals(BigInteger::of(0), $noUserCounted);
$this->assertEquals(BigInteger::of(10), $count);
}
}