-
-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make API controller services public for FOSRest (#1654)
Fixes #1652
- Loading branch information
Jeroen de Kok
committed
Feb 10, 2020
1 parent
cf039fb
commit e9a4c7d
Showing
9 changed files
with
282 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\MediaBundle\Tests\App; | ||
|
||
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; | ||
use FOS\RestBundle\FOSRestBundle; | ||
use JMS\SerializerBundle\JMSSerializerBundle; | ||
use Nelmio\ApiDocBundle\NelmioApiDocBundle; | ||
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle; | ||
use Sonata\MediaBundle\SonataMediaBundle; | ||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; | ||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; | ||
use Symfony\Bundle\SecurityBundle\SecurityBundle; | ||
use Symfony\Bundle\TwigBundle\TwigBundle; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
use Symfony\Component\Routing\RouteCollectionBuilder; | ||
|
||
final class AppKernel extends Kernel | ||
{ | ||
use MicroKernelTrait; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct('test', false); | ||
} | ||
|
||
public function registerBundles() | ||
{ | ||
return [ | ||
new FrameworkBundle(), | ||
new SecurityBundle(), | ||
new TwigBundle(), | ||
new FOSRestBundle(), | ||
new SonataMediaBundle(), | ||
new JMSSerializerBundle(), | ||
new DoctrineBundle(), | ||
new NelmioApiDocBundle(), | ||
new SensioFrameworkExtraBundle(), | ||
]; | ||
} | ||
|
||
public function getCacheDir(): string | ||
{ | ||
return $this->getBaseDir().'cache'; | ||
} | ||
|
||
public function getLogDir(): string | ||
{ | ||
return $this->getBaseDir().'log'; | ||
} | ||
|
||
public function getProjectDir(): string | ||
{ | ||
return __DIR__; | ||
} | ||
|
||
protected function configureRoutes(RouteCollectionBuilder $routes) | ||
{ | ||
$routes->import(__DIR__.'/routes.yml', '/', 'yaml'); | ||
} | ||
|
||
protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader) | ||
{ | ||
$loader->load(__DIR__.'/config.yml'); | ||
$loader->load(__DIR__.'/security.yml'); | ||
$containerBuilder->setParameter('app.base_dir', $this->getBaseDir()); | ||
} | ||
|
||
private function getBaseDir(): string | ||
{ | ||
return sys_get_temp_dir().'/sonata-media-bundle/var/'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\MediaBundle\Tests\App\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Sonata\MediaBundle\Tests\Entity\Media as BaseMedia; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="media__media") | ||
*/ | ||
class Media extends BaseMedia | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* Get id. | ||
*/ | ||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
framework: | ||
secret: secret | ||
form: | ||
enabled: true | ||
translator: | ||
enabled: true | ||
|
||
twig: | ||
paths: | ||
- '%kernel.project_dir%/templates' | ||
|
||
sonata_media: | ||
db_driver: doctrine_orm | ||
class: | ||
media: Sonata\MediaBundle\Tests\App\Entity\Media | ||
default_context: default | ||
contexts: | ||
default: | ||
providers: | ||
- sonata.media.provider.dailymotion | ||
- sonata.media.provider.youtube | ||
- sonata.media.provider.image | ||
- sonata.media.provider.file | ||
- sonata.media.provider.vimeo | ||
|
||
formats: | ||
small: {width: 100, quality: 70} | ||
big: {width: 500, quality: 70} | ||
|
||
cdn: | ||
server: | ||
path: /uploads/media | ||
|
||
filesystem: | ||
local: | ||
directory: "%kernel.root_dir%/../public/uploads/media" | ||
create: false | ||
|
||
fos_rest: | ||
param_fetcher_listener: true | ||
body_listener: false | ||
format_listener: | ||
rules: | ||
- {path: ^/, priorities: [json], fallback_format: ~, prefer_extension: true} | ||
view: | ||
view_response_listener: true | ||
body_converter: | ||
enabled: false | ||
validate: false | ||
|
||
sensio_framework_extra: | ||
router: {annotations: true} | ||
request: {converters: true} | ||
view: {annotations: true} | ||
|
||
doctrine: | ||
dbal: | ||
driver: pdo_sqlite | ||
path: "%app.base_dir%sonata_media_test.db3" | ||
orm: | ||
entity_managers: | ||
default: | ||
mappings: | ||
SonataMediaBundle: ~ | ||
SonataMediaTest: | ||
type: annotation | ||
dir: "%kernel.project_dir%/Entity" | ||
is_bundle: false | ||
prefix: Sonata\MediaBundle\Tests\App\Entity | ||
|
||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sonata_api_media: | ||
type: rest | ||
prefix: /api | ||
resource: "@SonataMediaBundle/Resources/config/routing/api.xml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
security: | ||
role_hierarchy: ~ | ||
|
||
providers: | ||
in_memory: | ||
memory: | ||
users: ~ | ||
|
||
firewalls: | ||
test: | ||
security: false | ||
|
||
access_control: ~ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\MediaBundle\Tests\Functional; | ||
|
||
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\CreateSchemaDoctrineCommand; | ||
use Sonata\MediaBundle\Tests\App\AppKernel; | ||
use Symfony\Bundle\FrameworkBundle\Client; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\ConsoleOutput; | ||
|
||
final class MediaControllerTest extends WebTestCase | ||
{ | ||
public function testGetMediaAction(): void | ||
{ | ||
$kernel = new AppKernel(); | ||
$kernel->boot(); | ||
|
||
$application = new Application($kernel); | ||
$application->setAutoExit(false); | ||
|
||
$application->run(new ArrayInput([ | ||
'command' => 'doctrine:database:drop', | ||
'--force' => '1', | ||
])); | ||
|
||
$application->run(new ArrayInput([ | ||
'command' => 'doctrine:database:create', | ||
])); | ||
|
||
$command = new CreateSchemaDoctrineCommand(); | ||
$application->add($command); | ||
$input = new ArrayInput([ | ||
'command' => 'doctrine:schema:create', | ||
]); | ||
$input->setInteractive(false); | ||
|
||
$command->run($input, new ConsoleOutput()); | ||
|
||
$client = new Client($kernel); | ||
$client->request('GET', '/api/media'); | ||
$this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
} | ||
} |