diff --git a/src/CustomException/FileException.php b/src/CustomException/FileException.php new file mode 100644 index 0000000..2b34582 --- /dev/null +++ b/src/CustomException/FileException.php @@ -0,0 +1,14 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('DROP TABLE customer'); + $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`'); + } +} diff --git a/src/Service/FileUploader.php b/src/Service/FileUploader.php new file mode 100644 index 0000000..a41699e --- /dev/null +++ b/src/Service/FileUploader.php @@ -0,0 +1,39 @@ +targetDirectory = $targetDirectory; +// } + + public function upload(UploadedFile $file) + { + $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 { + $file->move($this->getTargetDirectory(), $fileName); + } catch (FileException $exception) { + } + + return $fileName; + } + + public function getTargetDirectory() + { + return $this->targetDirectory; + } +} diff --git a/tests/AppTestCase.php b/tests/AppTestCase.php index ef5fd12..496fa73 100644 --- a/tests/AppTestCase.php +++ b/tests/AppTestCase.php @@ -12,11 +12,17 @@ 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; } @@ -24,7 +30,7 @@ public function saveEntity($JsonData) 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); diff --git a/tests/Large/Controller/PartnerControllerTest.php b/tests/Large/Controller/PartnerControllerTest.php index 204e967..ff915d8 100644 --- a/tests/Large/Controller/PartnerControllerTest.php +++ b/tests/Large/Controller/PartnerControllerTest.php @@ -12,6 +12,7 @@ class PartnerControllerTest extends AppTestCase protected function setUp(): void { + parent::setUp(); $this->client = $this->createClient(); } diff --git a/tests/Large/Controller/star_wars.webp b/tests/Large/Controller/star_wars.webp new file mode 100644 index 0000000..02494f4 Binary files /dev/null and b/tests/Large/Controller/star_wars.webp differ diff --git a/tests/Medium/Repository/RepositoryTraitTest.php b/tests/Medium/Repository/RepositoryTraitTest.php index 62e1505..30747fc 100644 --- a/tests/Medium/Repository/RepositoryTraitTest.php +++ b/tests/Medium/Repository/RepositoryTraitTest.php @@ -10,7 +10,7 @@ trait RepositoryTraitTest public function setUp(): void { parent::setUp(); - self::$kernel = self::bootKernel(); + self::bootKernel(); } public function initialState($entity)