mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-11 20:38:21 +02:00
938456087a
range('A', ...) silently truncates its end argument to one byte once a
sheet needs a column past 'Z' (e.g. 26+ questions), triggering a PHP
warning and mis-sizing columns. Replace it with a helper that walks
column indexes via Coordinate::stringFromColumnIndex, which handles
multi-letter columns correctly.
Fixes PHP-SYMFONY-3Z
48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tvdt\Tests\Service;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Tvdt\Entity\Question;
|
|
use Tvdt\Entity\Quiz;
|
|
use Tvdt\Repository\QuizRepository;
|
|
use Tvdt\Service\DataExportService;
|
|
use Tvdt\Service\QuizSpreadsheetService;
|
|
|
|
/**
|
|
* Reproduces a Sentry warning (PHP-SYMFONY-3Z): with more than 25 questions, the last raw-answers
|
|
* column goes past 'Z' (e.g. 'AA'), and range('A', 'AA') is invalid because range()'s second argument
|
|
* must be a single byte.
|
|
*/
|
|
#[CoversClass(DataExportService::class)]
|
|
final class DataExportServiceRawAnswersColumnsTest extends TestCase
|
|
{
|
|
public function testFillRawAnswersSheetHandlesMoreThanTwentyFiveQuestions(): void
|
|
{
|
|
$subject = new DataExportService(
|
|
$this->createStub(EntityManagerInterface::class),
|
|
$this->createStub(QuizSpreadsheetService::class),
|
|
$this->createStub(QuizRepository::class),
|
|
);
|
|
|
|
$quiz = new Quiz();
|
|
for ($i = 0; $i < 26; ++$i) {
|
|
$question = new Question();
|
|
$question->question = 'Question '.($i + 1);
|
|
$quiz->addQuestion($question);
|
|
}
|
|
|
|
$sheet = new Spreadsheet()->getActiveSheet();
|
|
|
|
$method = new \ReflectionMethod(DataExportService::class, 'fillRawAnswersSheet');
|
|
$method->invoke($subject, $sheet, $quiz);
|
|
|
|
$this->assertEqualsWithDelta(30.0, $sheet->getColumnDimension('AA')->getWidth(), \PHP_FLOAT_EPSILON);
|
|
}
|
|
}
|