diff --git a/composer.json b/composer.json index 9a882bf4..9a8858c3 100644 --- a/composer.json +++ b/composer.json @@ -23,38 +23,41 @@ "require": { "php": "^7.2", "doctrine/doctrine-bundle": "^1.12 || ^2.0", - "doctrine/persistence": "^1.3", + "doctrine/persistence": "^1.3.4", "sonata-project/datagrid-bundle": "^2.5", "sonata-project/doctrine-extensions": "^1.5", "sonata-project/form-extensions": "^0.1 || ^1.4", "symfony/config": "^4.4", "symfony/console": "^4.4", - "symfony/dependency-injection": "^4.4", + "symfony/dependency-injection": "^4.4.3", "symfony/doctrine-bridge": "^4.4", "symfony/event-dispatcher": "^4.4", - "symfony/event-dispatcher-contracts": "^1.1", + "symfony/event-dispatcher-contracts": "^1.1.1", "symfony/form": "^4.4", "symfony/http-foundation": "^4.4", "symfony/http-kernel": "^4.4", "symfony/security-core": "^4.4", - "zendframework/zenddiagnostics": "^1.0" + "zendframework/zenddiagnostics": "^1.0.2" }, "conflict": { - "friendsofsymfony/rest-bundle": "<2.1 || >=3.0", + "friendsofsymfony/rest-bundle": "<2.1", "jms/serializer": "<0.13", "sonata-project/admin-bundle": "<3.1", "sonata-project/core-bundle": "<3.20" }, "require-dev": { "enqueue/amqp-lib": "^0.8", - "friendsofsymfony/rest-bundle": "^2.1", + "friendsofsymfony/rest-bundle": "^2.6 || ^3.0", "guzzlehttp/guzzle": "^3.8", "jms/serializer-bundle": "^2.0 || ^3.0", - "liip/monitor-bundle": "^2.0", - "nelmio/api-doc-bundle": "^2.4", - "sonata-project/doctrine-orm-admin-bundle": "^3.4", + "liip/monitor-bundle": "^2.6.1", + "nelmio/api-doc-bundle": "^2.13.3", + "sensio/framework-extra-bundle": "^5.5", + "sonata-project/doctrine-orm-admin-bundle": "^3.19", "swiftmailer/swiftmailer": "^5.0 || ^6.0", - "symfony/phpunit-bridge": "^5.0" + "symfony/browser-kit": "^4.4 || ^5.1", + "symfony/phpunit-bridge": "^5.1", + "symfony/yaml": "^4.4" }, "suggest": { "guzzlehttp/guzzle": "If you want to get a status report when using the rabbitMQ backend.", diff --git a/src/Controller/Api/MessageController.php b/src/Controller/Api/MessageController.php index 9b2a1583..aad245d8 100644 --- a/src/Controller/Api/MessageController.php +++ b/src/Controller/Api/MessageController.php @@ -13,6 +13,8 @@ namespace Sonata\NotificationBundle\Controller\Api; +use FOS\RestBundle\Controller\Annotations\Get; +use FOS\RestBundle\Controller\Annotations\Post; use FOS\RestBundle\Controller\Annotations\QueryParam; use FOS\RestBundle\Controller\Annotations\Route; use FOS\RestBundle\Controller\Annotations\View; @@ -53,6 +55,8 @@ public function __construct(MessageManagerInterface $messageManager, FormFactory * output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"={"sonata_api_read"}} * ) * + * @Get("/messages", name="get_messages") + * * @QueryParam(name="page", requirements="\d+", default="1", description="Page for message list pagination") * @QueryParam(name="count", requirements="\d+", default="10", description="Number of messages by page") * @QueryParam(name="type", nullable=true, description="Message type filter") @@ -102,6 +106,8 @@ public function getMessagesAction(ParamFetcherInterface $paramFetcher) * } * ) * + * @Post("/messages", name="post_message") + * * @View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true) * * @Route(requirements={"_format"="json|xml"}) diff --git a/src/Resources/config/routing/api.xml b/src/Resources/config/routing/api.xml index 9f4f1da5..313483e9 100644 --- a/src/Resources/config/routing/api.xml +++ b/src/Resources/config/routing/api.xml @@ -1,4 +1,4 @@ - - + + diff --git a/tests/App/AppKernel.php b/tests/App/AppKernel.php new file mode 100644 index 00000000..af7289f7 --- /dev/null +++ b/tests/App/AppKernel.php @@ -0,0 +1,134 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\NotificationBundle\Tests\App; + +use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; +use FOS\RestBundle\FOSRestBundle; +use JMS\SerializerBundle\JMSSerializerBundle; +use Nelmio\ApiDocBundle\NelmioApiDocBundle; +use Sonata\NotificationBundle\SonataNotificationBundle; +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 SonataNotificationBundle(), + new JMSSerializerBundle(), + new DoctrineBundle(), + new NelmioApiDocBundle(), + ]; + } + + 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($this->getProjectDir().'/config/routes.yaml'); + } + + 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); + + $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, + ]); + } + + private function getBaseDir(): string + { + return sys_get_temp_dir().'/sonata-notification-bundle/var/'; + } +} diff --git a/tests/App/config/routes.yaml b/tests/App/config/routes.yaml new file mode 100644 index 00000000..fb318861 --- /dev/null +++ b/tests/App/config/routes.yaml @@ -0,0 +1,7 @@ +#NelmioApiDocBundle: +# prefix: /api/doc +# resource: "@NelmioApiDocBundle/Resources/config/routing.yml" + +sonata_api_notification: + prefix: /api/notification + resource: "@SonataNotificationBundle/Resources/config/routing/api.xml" diff --git a/tests/Controller/Api/MessageControllerTest.php b/tests/Controller/Api/MessageControllerTest.php index 36ab139f..1d57ae43 100644 --- a/tests/Controller/Api/MessageControllerTest.php +++ b/tests/Controller/Api/MessageControllerTest.php @@ -13,7 +13,7 @@ namespace Sonata\NotificationBundle\Tests\Controller\Api; -use FOS\RestBundle\Request\ParamFetcher; +use FOS\RestBundle\Request\ParamFetcherInterface; use PHPUnit\Framework\TestCase; use Sonata\NotificationBundle\Controller\Api\MessageController; use Sonata\NotificationBundle\Model\MessageInterface; @@ -34,7 +34,7 @@ public function testGetMessagesAction(): void $messageManager = $this->createMock(MessageManagerInterface::class); $messageManager->expects($this->once())->method('getPager')->willReturn([]); - $paramFetcher = $this->createMock(ParamFetcher::class); + $paramFetcher = $this->createMock(ParamFetcherInterface::class); $paramFetcher->expects($this->exactly(3))->method('get'); $paramFetcher->expects($this->once())->method('all')->willReturn([]); diff --git a/tests/Functional/RoutingTest.php b/tests/Functional/RoutingTest.php new file mode 100644 index 00000000..2e4e5d08 --- /dev/null +++ b/tests/Functional/RoutingTest.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\NotificationBundle\Tests\Functional\Routing; + +use Sonata\NotificationBundle\Tests\App\AppKernel; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; + +/** + * @author Javier Spagnoletti + */ +final class RoutingTest extends WebTestCase +{ + /** + * @group legacy + * + * @dataProvider getRoutes + */ + public function testRoutes(string $name, string $path, array $methods): void + { + $client = static::createClient(); + $router = $client->getContainer()->get('router'); + + $route = $router->getRouteCollection()->get($name); + + $this->assertNotNull($route); + $this->assertSame($path, $route->getPath()); + $this->assertEmpty(array_diff($methods, $route->getMethods())); + } + + public function getRoutes(): iterable + { + //yield ['nelmio_api_doc_index', '/api/doc/{view}', ['GET']]; + yield ['sonata_api_notification_message_get_messages', '/api/notification/messages', ['GET']]; + yield ['sonata_api_notification_message_post_message', '/api/notification/messages', ['POST']]; + } + + protected static function getKernelClass(): string + { + return AppKernel::class; + } +}