Skip to content

Commit

Permalink
Updated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Dec 17, 2024
1 parent cfed6e5 commit 08aa19c
Show file tree
Hide file tree
Showing 98 changed files with 230 additions and 153 deletions.
59 changes: 12 additions & 47 deletions src/Controller/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use App\Enums\Importance;
use App\Enums\MessagePosition;
use App\Enums\StrengthLevel;
use App\Enums\TableView;
use App\Form\Admin\CustomerParameterType;
use App\Form\Type\AlphaCaptchaType;
use App\Form\Type\CaptchaImageType;
use App\Form\Type\ReCaptchaType;
Expand All @@ -37,7 +37,6 @@
use App\Interfaces\UserInterface;
use App\Model\HttpClientError;
use App\Parameter\ApplicationParameters;
use App\Parameter\UserParameters;
use App\Pdf\Events\PdfLabelTextEvent;
use App\Pdf\Interfaces\PdfLabelTextListenerInterface;
use App\Pdf\PdfLabelDocument;
Expand Down Expand Up @@ -503,53 +502,19 @@ public function swiss(Request $request, SwissPostService $service): JsonResponse
return $this->json($data);
}

#[Get(path: '/parameter', name: 'parameter')]
public function testParameter(ApplicationParameters $application, UserParameters $user): Response
#[GetPost(path: '/parameter', name: 'parameter')]
public function testParameter(Request $request, ApplicationParameters $application): Response
{
$application->getDate()
->setUpdateCalculations()
->setImport();

$application->getCustomer()
->setFax('fake');

$application->getDisplay()
->setDisplayMode(TableView::CUSTOM);

$application->getHomePage()
->setCalculations(8);

$application->getProduct();
$application->getDefault();

$application->getSecurity()
->setCaptcha(true)
->setLevel(StrengthLevel::MEDIUM);

$user->getHomePage()
->setCalculations(7);
$user->getOption()
->setPrintAddress(true);

$applicationSaved = $application->save();
$userSaved = $user->save();

return $this->json([
'application_saved' => $applicationSaved,
'user_saved' => $userSaved,

'application_display' => $application->getDisplay(),
'user_display' => $user->getDisplay(),

'application_home_page' => $application->getHomePage(),
'user_home_page' => $user->getHomePage(),

'application_option' => $application->getOption(),
'user_option' => $user->getOption(),
$form = $this->createForm(CustomerParameterType::class, $application->getCustomer());
if ($this->handleRequestForm($request, $form)) {
if ($application->save()) {
return $this->redirectToHomePage($this->trans('parameters.success'));
}
// return $this->redirectToHomePage();
}

'date' => $application->getDate(),
'customer' => $application->getCustomer(),
'security' => $application->getSecurity(),
return $this->render('test/parameter.html.twig', [
'form' => $form,
]);
}

Expand Down
64 changes: 64 additions & 0 deletions src/Form/Admin/CustomerParameterType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/*
* This file is part of the Calculation package.
*
* (c) bibi.nu <bibi@bibi.nu>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Form\Admin;

use App\Form\AbstractHelperType;
use App\Form\FormHelper;

class CustomerParameterType extends AbstractHelperType
{
public function __construct()
{
}

public function getBlockPrefix(): string
{
return 'customer';
}

protected function addFormFields(FormHelper $helper): void
{
$helper->field('name')
->updateOption('prepend_icon', 'fa-solid fa-user-group')
->addTextType();
$helper->field('address')
->updateOption('prepend_icon', 'fa-solid fa-location-dot')
->notRequired()
->addTextType();
$helper->field('zipCity')
->updateOption('prepend_icon', 'fa-solid fa-map-location-dot')
->notRequired()
->addTextType();
$helper->field('phone')
->updateOption('prepend_title', 'parameters.fields.customer_phone_title')
->notRequired()
->addTelType();
$helper->field('fax')
->notRequired()
->addFaxType();
$helper->field('email')
->updateOption('prepend_title', 'parameters.fields.customer_email_title')
->notRequired()
->addEmailType();
$helper->field('url')
->updateOption('prepend_title', 'parameters.fields.customer_url_title')
->notRequired()
->addUrlType();
}

protected function getLabelPrefix(): ?string
{
return 'parameters.fields.customer_';
}
}
38 changes: 38 additions & 0 deletions src/Form/Parameters/OptionParameterType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of the Calculation package.
*
* (c) bibi.nu <bibi@bibi.nu>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Form\Parameters;

use App\Form\AbstractHelperType;
use App\Form\FormHelper;

class OptionParameterType extends AbstractHelperType
{
public function getBlockPrefix(): string
{
return 'option';
}

protected function addFormFields(FormHelper $helper): void
{
$helper->field('printAddress')
// ->updateAttribute('data-default', $this->getDefaultValue('printAddress'))
->help('parameters.helps.qr_code')
->addCheckboxType();

$helper->field('qrCode')
// ->updateAttribute('data-default', $this->getDefaultValue('qrCode'))
->help('parameters.helps.print_address')
->addCheckboxType();
}
}
1 change: 1 addition & 0 deletions src/Reader/CSVReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected function getNextData($stream): ?array
{
$data = \fgetcsv($stream, $this->length, $this->separator, $this->enclosure, $this->escape);

/** @phpstan-var list<string>|null */
return \is_array($data) ? $data : null;
}
}
9 changes: 9 additions & 0 deletions templates/test/parameter.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'cards/card_edit.html.twig' %}
{%- set title = 'parameters.title' -%}
{%- set title_icon = 'cogs' -%}
{%- set title_description = 'parameters.description' -%}
{# javascript #}
{% block javascripts -%}
{{ parent() }}
{{- asset_js('js/application/validation_edit.js') }}
{% endblock %}
10 changes: 5 additions & 5 deletions tests/Command/FontAwesomeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FontAwesomeCommandTest extends CommandTestCase

public function testInvalidJson(): void
{
$input = ['source' => 'tests/data/json/fontawesome_invalid.json'];
$input = ['source' => 'tests/files/json/fontawesome_invalid.json'];
$output = $this->execute(
name: self::COMMAND_NAME,
input: $input,
Expand All @@ -35,7 +35,7 @@ public function testRawEmpty(): void
{
try {
$input = [
'source' => 'tests/data/json/fontawesome_raw_empty.json',
'source' => 'tests/files/json/fontawesome_raw_empty.json',
'target' => '/tests/Command/temp',
];
$output = $this->execute(
Expand All @@ -52,7 +52,7 @@ public function testSimulate(): void
{
try {
$input = [
'source' => 'tests/data/json/fontawesome_valid.json',
'source' => 'tests/files/json/fontawesome_valid.json',
'target' => '/tests/Command/temp',
'--dry-run' => true,
];
Expand All @@ -68,7 +68,7 @@ public function testSimulate(): void

public function testSourceEmpty(): void
{
$input = ['source' => 'tests/data/json/fontawesome_empty.json'];
$input = ['source' => 'tests/files/json/fontawesome_empty.json'];
$output = $this->execute(
name: self::COMMAND_NAME,
input: $input,
Expand All @@ -91,7 +91,7 @@ public function testSuccess(): void
{
try {
$input = [
'source' => 'tests/data/json/fontawesome_valid.json',
'source' => 'tests/files/json/fontawesome_valid.json',
'target' => '/tests/Command/temp',
];
$output = $this->execute(
Expand Down
10 changes: 5 additions & 5 deletions tests/Command/HeaderNameCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class HeaderNameCommandTest extends CommandTestCase
{
private const COMMAND_NAME = 'app:header:name';
private const DATA_PATH = '/tests/data/css';
private const DATA_PATH = '/tests/files/css';

protected function setUp(): void
{
Expand Down Expand Up @@ -127,8 +127,8 @@ public function testSetContent(): void
self::DATA_PATH,
'Skipped 2',
'Updated 2',
'tests/data/css/no_header.css',
'tests/data/css/old_header.css',
'tests/files/css/no_header.css',
'tests/files/css/old_header.css',
];
$input = [
'--pattern' => 'css',
Expand All @@ -141,11 +141,11 @@ public function testSetContent(): void

private function replaceCssContents(): void
{
$file = __DIR__ . '/../data/css/no_header.css';
$file = __DIR__ . '/../files/css/no_header.css';
if (\file_exists($file)) {
\file_put_contents($file, "html {\n width: 100vw;\n}\n");
}
$file = __DIR__ . '/../data/css/old_header.css';
$file = __DIR__ . '/../files/css/old_header.css';
if (\file_exists($file)) {
\file_put_contents($file, "/* old_header.css */\nhtml {\n width: 100vw;\n}\n");
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Command/WebpCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testExecuteDrySuccess(): void
'Skip: 0',
];
$input = [
'source' => '/tests/data/public/images/users',
'source' => '/tests/files/public/images/users',
'--dry-run' => true,
];
$output = $this->execute(self::COMMAND_NAME, $input);
Expand All @@ -51,7 +51,7 @@ public function testExecuteImageInvalid(): void
$name = 'example_invalid.png';
$path = FileUtils::tempDir(__DIR__);
self::assertIsString($path);
$source = FileUtils::buildPath(__DIR__, '/../data/images', $name);
$source = FileUtils::buildPath(__DIR__, '/../files/images', $name);
$target = FileUtils::buildPath($path, $name);
self::assertTrue(FileUtils::copy($source, $target));
$source = FileUtils::makePathRelative($path, __DIR__ . '/../..');
Expand Down Expand Up @@ -121,7 +121,7 @@ public function testExecuteSuccess(): void
$name = 'example.png';
$path = FileUtils::tempDir(__DIR__);
self::assertIsString($path);
$source = FileUtils::buildPath(__DIR__, '/../data/images', $name);
$source = FileUtils::buildPath(__DIR__, '/../files/images', $name);
$target = FileUtils::buildPath($path, $name);
self::assertTrue(FileUtils::copy($source, $target));
$source = FileUtils::makePathRelative($path, __DIR__ . '/../..');
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/AboutSymfonyControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function getRoutes(): \Iterator
$query = '/about/symfony/license?file=fake';
yield [$query, self::ROLE_ADMIN, Response::HTTP_OK, Request::METHOD_GET, true];

$query = '/about/symfony/license?file=tests/data/txt/empty.txt';
$query = '/about/symfony/license?file=tests/files/txt/empty.txt';
yield [$query, self::ROLE_ADMIN, Response::HTTP_OK, Request::METHOD_GET, true];
}
}
2 changes: 1 addition & 1 deletion tests/Controller/HelpControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private function checkUrl(string $url): void

private function getDownloadImage(): string
{
$path = __DIR__ . '/../data/images/example.png';
$path = __DIR__ . '/../files/images/example.png';
$type = \mime_content_type($path);
$data = (string) \file_get_contents($path);
$encoded = \base64_encode($data);
Expand Down
2 changes: 1 addition & 1 deletion tests/Controller/OpenWeatherControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private function getImportFile(): string
self::assertIsString($targetFile);
self::assertFileExists($targetFile);

$originFile = __DIR__ . '/../data/city/list.invalid.json.gz';
$originFile = __DIR__ . '/../files/city/list.invalid.json.gz';
self::assertFileExists($originFile);

FileUtils::copy($originFile, $targetFile, true);
Expand Down
4 changes: 0 additions & 4 deletions tests/Data/css/header.css

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Enums/ImageExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ImageExtensionTest extends TestCase
{
public static function getCreateImages(): \Iterator
{
$dir = \realpath(__DIR__ . '/../data/images');
$dir = \realpath(__DIR__ . '/../files/images');
yield [ImageExtension::BMP, $dir . '/example.bmp'];
yield [ImageExtension::GIF, $dir . '/example.gif'];
yield [ImageExtension::JPEG, $dir . '/example.jpeg'];
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixture/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function search(string $query, string $value, int $limit, int $mode = \SQ
protected function createSchema(): void
{
// load script
$file = __DIR__ . '/../data/sql/db_test.sql';
$file = __DIR__ . '/../files/sql/db_test.sql';
$sql = FileUtils::readFile($file);
if ('' === $sql) {
throw new \LogicException('Unable to find the schema.');
Expand Down
4 changes: 2 additions & 2 deletions tests/Form/Type/SimpleEditorTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testFormView(): void
*/
public function testInvalidJson(): void
{
$actionsPath = __DIR__ . '/../../data/json/fontawesome_invalid.json';
$actionsPath = __DIR__ . '/../../files/json/fontawesome_invalid.json';

$resolver = new OptionsResolver();
$view = $this->createMock(FormView::class);
Expand Down Expand Up @@ -70,7 +70,7 @@ public function testSubmit(): void

protected function getPreloadedExtensions(): array
{
$actionsPath = __DIR__ . '/../../../resources/data/simple_editor_actions.json';
$actionsPath = __DIR__ . '/../../../resources/files/simple_editor_actions.json';

return [new SimpleEditorType($actionsPath)];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Listener/VichListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private function createUser(?UploadedFile $file = null): User

private function getImagesPath(): string
{
return __DIR__ . '/../data/images/';
return __DIR__ . '/../files/images/';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Model/ImageDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ImageDataTest extends TestCase
{
public function testValidData(): void
{
$path = __DIR__ . '/../data/images/example.png';
$path = __DIR__ . '/../files/images/example.png';
$content = \file_get_contents($path);
self::assertIsString($content);
$imageData = ImageData::instance($content);
Expand Down
Loading

0 comments on commit 08aa19c

Please sign in to comment.