Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions src/CustomException/FileException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php


namespace App\CustomException;

use Throwable;

class FileException extends \Symfony\Component\HttpFoundation\File\Exception\FileException
{
public function __construct($message = "", $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
37 changes: 37 additions & 0 deletions src/Migrations/Version20191127143154.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20191127143154 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}

public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('DROP TABLE customer');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

il faudra que tu rebase ta table pour ne pas garder customer dans ta migration

$this->addSql('ALTER TABLE partner CHANGE project project VARCHAR(255) DEFAULT NULL');
}

public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('CREATE TABLE customer (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
$this->addSql('ALTER TABLE partner CHANGE project project VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`');
}
}
39 changes: 39 additions & 0 deletions src/Service/FileUploader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php


namespace App\Service;

use App\CustomException\FileException;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class FileUploader
{
private $targetDirectory;

// public function __construct($targetDirectory)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ne merge jamais de code commenté. Si tu n'as pas besoin de se bout de code tu le vire. Si tu n'en as pas besoin dans cette PR, tu le fais dans une pr distincte. 90% du code commenté reste du code mort

// {
// //$this->targetDirectory = $targetDirectory;
// }

public function upload(UploadedFile $file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type ta sortie

{
$originalFilename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
$safeFilename = transliterator_transliterate(
'Any-Latin; Latin-ASCII; [^A-Za-z0-9_] remove; Lower()',
$originalFilename
);
$fileName = $safeFilename.'-'.uniqid().'.'.$file->guessExtension();

try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ta méthode ne va pas car tu retourne soit ton $fileName, soit void. Dans ton cas, je retournerais toujours une string soit le filename, soit ''.

Du coup tu peux virer ton try catch qui ne te sert pas

$file->move($this->getTargetDirectory(), $fileName);
} catch (FileException $exception) {
}

return $fileName;
}

public function getTargetDirectory()
{
return $this->targetDirectory;
}
}
10 changes: 8 additions & 2 deletions tests/AppTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@ class AppTestCase extends WebTestCase
{
protected static $entities = [];

protected function setUp(): void
{
parent::setUp();
self::bootKernel();
}

public function saveEntity($JsonData)
{
$data = json_decode($JsonData, true);

$entity = self::bootKernel()->getContainer()->get(PartnerRepository::class)->find($data['id']);
$entity = self::$kernel->getContainer()->get(PartnerRepository::class)->find($data['id']);

self::$entities[] = $entity;
}

protected static function cleanUpDataBase()
{
/** @var EntityManager $entityManager */
$entityManager = self::bootKernel()->getContainer()->get('doctrine')->getManager();
$entityManager = self::$kernel->getContainer()->get('doctrine')->getManager();

foreach (self::$entities as $entity) {
$entityAttached = $entityManager->merge($entity);
Expand Down
1 change: 1 addition & 0 deletions tests/Large/Controller/PartnerControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PartnerControllerTest extends AppTestCase

protected function setUp(): void
{
parent::setUp();
$this->client = $this->createClient();
}

Expand Down
Binary file added tests/Large/Controller/star_wars.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tests/Medium/Repository/RepositoryTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait RepositoryTraitTest
public function setUp(): void
{
parent::setUp();
self::$kernel = self::bootKernel();
self::bootKernel();
}

public function initialState($entity)
Expand Down