Upgrade tests to PhpUnit 10 (#5252)

This commit is contained in:
Kevin Papst
2024-12-22 01:25:30 +01:00
committed by GitHub
parent 9bd37fb695
commit c7f0508707
377 changed files with 3308 additions and 3409 deletions

View File

@@ -37,7 +37,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;
abstract class AbstractRendererTest extends KernelTestCase
abstract class AbstractRendererTestCase extends KernelTestCase
{
/**
* @param class-string $classname

View File

@@ -19,17 +19,17 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse;
* @covers \App\Export\Renderer\CsvRenderer
* @group integration
*/
class CsvRendererTest extends AbstractRendererTest
class CsvRendererTest extends AbstractRendererTestCase
{
public function testConfiguration(): void
{
$sut = $this->getAbstractRenderer(CsvRenderer::class);
$this->assertEquals('csv', $sut->getId());
$this->assertEquals('csv', $sut->getTitle());
self::assertEquals('csv', $sut->getId());
self::assertEquals('csv', $sut->getTitle());
}
public function getTestModel()
public static function getTestModel()
{
return [
['400', '2437.12', ' EUR 1,947.99 ', 7, 6, 1, 2, 2]
@@ -48,25 +48,25 @@ class CsvRendererTest extends AbstractRendererTest
$file = $response->getFile();
$prefix = date('Ymd');
$this->assertEquals('text/csv', $response->headers->get('Content-Type'));
$this->assertEquals('attachment; filename=' . $prefix . '-Customer_Name-project_name.csv', $response->headers->get('Content-Disposition'));
self::assertEquals('text/csv', $response->headers->get('Content-Type'));
self::assertEquals('attachment; filename=' . $prefix . '-Customer_Name-project_name.csv', $response->headers->get('Content-Disposition'));
$this->assertTrue(file_exists($file->getRealPath()));
self::assertTrue(file_exists($file->getRealPath()));
$content = file_get_contents($file->getRealPath());
$this->assertStringContainsString('"' . $expectedRate . '"', $content);
$this->assertEquals($expectedRows, substr_count($content, PHP_EOL));
$this->assertEquals($expectedDescriptions, substr_count($content, 'activity description'));
$this->assertEquals($expectedUser1, substr_count($content, ',"kevin",'));
$this->assertEquals($expectedUser3, substr_count($content, ',"hello-world",'));
$this->assertEquals($expectedUser2, substr_count($content, ',"foo-bar",'));
self::assertStringContainsString('"' . $expectedRate . '"', $content);
self::assertEquals($expectedRows, substr_count($content, PHP_EOL));
self::assertEquals($expectedDescriptions, substr_count($content, 'activity description'));
self::assertEquals($expectedUser1, substr_count($content, ',"kevin",'));
self::assertEquals($expectedUser3, substr_count($content, ',"hello-world",'));
self::assertEquals($expectedUser2, substr_count($content, ',"foo-bar",'));
ob_start();
$response->sendContent();
$content2 = ob_get_clean();
$this->assertEquals($content, $content2);
$this->assertFalse(file_exists($file->getRealPath()));
self::assertEquals($content, $content2);
self::assertFalse(file_exists($file->getRealPath()));
$all = [];
$rows = str_getcsv($content2, PHP_EOL);

View File

@@ -27,7 +27,7 @@ use Twig\Environment;
* @covers \App\Export\Renderer\HtmlRenderer
* @group integration
*/
class HtmlRendererTest extends AbstractRendererTest
class HtmlRendererTest extends AbstractRendererTestCase
{
public function testConfiguration(): void
{
@@ -38,8 +38,8 @@ class HtmlRendererTest extends AbstractRendererTest
$this->createMock(ActivityStatisticService::class)
);
$this->assertEquals('html', $sut->getId());
$this->assertEquals('print', $sut->getTitle());
self::assertEquals('html', $sut->getId());
self::assertEquals('print', $sut->getTitle());
}
public function testRender(): void
@@ -79,21 +79,21 @@ class HtmlRendererTest extends AbstractRendererTest
$content = $response->getContent();
$this->assertStringContainsString('<h2 id="doc-title" contenteditable="true"', $content);
$this->assertStringContainsString('<h3 class="card-title" id="doc-summary" contenteditable="true" data-original="Summary">Summary</h3>', $content);
$this->assertEquals(1, substr_count($content, 'id="export-summary"'));
$this->assertEquals(1, substr_count($content, 'id="export-records"'));
$this->assertEquals(1, substr_count($content, 'id="summary-project"'));
$this->assertEquals(1, substr_count($content, 'id="summary-activity"'));
self::assertStringContainsString('<h2 id="doc-title" contenteditable="true"', $content);
self::assertStringContainsString('<h3 class="card-title" id="doc-summary" contenteditable="true" data-original="Summary">Summary</h3>', $content);
self::assertEquals(1, substr_count($content, 'id="export-summary"'));
self::assertEquals(1, substr_count($content, 'id="export-records"'));
self::assertEquals(1, substr_count($content, 'id="summary-project"'));
self::assertEquals(1, substr_count($content, 'id="summary-activity"'));
$this->assertStringContainsString('<td>Customer Name</td>', $content);
$this->assertStringContainsString('<td>project name</td>', $content);
$this->assertStringContainsString('<span class="duration-format" data-duration-decimal="1.94" data-duration="1:56">1:56</span>', $content);
$this->assertStringContainsString('<td class="cost summary-rate">€2,437.12</td>', $content);
$this->assertStringContainsString('-€100.92', $content);
self::assertStringContainsString('<td>Customer Name</td>', $content);
self::assertStringContainsString('<td>project name</td>', $content);
self::assertStringContainsString('<span class="duration-format" data-duration-decimal="1.94" data-duration="1:56">1:56</span>', $content);
self::assertStringContainsString('<td class="cost summary-rate">€2,437.12</td>', $content);
self::assertStringContainsString('-€100.92', $content);
// 5 times in the "full list" and once in the "summary with activities"
$this->assertEquals(7, substr_count($content, 'activity description'));
$this->assertEquals(1, substr_count($content, '<td>activity description</td>'));
self::assertEquals(7, substr_count($content, 'activity description'));
self::assertEquals(1, substr_count($content, '<td>activity description</td>'));
}
}

View File

@@ -24,7 +24,7 @@ use Twig\Environment;
* @covers \App\Export\Renderer\PDFRenderer
* @group integration
*/
class PdfRendererTest extends AbstractRendererTest
class PdfRendererTest extends AbstractRendererTestCase
{
public function testConfiguration(): void
{
@@ -34,13 +34,13 @@ class PdfRendererTest extends AbstractRendererTest
$this->createMock(ProjectStatisticService::class)
);
$this->assertEquals('pdf', $sut->getId());
$this->assertEquals('pdf', $sut->getTitle());
$this->assertEquals([], $sut->getPdfOptions());
self::assertEquals('pdf', $sut->getId());
self::assertEquals('pdf', $sut->getTitle());
self::assertEquals([], $sut->getPdfOptions());
$sut->setPdfOption('foo', 'bar');
$sut->setPdfOption('bar1', 'foo1');
$this->assertEquals(['foo' => 'bar', 'bar1' => 'foo1'], $sut->getPdfOptions());
self::assertEquals(['foo' => 'bar', 'bar1' => 'foo1'], $sut->getPdfOptions());
}
public function testRenderAttachment(): void
@@ -62,9 +62,9 @@ class PdfRendererTest extends AbstractRendererTest
$prefix = date('Ymd');
$response = $this->render($sut);
$this->assertEquals('application/pdf', $response->headers->get('Content-Type'));
$this->assertEquals('attachment; filename=' . $prefix . '-Customer_Name-project_name.pdf', $response->headers->get('Content-Disposition'));
$this->assertNotEmpty($response->getContent());
self::assertEquals('application/pdf', $response->headers->get('Content-Type'));
self::assertEquals('attachment; filename=' . $prefix . '-Customer_Name-project_name.pdf', $response->headers->get('Content-Disposition'));
self::assertNotEmpty($response->getContent());
}
public function testRenderInline(): void
@@ -87,8 +87,8 @@ class PdfRendererTest extends AbstractRendererTest
$sut->setDispositionInline(true);
$response = $this->render($sut);
$this->assertEquals('application/pdf', $response->headers->get('Content-Type'));
$this->assertEquals('inline; filename=' . $prefix . '-Customer_Name-project_name.pdf', $response->headers->get('Content-Disposition'));
$this->assertNotEmpty($response->getContent());
self::assertEquals('application/pdf', $response->headers->get('Content-Type'));
self::assertEquals('inline; filename=' . $prefix . '-Customer_Name-project_name.pdf', $response->headers->get('Content-Disposition'));
self::assertNotEmpty($response->getContent());
}
}

View File

@@ -19,14 +19,14 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse;
* @covers \App\Export\Renderer\XlsxRenderer
* @group integration
*/
class XlsxRendererTest extends AbstractRendererTest
class XlsxRendererTest extends AbstractRendererTestCase
{
public function testConfiguration(): void
{
$sut = $this->getAbstractRenderer(XlsxRenderer::class);
$this->assertEquals('xlsx', $sut->getId());
$this->assertEquals('xlsx', $sut->getTitle());
self::assertEquals('xlsx', $sut->getId());
self::assertEquals('xlsx', $sut->getTitle());
}
public function testRender(): void
@@ -38,16 +38,16 @@ class XlsxRendererTest extends AbstractRendererTest
$file = $response->getFile();
$prefix = date('Ymd');
$this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type'));
$this->assertEquals('attachment; filename=' . $prefix . '-Customer_Name-project_name.xlsx', $response->headers->get('Content-Disposition'));
self::assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type'));
self::assertEquals('attachment; filename=' . $prefix . '-Customer_Name-project_name.xlsx', $response->headers->get('Content-Disposition'));
$this->assertTrue(file_exists($file->getRealPath()));
self::assertTrue(file_exists($file->getRealPath()));
ob_start();
$response->sendContent();
$content2 = ob_get_clean();
$this->assertNotEmpty($content2);
self::assertNotEmpty($content2);
$this->assertFalse(file_exists($file->getRealPath()));
self::assertFalse(file_exists($file->getRealPath()));
}
}

View File

@@ -16,7 +16,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Style;
use PHPUnit\Framework\TestCase;
abstract class AbstractFormatterTest extends TestCase
abstract class AbstractFormatterTestCase extends TestCase
{
abstract protected function getFormatter(): CellFormatterInterface;

View File

@@ -16,7 +16,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
/**
* @covers \App\Export\Spreadsheet\CellFormatter\ArrayFormatter
*/
class ArrayFormatterTest extends AbstractFormatterTest
class ArrayFormatterTest extends AbstractFormatterTestCase
{
protected function getFormatter(): CellFormatterInterface
{

View File

@@ -16,7 +16,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
/**
* @covers \App\Export\Spreadsheet\CellFormatter\BooleanFormatter
*/
class BooleanFormatterTest extends AbstractFormatterTest
class BooleanFormatterTest extends AbstractFormatterTestCase
{
protected function getFormatter(): CellFormatterInterface
{

View File

@@ -19,7 +19,7 @@ use PhpOffice\PhpSpreadsheet\Style\Style;
/**
* @covers \App\Export\Spreadsheet\CellFormatter\DateFormatter
*/
class DateFormatterTest extends AbstractFormatterTest
class DateFormatterTest extends AbstractFormatterTestCase
{
private $date;

View File

@@ -18,7 +18,7 @@ use PhpOffice\PhpSpreadsheet\Style\Style;
/**
* @covers \App\Export\Spreadsheet\CellFormatter\DateTimeFormatter
*/
class DateTimeFormatterTest extends AbstractFormatterTest
class DateTimeFormatterTest extends AbstractFormatterTestCase
{
private $date;

View File

@@ -18,7 +18,7 @@ use PhpOffice\PhpSpreadsheet\Style\Style;
/**
* @covers \App\Export\Spreadsheet\CellFormatter\DurationFormatter
*/
class DurationFormatterTest extends AbstractFormatterTest
class DurationFormatterTest extends AbstractFormatterTestCase
{
protected function getFormatter(): CellFormatterInterface
{

View File

@@ -18,7 +18,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
/**
* @covers \App\Export\Spreadsheet\CellFormatter\StringFormatter
*/
class StringFormatterTest extends AbstractFormatterTest
class StringFormatterTest extends AbstractFormatterTestCase
{
protected function getFormatter(): CellFormatterInterface
{
@@ -59,8 +59,7 @@ class StringFormatterTest extends AbstractFormatterTest
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$test = new StringHelperTest();
foreach ($test->getDdeAttackStrings() as $attackString) {
foreach (StringHelperTest::getDdeAttackStrings() as $attackString) {
$value = $attackString[0];
// PHPOffice converts that, so simply skip it
if (!str_contains($value, "\r")) {

View File

@@ -18,7 +18,7 @@ use PhpOffice\PhpSpreadsheet\Style\Style;
/**
* @covers \App\Export\Spreadsheet\CellFormatter\TimeFormatter
*/
class TimeFormatterTest extends AbstractFormatterTest
class TimeFormatterTest extends AbstractFormatterTestCase
{
private $date;

View File

@@ -36,7 +36,7 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;
abstract class AbstractRendererTest extends KernelTestCase
abstract class AbstractRendererTestCase extends KernelTestCase
{
/**
* @param class-string $classname

View File

@@ -19,17 +19,17 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse;
* @covers \App\Export\Timesheet\CsvRenderer
* @group integration
*/
class CsvRendererTest extends AbstractRendererTest
class CsvRendererTest extends AbstractRendererTestCase
{
public function testConfiguration(): void
{
$sut = $this->getAbstractRenderer(CsvRenderer::class);
$this->assertEquals('csv', $sut->getId());
$this->assertEquals('csv', $sut->getTitle());
self::assertEquals('csv', $sut->getId());
self::assertEquals('csv', $sut->getTitle());
}
public function getTestModel()
public static function getTestModel()
{
return [
['400', '2437.12', ' EUR 1,947.99 ', 6, 5, 1, 2, 2]
@@ -48,25 +48,25 @@ class CsvRendererTest extends AbstractRendererTest
$file = $response->getFile();
$prefix = date('Ymd');
$this->assertEquals('text/csv', $response->headers->get('Content-Type'));
$this->assertEquals('attachment; filename=' . $prefix . '-Customer_Name-project_name.csv', $response->headers->get('Content-Disposition'));
self::assertEquals('text/csv', $response->headers->get('Content-Type'));
self::assertEquals('attachment; filename=' . $prefix . '-Customer_Name-project_name.csv', $response->headers->get('Content-Disposition'));
$this->assertTrue(file_exists($file->getRealPath()));
self::assertTrue(file_exists($file->getRealPath()));
$content = file_get_contents($file->getRealPath());
$this->assertStringContainsString('"' . $expectedRate . '"', $content);
$this->assertEquals($expectedRows, substr_count($content, PHP_EOL));
$this->assertEquals($expectedDescriptions, substr_count($content, 'activity description'));
$this->assertEquals($expectedUser1, substr_count($content, ',"kevin",'));
$this->assertEquals($expectedUser3, substr_count($content, ',"hello-world",'));
$this->assertEquals($expectedUser2, substr_count($content, ',"foo-bar",'));
self::assertStringContainsString('"' . $expectedRate . '"', $content);
self::assertEquals($expectedRows, substr_count($content, PHP_EOL));
self::assertEquals($expectedDescriptions, substr_count($content, 'activity description'));
self::assertEquals($expectedUser1, substr_count($content, ',"kevin",'));
self::assertEquals($expectedUser3, substr_count($content, ',"hello-world",'));
self::assertEquals($expectedUser2, substr_count($content, ',"foo-bar",'));
ob_start();
$response->sendContent();
$content2 = ob_get_clean();
$this->assertEquals($content, $content2);
$this->assertFalse(file_exists($file->getRealPath()));
self::assertEquals($content, $content2);
self::assertFalse(file_exists($file->getRealPath()));
$all = [];
$rows = str_getcsv($content2, PHP_EOL);

View File

@@ -21,7 +21,7 @@ use Twig\Environment;
* @covers \App\Export\Timesheet\HtmlRenderer
* @group integration
*/
class HtmlRendererTest extends AbstractRendererTest
class HtmlRendererTest extends AbstractRendererTestCase
{
public function testConfiguration(): void
{
@@ -32,8 +32,8 @@ class HtmlRendererTest extends AbstractRendererTest
$this->createMock(ActivityStatisticService::class)
);
$this->assertEquals('print', $sut->getId());
$this->assertEquals('print', $sut->getTitle());
self::assertEquals('print', $sut->getId());
self::assertEquals('print', $sut->getTitle());
}
public function testRender(): void
@@ -58,6 +58,6 @@ class HtmlRendererTest extends AbstractRendererTest
$content = $response->getContent();
$this->assertStringContainsString('>1:50<', $content);
self::assertStringContainsString('>1:50<', $content);
}
}

View File

@@ -24,7 +24,7 @@ use Twig\Environment;
* @covers \App\Export\Timesheet\PDFRenderer
* @group integration
*/
class PdfRendererTest extends AbstractRendererTest
class PdfRendererTest extends AbstractRendererTestCase
{
public function testConfiguration(): void
{
@@ -34,8 +34,8 @@ class PdfRendererTest extends AbstractRendererTest
$this->createMock(ProjectStatisticService::class)
);
$this->assertEquals('pdf', $sut->getId());
$this->assertEquals('pdf', $sut->getTitle());
self::assertEquals('pdf', $sut->getId());
self::assertEquals('pdf', $sut->getTitle());
}
public function testRender(): void
@@ -57,9 +57,9 @@ class PdfRendererTest extends AbstractRendererTest
$response = $this->render($sut);
$prefix = date('Ymd');
$this->assertEquals('application/pdf', $response->headers->get('Content-Type'));
$this->assertEquals('attachment; filename=' . $prefix . '-Customer_Name-project_name.pdf', $response->headers->get('Content-Disposition'));
self::assertEquals('application/pdf', $response->headers->get('Content-Type'));
self::assertEquals('attachment; filename=' . $prefix . '-Customer_Name-project_name.pdf', $response->headers->get('Content-Disposition'));
$this->assertNotEmpty($response->getContent());
self::assertNotEmpty($response->getContent());
}
}

View File

@@ -19,14 +19,14 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse;
* @covers \App\Export\Timesheet\XlsxRenderer
* @group integration
*/
class XlsxRendererTest extends AbstractRendererTest
class XlsxRendererTest extends AbstractRendererTestCase
{
public function testConfiguration(): void
{
$sut = $this->getAbstractRenderer(XlsxRenderer::class);
$this->assertEquals('xlsx', $sut->getId());
$this->assertEquals('xlsx', $sut->getTitle());
self::assertEquals('xlsx', $sut->getId());
self::assertEquals('xlsx', $sut->getTitle());
}
public function testRender(): void
@@ -38,16 +38,16 @@ class XlsxRendererTest extends AbstractRendererTest
$file = $response->getFile();
$prefix = date('Ymd');
$this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type'));
$this->assertEquals('attachment; filename=' . $prefix . '-Customer_Name-project_name.xlsx', $response->headers->get('Content-Disposition'));
self::assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type'));
self::assertEquals('attachment; filename=' . $prefix . '-Customer_Name-project_name.xlsx', $response->headers->get('Content-Disposition'));
$this->assertTrue(file_exists($file->getRealPath()));
self::assertTrue(file_exists($file->getRealPath()));
ob_start();
$response->sendContent();
$content2 = ob_get_clean();
$this->assertNotEmpty($content2);
self::assertNotEmpty($content2);
$this->assertFalse(file_exists($file->getRealPath()));
self::assertFalse(file_exists($file->getRealPath()));
}
}