diff --git a/composer.json b/composer.json index 861782e4..00bc3ff0 100644 --- a/composer.json +++ b/composer.json @@ -52,13 +52,14 @@ "jms/serializer-bundle": "^2.0 || ^3.0", "liip/monitor-bundle": "^2.6", "matthiasnoback/symfony-config-test": "^4.0", - "matthiasnoback/symfony-dependency-injection-test": "^4.0", + "matthiasnoback/symfony-dependency-injection-test": "^4.1", "nelmio/api-doc-bundle": "^2.13", "sensio/framework-extra-bundle": "^5.5", "sonata-project/doctrine-orm-admin-bundle": "^3.19", "swiftmailer/swiftmailer": "^5.0 || ^6.0", "symfony/browser-kit": "^4.4 || ^5.1", "symfony/phpunit-bridge": "^5.1", + "symfony/swiftmailer-bundle": "^3.4", "symfony/yaml": "^4.4" }, "suggest": { diff --git a/src/Controller/Api/MessageController.php b/src/Controller/Api/MessageController.php index 744ab202..a6dbadab 100644 --- a/src/Controller/Api/MessageController.php +++ b/src/Controller/Api/MessageController.php @@ -21,12 +21,9 @@ use Sonata\NotificationBundle\Model\MessageManagerInterface; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\Annotation\Route; /** * @author Hugo Briand - * - * @Route(defaults={"_format": "json"}, requirements={"_format": "json|xml|html"}) */ class MessageController { @@ -54,8 +51,6 @@ public function __construct(MessageManagerInterface $messageManager, FormFactory * output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"={"sonata_api_read"}} * ) * - * @Rest\Get("/messages.{_format}", name="get_messages") - * * @Rest\QueryParam(name="page", requirements="\d+", default="1", description="Page for message list pagination") * @Rest\QueryParam(name="count", requirements="\d+", default="10", description="Number of messages by page") * @Rest\QueryParam(name="type", nullable=true, description="Message type filter") @@ -105,8 +100,6 @@ public function getMessagesAction(ParamFetcherInterface $paramFetcher) * } * ) * - * @Rest\Post("/messages.{_format}", name="post_message") - * * @Rest\View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true) * * @param Request $request A Symfony request diff --git a/src/Resources/config/routing/api.xml b/src/Resources/config/routing/api.xml index 313483e9..21a7361f 100644 --- a/src/Resources/config/routing/api.xml +++ b/src/Resources/config/routing/api.xml @@ -1,4 +1,9 @@ - + + json|xml|html + + + json|xml|html + diff --git a/tests/App/AppKernel.php b/tests/App/AppKernel.php index a13e8c7f..4cd0e72f 100644 --- a/tests/App/AppKernel.php +++ b/tests/App/AppKernel.php @@ -22,6 +22,7 @@ use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Bundle\SecurityBundle\SecurityBundle; +use Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle; use Symfony\Bundle\TwigBundle\TwigBundle; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -49,6 +50,7 @@ public function registerBundles() new JMSSerializerBundle(), new DoctrineBundle(), new NelmioApiDocBundle(), + new SwiftmailerBundle(), ]; } @@ -74,63 +76,14 @@ protected function configureRoutes(RouteCollectionBuilder $routes) protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader): void { - $containerBuilder->register('templating')->setSynthetic(true); - $containerBuilder->register('templating.locator')->setSynthetic(true); - $containerBuilder->register('templating.name_parser')->setSynthetic(true); - $containerBuilder->register('mailer')->setSynthetic(true); + $loader->load(__DIR__.'/config/config.yml'); + $loader->load(__DIR__.'/config/security.yml'); - $containerBuilder->loadFromExtension('framework', [ - 'secret' => '50n474.U53r', - 'session' => [ - 'handler_id' => 'session.handler.native_file', - 'storage_id' => 'session.storage.mock_file', - 'name' => 'MOCKSESSID', - ], - 'translator' => null, - 'validation' => [ - 'enabled' => true, - ], - 'form' => [ - 'enabled' => true, - ], - 'assets' => null, - 'test' => true, - 'profiler' => [ - 'enabled' => true, - 'collect' => false, - ], - ]); - - $containerBuilder->loadFromExtension('security', [ - 'firewalls' => ['api' => ['anonymous' => true]], - 'providers' => ['in_memory' => ['memory' => null]], - ]); - - $containerBuilder->loadFromExtension('twig', [ - 'strict_variables' => '%kernel.debug%', - 'exception_controller' => null, - ]); - - $containerBuilder->loadFromExtension('doctrine', [ - 'dbal' => [ - 'connections' => [ - 'default' => [ - 'driver' => 'pdo_sqlite', - ], - ], - ], - 'orm' => [ - 'default_entity_manager' => 'default', - ], - ]); - - $containerBuilder->loadFromExtension('fos_rest', [ - 'param_fetcher_listener' => true, - ]); + $containerBuilder->setParameter('app.base_dir', $this->getBaseDir()); } private function getBaseDir(): string { - return sys_get_temp_dir().'/sonata-notification-bundle/var/'; + return sys_get_temp_dir().'/sonata-notification-bundle/var/11aaasdqwedqweqdqwqwd'; } } diff --git a/tests/App/Entity/Message.php b/tests/App/Entity/Message.php new file mode 100644 index 00000000..60a30a9a --- /dev/null +++ b/tests/App/Entity/Message.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\NotificationBundle\Tests\App\Entity; + +use Doctrine\ORM\Mapping as ORM; +use Sonata\NotificationBundle\Entity\BaseMessage; + +/** + * @ORM\Entity + * @ORM\Table(name="notification__message") + */ +class Message extends BaseMessage +{ + /** + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") + */ + protected $id; +} diff --git a/tests/App/config/config.yml b/tests/App/config/config.yml new file mode 100644 index 00000000..475154b0 --- /dev/null +++ b/tests/App/config/config.yml @@ -0,0 +1,46 @@ +framework: + test: true + secret: '50n474.U53r' + form: + enabled: true + translator: + enabled: true + session: + handler_id: session.handler.native_file + storage_id: session.storage.mock_file + name: MOCKSESSID + profiler: + enabled: true + collect: false + +twig: + exception_controller: null + paths: + - '%kernel.project_dir%/templates' + strict_variables: "%kernel.debug%" + + +fos_rest: + param_fetcher_listener: true + body_listener: true + format_listener: true + view: + view_response_listener: force + body_converter: + enabled: false + validate: true + +doctrine: + dbal: + driver: pdo_sqlite + path: "%app.base_dir%sonata_notification_test.db3" + orm: + entity_managers: + default: + mappings: + SonataNotificationBundle: ~ + SonataNotificationTest: + type: annotation + dir: "%kernel.project_dir%/Entity" + is_bundle: false + prefix: Sonata\NotificationBundle\Tests\App\Entity diff --git a/tests/App/config/security.yml b/tests/App/config/security.yml new file mode 100644 index 00000000..fcf3d894 --- /dev/null +++ b/tests/App/config/security.yml @@ -0,0 +1,13 @@ +security: + role_hierarchy: ~ + + providers: + in_memory: + memory: + users: ~ + + firewalls: + test: + security: false + + access_control: ~ diff --git a/tests/App/templates/.gitkeep b/tests/App/templates/.gitkeep new file mode 100644 index 00000000..e69de29b