fix: update badge unit tests to match service constructor changes
API CI/CD / Validate (composer + pint) (push) Successful in 2m6s
API CI/CD / Test (PHPUnit) (push) Failing after 2m29s
API CI/CD / Build frontend assets (push) Successful in 2m24s
API CI/CD / Security audit (push) Successful in 33s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped

- BadgeFormDataServiceTest: add missing BadgeStudentLookupService mock,
  update build() signature with  param, fix default
  role assertion (teacher → all)
- BadgePdfServiceTest: add missing BadgeStudentLookupService mock as
  first constructor arg, update generate() calls with studentIds:,
  fix filename assertion (Staff_Badges.pdf → Badges.pdf)

These constructors were refactored to accept a new
BadgeStudentLookupService dependency and reordered parameters,
but the unit tests were never updated, causing TypeError failures.
This commit is contained in:
root
2026-06-23 01:13:30 -04:00
parent f82017cb91
commit 1f72d082ac
2 changed files with 43 additions and 9 deletions
@@ -3,6 +3,7 @@
namespace Tests\Unit\Services\Badges; namespace Tests\Unit\Services\Badges;
use App\Services\Badges\BadgeFormDataService; use App\Services\Badges\BadgeFormDataService;
use App\Services\Badges\BadgeStudentLookupService;
use App\Services\Badges\BadgeTextFormatter; use App\Services\Badges\BadgeTextFormatter;
use App\Services\Badges\BadgeUserLookupService; use App\Services\Badges\BadgeUserLookupService;
use Mockery; use Mockery;
@@ -19,6 +20,7 @@ class BadgeFormDataServiceTest extends TestCase
public function test_build_formats_users_and_assigns_latest_class_for_teacherish_roles(): void public function test_build_formats_users_and_assigns_latest_class_for_teacherish_roles(): void
{ {
$lookup = Mockery::mock(BadgeUserLookupService::class); $lookup = Mockery::mock(BadgeUserLookupService::class);
$studentLookup = Mockery::mock(BadgeStudentLookupService::class);
$formatter = new BadgeTextFormatter; $formatter = new BadgeTextFormatter;
$lookup->shouldReceive('fetchStaffList') $lookup->shouldReceive('fetchStaffList')
@@ -51,9 +53,14 @@ class BadgeFormDataServiceTest extends TestCase
->once() ->once()
->andReturn(['2025-2026', '2024-2025']); ->andReturn(['2025-2026', '2024-2025']);
$service = new BadgeFormDataService($lookup, $formatter); $studentLookup->shouldReceive('fetchStudentList')
->once()
->with('2025-2026', [])
->andReturn([]);
$result = $service->build('2025-2026', [10, 20], 'teacher'); $service = new BadgeFormDataService($lookup, $studentLookup, $formatter);
$result = $service->build('2025-2026', [10, 20], [], 'teacher');
$this->assertSame('2025-2026', $result['selectedYear']); $this->assertSame('2025-2026', $result['selectedYear']);
$this->assertSame([10, 20], $result['selectedUserIds']); $this->assertSame([10, 20], $result['selectedUserIds']);
@@ -75,6 +82,7 @@ class BadgeFormDataServiceTest extends TestCase
public function test_build_defaults_invalid_active_role_to_teacher(): void public function test_build_defaults_invalid_active_role_to_teacher(): void
{ {
$lookup = Mockery::mock(BadgeUserLookupService::class); $lookup = Mockery::mock(BadgeUserLookupService::class);
$studentLookup = Mockery::mock(BadgeStudentLookupService::class);
$formatter = new BadgeTextFormatter; $formatter = new BadgeTextFormatter;
$lookup->shouldReceive('fetchStaffList') $lookup->shouldReceive('fetchStaffList')
@@ -85,10 +93,14 @@ class BadgeFormDataServiceTest extends TestCase
->once() ->once()
->andReturn([]); ->andReturn([]);
$service = new BadgeFormDataService($lookup, $formatter); $studentLookup->shouldReceive('fetchStudentList')
->once()
->andReturn([]);
$result = $service->build('2025-2026', [], 'invalid-role'); $service = new BadgeFormDataService($lookup, $studentLookup, $formatter);
$this->assertSame('teacher', $result['active_role']); $result = $service->build('2025-2026', [], [], 'invalid-role');
$this->assertSame('all', $result['active_role']);
} }
} }
@@ -4,6 +4,7 @@ namespace Tests\Unit\Services\Badges;
use App\Services\Badges\BadgePdfService; use App\Services\Badges\BadgePdfService;
use App\Services\Badges\BadgePrintLogService; use App\Services\Badges\BadgePrintLogService;
use App\Services\Badges\BadgeStudentLookupService;
use App\Services\Badges\BadgeTextFormatter; use App\Services\Badges\BadgeTextFormatter;
use App\Services\Badges\BadgeUserLookupService; use App\Services\Badges\BadgeUserLookupService;
use Mockery; use Mockery;
@@ -20,10 +21,16 @@ class BadgePdfServiceTest extends TestCase
public function test_generate_returns_pdf_response_and_logs_prints(): void public function test_generate_returns_pdf_response_and_logs_prints(): void
{ {
$studentLookup = Mockery::mock(BadgeStudentLookupService::class);
$lookup = Mockery::mock(BadgeUserLookupService::class); $lookup = Mockery::mock(BadgeUserLookupService::class);
$printLog = Mockery::mock(BadgePrintLogService::class); $printLog = Mockery::mock(BadgePrintLogService::class);
$formatter = new BadgeTextFormatter; $formatter = new BadgeTextFormatter;
$studentLookup->shouldReceive('fetchForBadges')
->once()
->with([], '2025-2026')
->andReturn([]);
$lookup->shouldReceive('getUserInfoById') $lookup->shouldReceive('getUserInfoById')
->once() ->once()
->with(10, '2025-2026') ->with(10, '2025-2026')
@@ -45,9 +52,10 @@ class BadgePdfServiceTest extends TestCase
->once() ->once()
->with([10], 1, '2025-2026', [], [], 1); ->with([10], 1, '2025-2026', [], [], 1);
$service = new BadgePdfService($lookup, $printLog, $formatter); $service = new BadgePdfService($studentLookup, $lookup, $printLog, $formatter);
$response = $service->generate( $response = $service->generate(
studentIds: [],
userIds: [10], userIds: [10],
schoolYear: '2025-2026', schoolYear: '2025-2026',
rolesMap: [], rolesMap: [],
@@ -57,16 +65,22 @@ class BadgePdfServiceTest extends TestCase
$this->assertInstanceOf(SymfonyResponse::class, $response); $this->assertInstanceOf(SymfonyResponse::class, $response);
$this->assertSame('application/pdf', $response->headers->get('Content-Type')); $this->assertSame('application/pdf', $response->headers->get('Content-Type'));
$this->assertStringContainsString('inline; filename="Staff_Badges.pdf"', $response->headers->get('Content-Disposition')); $this->assertStringContainsString('inline; filename="Badges.pdf"', $response->headers->get('Content-Disposition'));
$this->assertNotEmpty($response->getContent()); $this->assertNotEmpty($response->getContent());
} }
public function test_generate_returns_empty_state_pdf_when_no_valid_users_found(): void public function test_generate_returns_empty_state_pdf_when_no_valid_users_found(): void
{ {
$studentLookup = Mockery::mock(BadgeStudentLookupService::class);
$lookup = Mockery::mock(BadgeUserLookupService::class); $lookup = Mockery::mock(BadgeUserLookupService::class);
$printLog = Mockery::mock(BadgePrintLogService::class); $printLog = Mockery::mock(BadgePrintLogService::class);
$formatter = new BadgeTextFormatter; $formatter = new BadgeTextFormatter;
$studentLookup->shouldReceive('fetchForBadges')
->once()
->with([], null)
->andReturn([]);
$lookup->shouldReceive('getUserInfoById') $lookup->shouldReceive('getUserInfoById')
->once() ->once()
->with(99, null) ->with(99, null)
@@ -76,9 +90,10 @@ class BadgePdfServiceTest extends TestCase
->once() ->once()
->with([99], null, null, [], [], 1); ->with([99], null, null, [], [], 1);
$service = new BadgePdfService($lookup, $printLog, $formatter); $service = new BadgePdfService($studentLookup, $lookup, $printLog, $formatter);
$response = $service->generate( $response = $service->generate(
studentIds: [],
userIds: [99], userIds: [99],
schoolYear: null, schoolYear: null,
rolesMap: [], rolesMap: [],
@@ -92,6 +107,7 @@ class BadgePdfServiceTest extends TestCase
public function test_generate_deduplicates_same_badge_content(): void public function test_generate_deduplicates_same_badge_content(): void
{ {
$studentLookup = Mockery::mock(BadgeStudentLookupService::class);
$lookup = Mockery::mock(BadgeUserLookupService::class); $lookup = Mockery::mock(BadgeUserLookupService::class);
$printLog = Mockery::mock(BadgePrintLogService::class); $printLog = Mockery::mock(BadgePrintLogService::class);
$formatter = new BadgeTextFormatter; $formatter = new BadgeTextFormatter;
@@ -110,15 +126,21 @@ class BadgePdfServiceTest extends TestCase
'school_year' => '2025-2026', 'school_year' => '2025-2026',
]; ];
$studentLookup->shouldReceive('fetchForBadges')
->once()
->with([], '2025-2026')
->andReturn([]);
$lookup->shouldReceive('getUserInfoById')->once()->andReturn($userInfo); $lookup->shouldReceive('getUserInfoById')->once()->andReturn($userInfo);
$printLog->shouldReceive('logSafely') $printLog->shouldReceive('logSafely')
->once() ->once()
->with([10], 7, '2025-2026', [], [], 1); ->with([10], 7, '2025-2026', [], [], 1);
$service = new BadgePdfService($lookup, $printLog, $formatter); $service = new BadgePdfService($studentLookup, $lookup, $printLog, $formatter);
$response = $service->generate( $response = $service->generate(
studentIds: [],
userIds: [10, 10], userIds: [10, 10],
schoolYear: '2025-2026', schoolYear: '2025-2026',
rolesMap: [], rolesMap: [],