Skip to content

Commit

Permalink
Merge pull request #19 from PlumTreeSystems/symfony6
Browse files Browse the repository at this point in the history
upgraded to symfony 6.2
  • Loading branch information
MariusAmbr authored Apr 5, 2023
2 parents a3bd3a4 + 677ca63 commit 92a9257
Show file tree
Hide file tree
Showing 12 changed files with 4,175 additions and 2,632 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
###> phpunit/phpunit ###
/phpunit.xml
###< phpunit/phpunit ###

/.phpunit.cache
/.phpunit.result.cache
/.idea
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/tmp/FileBundle": "${workspaceRoot}",
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"args": ["--no-coverage", "--filter", "${fileBasenameNoExtension}"],
"program": "${workspaceRoot}/vendor/bin/phpunit",
"cwd": "${workspaceRoot}",
"port": 9003
}
]
}
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
6 changes: 3 additions & 3 deletions Tests/Form/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getExtensions()

public function testCreateViewSingle()
{
$formData = [];
$formData = null;
$form = $this->factory->create(PTSFileType::class);
$form->submit($formData);
$this->assertTrue($form->isSynchronized());
Expand Down Expand Up @@ -164,7 +164,7 @@ public function testInitializedMulti(RequestHandlerInterface $requestHandler)
->getMock();

$initial = [$ptsFile, $ptsFile2];
$form = $this->factory->createBuilder(PTSFileType::class, $initial, ['multiple' => true])
$form = $this->factory->createBuilder(PTSFileType::class, $initial, ['multiple' => true, 'expanded' => true])
->setRequestHandler($requestHandler)
->getForm();

Expand Down Expand Up @@ -249,7 +249,7 @@ public function testNativeWithBuilder()
$this->assertInstanceOf(File::class, $resolvedData['file']);
}

public function requestHandlerProvider()
static function requestHandlerProvider()
{
return [
[new HttpFoundationRequestHandler()],
Expand Down
69 changes: 53 additions & 16 deletions Tests/Service/FileManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Doctrine\Persistence\ObjectRepository;
use Gaufrette\Filesystem;
use PHPUnit\Framework\MockObject\MockObject;
use PlumTreeSystems\FileBundle\Entity\File;
use PlumTreeSystems\FileBundle\Model\FileManagerInterface;
use PlumTreeSystems\FileBundle\Model\FileSystemFactoryInterface;
use PlumTreeSystems\FileBundle\Service\FileSystemFactory;
use PlumTreeSystems\FileBundle\Service\GaufretteFileManager;
use PlumTreeSystems\FileBundle\Tests\Service\FileManagerTest\TestFile;
use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

Expand Down Expand Up @@ -50,6 +53,8 @@ class FileManagerTest extends TypeTestCase
*/
private $fileManager;

private RequestStack $rs;

/**
* @var array
*/
Expand Down Expand Up @@ -93,7 +98,7 @@ public function setUp(): void
->willReturn($this->filesystem);

$this->entityManager = $this
->getMockBuilder(EntityManager::class)
->getMockBuilder(\Doctrine\Persistence\ObjectManager::class)
->disableOriginalConstructor()
->getMock();

Expand All @@ -102,11 +107,21 @@ public function setUp(): void
$this->router = $this->getMockBuilder(UrlGeneratorInterface::class)
->getMock();

$this->fileManager = new GaufretteFileManager(
$filesystemFactory,
$this->rs = $this->getMockBuilder(RequestStack::class)
->getMock();

$this->fileManager = $this->buildFileManager($filesystemFactory);
}

private function buildFileManager(FileSystemFactoryInterface $fs): GaufretteFileManager {
return new GaufretteFileManager(
$fs,
$this->entityManager,
$this->router,
$this->class
$this->rs,
[],
$this->class,
"local"
);
}

Expand All @@ -123,13 +138,19 @@ public function tearDown(): void

public function testGetFileReference()
{
$this->filesystem
->expects($this->once())
->method('has')
->willReturn(true);

$this->filesystem
->expects($this->once())
->method('get')
->willReturn($this
->getMockBuilder(\Gaufrette\File::class)
->disableOriginalConstructor()
->getMock());
->getMock()
);

$file = new $this->class();

Expand Down Expand Up @@ -157,8 +178,7 @@ public function testSave()
$this->config
);

$this->fileManager =
new GaufretteFileManager($fileSystemFactory, $this->entityManager, $this->router, $this->class);
$this->fileManager = $this->buildFileManager($fileSystemFactory);

/**
* @var File $file
Expand All @@ -177,6 +197,12 @@ public function testSave()

public function testGetByName()
{

$this->filesystem
->expects($this->once())
->method('has')
->willReturn(true);

$this->filesystem
->expects($this->once())
->method('get')
Expand All @@ -186,7 +212,7 @@ public function testGetByName()
->getMock());

$mockpository = $this
->getMockBuilder(EntityRepository::class)
->getMockBuilder(ObjectRepository::class)
->disableOriginalConstructor()
->getMock();

Expand All @@ -207,6 +233,11 @@ public function testGetByName()

public function testGetById()
{
$this->filesystem
->expects($this->once())
->method('has')
->willReturn(true);

$this->filesystem
->expects($this->once())
->method('get')
Expand All @@ -216,7 +247,7 @@ public function testGetById()
->getMock());

$mockpository = $this
->getMockBuilder(EntityRepository::class)
->getMockBuilder(ObjectRepository::class)
->disableOriginalConstructor()
->getMock();

Expand All @@ -240,6 +271,11 @@ public function testRemove()
$file = new $this->class();
$file->setName('test');

$this->filesystem
->expects($this->atLeastOnce())
->method('has')
->willReturn(true);

$this->filesystem
->expects($this->once())
->method('delete')
Expand All @@ -253,6 +289,11 @@ public function testRemoveEntity()
$file = new $this->class();
$file->setName('test');

$this->filesystem
->expects($this->atLeastOnce())
->method('has')
->willReturn(true);

$this->filesystem
->expects($this->exactly(2))
->method('delete')
Expand Down Expand Up @@ -294,7 +335,7 @@ public function testGenerateRemoveUrl()
->with($this->isType('string'), $this->isType('array'))
->willReturn($url);

$returned = $this->fileManager->generateRemoveUrl($file);
$returned = $this->fileManager->generateRemoveUrl($file, "");
$this->assertEquals($url, $returned);
}

Expand Down Expand Up @@ -322,8 +363,7 @@ public function testDownloadFile()
$this->config
);

$this->fileManager =
new GaufretteFileManager($fileSystemFactory, $this->entityManager, $this->router, $this->class);
$this->fileManager = $this->buildFileManager($fileSystemFactory);

/**
* @var File $file
Expand All @@ -342,10 +382,7 @@ public function testDownloadFile()
$response->headers->get('Content-Disposition'),
'attachment; filename="' . $returned->getOriginalName() . '";'
);
$this->assertEquals(
$response->headers->get('Content-type'),
$file->getContextValue('Content-Type')
);

$this->assertEquals(
$response->headers->get('Cache-Control'),
'private'
Expand Down
11 changes: 11 additions & 0 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Symfony\Component\Dotenv\Dotenv;

require dirname(__DIR__) . '/vendor/autoload.php';

if (file_exists(dirname(__DIR__) . '/config/bootstrap.php')) {
require dirname(__DIR__) . '/config/bootstrap.php';
} elseif (method_exists(Dotenv::class, 'bootEnv')) {
(new Dotenv())->bootEnv(dirname(__DIR__) . '/.env');
}
34 changes: 19 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@
"type": "symfony-bundle",
"license": "MIT",
"require": {
"php": ">=7.2",
"php": ">=8.0",
"ext-ctype": "*",
"ext-iconv": "*",
"ext-json": "*",
"doctrine/common": "^3.0",
"gaufrette/aws-s3-adapter": "^0.4.0",
"google/apiclient": "^2.0",
"knplabs/gaufrette": "^0.9",
"symfony/console": "^5.0",
"symfony/dotenv": "^5.0",
"knplabs/gaufrette": "^0.11",
"symfony/console": "^6.2",
"symfony/dotenv": "^6.2",
"symfony/flex": "^1.15",
"symfony/form": "^5.0",
"symfony/framework-bundle": "^5.0",
"symfony/security-bundle": "^5.0",
"symfony/twig-bundle": "^5.0",
"symfony/validator": "^5.0",
"symfony/yaml": "^5.0"
"symfony/form": "^6.2",
"symfony/framework-bundle": "^6.2",
"symfony/mime": "^6.2",
"symfony/security-bundle": "^6.2",
"symfony/twig-bundle": "^6.2",
"symfony/validator": "^6.2",
"symfony/yaml": "^6.2"
},
"config": {
"preferred-install": {
"*": "dist"
},
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"symfony/flex": true
}
},
"autoload": {
"psr-4": {
Expand All @@ -38,10 +42,10 @@
}
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"symfony/browser-kit": "^5.0",
"symfony/css-selector": "^5.0",
"symfony/phpunit-bridge": "^5.0"
"phpunit/phpunit": "^10.0",
"symfony/browser-kit": "^6.0",
"symfony/css-selector": "^6.0",
"symfony/phpunit-bridge": "^6.0"
},
"scripts": {
"auto-scripts": {
Expand Down
Loading

0 comments on commit 92a9257

Please sign in to comment.