From 09f243bf8ac16db976ebc12e0724516bf89bee2a Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Sun, 5 Jul 2020 18:22:16 -0300 Subject: [PATCH] Add "friendsofsymfony/user-bundle" to development dependencies --- .travis.yml | 12 +++-- Command/AutoClosingCommand.php | 10 +++-- Command/TicketManagerCommand.php | 4 ++ Makefile | 20 ++++----- README.md | 6 +-- Tests/Functional/Command/ApplicationTest.php | 35 +++++++++++++++ Tests/Functional/Entity/User.php | 41 +++++------------ Tests/Functional/TestKernel.php | 46 ++++++++++++++++---- composer.json | 33 +++++++------- 9 files changed, 130 insertions(+), 77 deletions(-) create mode 100644 Tests/Functional/Command/ApplicationTest.php diff --git a/.travis.yml b/.travis.yml index 36635248..fd64ce59 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,17 +22,15 @@ matrix: - php: 5.6 env: SYMFONY_VERSION="~2.8.0" SYMFONY_PHPUNIT_VERSION="5.7.27" - php: 5.6 - env: SYMFONY_VERSION="~3.0.0" SYMFONY_PHPUNIT_VERSION="5.7.27" - - php: 5.6 - env: SYMFONY_VERSION="~3.1.0" SYMFONY_PHPUNIT_VERSION="5.7.27" - - php: 5.6 - env: SYMFONY_VERSION="~3.2.0" SYMFONY_PHPUNIT_VERSION="5.7.27" + env: SYMFONY_VERSION="~3.4.0" SYMFONY_PHPUNIT_VERSION="5.7.27" - php: 5.6 env: INSTALL_VICH_UPLOADER_BUNDLE=true SYMFONY_PHPUNIT_VERSION="5.7.27" - php: 7.0 env: SYMFONY_PHPUNIT_VERSION="5.7.27" - php: 7.4 env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_PHPUNIT_VERSION="5.7.27" + - php: 7.4 + env: INSTALL_VICH_UPLOADER_BUNDLE=true allow_failures: - php: nightly - env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_PHPUNIT_VERSION="5.7.27" @@ -48,8 +46,8 @@ before_script: - if [ "$GITHUB_OAUTH_TOKEN" != "" ]; then echo -e $GITHUB_OAUTH_TOKEN && composer config -g github-oauth.github.com $GITHUB_OAUTH_TOKEN; fi; - if [ 70100 -gt $(php -r 'echo PHP_VERSION_ID;') ]; then composer remove --dev "phpstan/phpstan" --no-update; fi; - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi; - - if [ -n $INSTALL_VICH_UPLOADER_BUNDLE ]; then composer require "vich/uploader-bundle" --no-update; fi; + - if [ ! -z $INSTALL_VICH_UPLOADER_BUNDLE ]; then composer require "vich/uploader-bundle" --no-update; fi; - COMPOSER_MEMORY_LIMIT=-1 composer update --prefer-dist --no-interaction $COMPOSER_FLAGS script: - - if [[ -n $INSTALL_VICH_UPLOADER_BUNDLE ]]; then make test_with_vichuploaderbundle; else make test; fi; + - if [ ! -z $INSTALL_VICH_UPLOADER_BUNDLE ]; then make test_with_vichuploaderbundle; else make test; fi; diff --git a/Command/AutoClosingCommand.php b/Command/AutoClosingCommand.php index 2529dac5..b7743677 100644 --- a/Command/AutoClosingCommand.php +++ b/Command/AutoClosingCommand.php @@ -44,7 +44,11 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $ticket_manager = $this->getContainer()->get('hackzilla_ticket.ticket_manager'); + if (!$this->getContainer()->has('fos_user.user_manager')) { + throw new \RuntimeException(sprintf('Command "%s" requires the service "fos_user.user_manager". Is "friendsofsymfony/user-bundle" installed and enabled?', $this->getName())); + } + + $ticketManager = $this->getContainer()->get('hackzilla_ticket.ticket_manager'); $userManager = $this->getContainer()->get('fos_user.user_manager'); $ticketRepository = $this->getContainer()->get('doctrine')->getRepository('HackzillaTicketBundle:Ticket'); @@ -59,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $resolved_tickets = $ticketRepository->getResolvedTicketOlderThan($input->getOption('age')); foreach ($resolved_tickets as $ticket) { - $message = $ticket_manager->createMessage() + $message = $ticketManager->createMessage() ->setMessage( $translator->trans('MESSAGE_STATUS_CHANGED', ['%status%' => $translator->trans('STATUS_CLOSED', [], $translationDomain)], $translationDomain) ) @@ -69,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ->setTicket($ticket); $ticket->setStatus(TicketMessage::STATUS_CLOSED); - $ticket_manager->updateTicket($ticket, $message); + $ticketManager->updateTicket($ticket, $message); $output->writeln('The ticket "'.$ticket->getSubject().'" has been closed.'); } diff --git a/Command/TicketManagerCommand.php b/Command/TicketManagerCommand.php index c0a80f4c..48fa8f6c 100644 --- a/Command/TicketManagerCommand.php +++ b/Command/TicketManagerCommand.php @@ -49,6 +49,10 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + if (!$this->getContainer()->has('fos_user.user_manager')) { + throw new \RuntimeException(sprintf('Command "%s" requires the service "fos_user.user_manager". Is "friendsofsymfony/user-bundle" installed and enabled?', $this->getName())); + } + $userManager = $this->getContainer()->get('fos_user.user_manager'); $ticketManager = $this->getContainer()->get('hackzilla_ticket.ticket_manager'); diff --git a/Makefile b/Makefile index c604e1a9..139cd7c3 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,10 @@ cs: vendor/bin/php-cs-fixer fix --verbose +.PHONY: cs cs_dry_run: vendor/bin/php-cs-fixer fix --verbose --dry-run - -test: - vendor/bin/simple-phpunit -c phpunit.xml.dist --exclude-group vichuploaderbundle - -test_with_vichuploaderbundle: - vendor/bin/simple-phpunit -c phpunit.xml.dist +.PHONY: cs_dry_run all: @echo "Please choose a task." @@ -61,13 +57,17 @@ build: mkdir $@ test: +ifeq ($(shell php --modules|grep --quiet pcov;echo $$?), 0) + vendor/bin/simple-phpunit -c phpunit.xml.dist --coverage-clover build/logs/clover.xml --exclude-group vichuploaderbundle +else + vendor/bin/simple-phpunit -c phpunit.xml.dist --exclude-group vichuploaderbundle +endif +.PHONY: test + +test_with_vichuploaderbundle: ifeq ($(shell php --modules|grep --quiet pcov;echo $$?), 0) vendor/bin/simple-phpunit -c phpunit.xml.dist --coverage-clover build/logs/clover.xml else vendor/bin/simple-phpunit -c phpunit.xml.dist endif .PHONY: test - -docs: - cd docs && sphinx-build -W -b html -d _build/doctrees . _build/html -.PHONY: docs diff --git a/README.md b/README.md index 566fab59..d5a575cb 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Available translations for: ## Requirements * PHP >= 5.6 -* [Symfony][1] ^2.8|^3.0|^4.0 +* [Symfony][1] ^2.8|^3.4|^4.0 * [Knp Paginator bundle][2] * [Bootstrap v3][3] (optional) see: [http://symfony.com/blog/new-in-symfony-2-6-bootstrap-form-theme][4] @@ -31,8 +31,8 @@ Available translations for: | Ticket Bundle | Symfony | PHP | | --------------| ---------------- | ----- | -| [3.x][6] | ^2.8\|^3.0\|^4.0 | >=5.6 | -| [2.x][7] | ^2.7\|^3.0 | >=5.3 | +| [3.x][6] | ^2.8\|^3.4\|^4.0 | >=5.6 | +| [2.x][7] | ^2.7\|^3.4 | >=5.3 | | [1.x][8] | ^2.3 | >=5.3 | | [0.x][9] | ^2.3 | >=5.3 | diff --git a/Tests/Functional/Command/ApplicationTest.php b/Tests/Functional/Command/ApplicationTest.php new file mode 100644 index 00000000..3bd4f563 --- /dev/null +++ b/Tests/Functional/Command/ApplicationTest.php @@ -0,0 +1,35 @@ + + */ +final class ApplicationTest extends WebTestCase +{ + /** + * @dataProvider getCommands + * + * @param string $expectedClass + * @param string $commandName + */ + public function testCommandRegistration($expectedClass, $commandName) + { + $application = new Application(static::$kernel); + + $this->assertInstanceOf($expectedClass, $application->find($commandName)); + } + + public function getCommands() + { + return [ + [AutoClosingCommand::class, 'ticket:autoclosing'], + [TicketManagerCommand::class, 'ticket:create'], + ]; + } +} diff --git a/Tests/Functional/Entity/User.php b/Tests/Functional/Entity/User.php index 55a9632c..53280c8a 100644 --- a/Tests/Functional/Entity/User.php +++ b/Tests/Functional/Entity/User.php @@ -2,38 +2,21 @@ namespace Hackzilla\Bundle\TicketBundle\Tests\Functional\Entity; -use Hackzilla\Bundle\TicketBundle\Model\UserInterface; +use Doctrine\ORM\Mapping as ORM; +use FOS\UserBundle\Model\User as BaseUser; /** + * @ORM\Entity + * @ORM\Table(name="fos_user") + * * @author Javier Spagnoletti */ -final class User implements UserInterface +class User extends BaseUser { - public function getId() - { - } - - public function getUsername() - { - } - - public function getEmail() - { - } - - public function getRoles() - { - } - - public function getPassword() - { - } - - public function getSalt() - { - } - - public function eraseCredentials() - { - } + /** + * @ORM\Id + * @ORM\Column(type="integer") + * @ORM\GeneratedValue(strategy="AUTO") + */ + protected $id; } diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index d531aee3..d5244579 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -3,6 +3,7 @@ namespace Hackzilla\Bundle\TicketBundle\Tests\Functional; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; +use FOS\UserBundle\FOSUserBundle; use Hackzilla\Bundle\TicketBundle\HackzillaTicketBundle; use Hackzilla\Bundle\TicketBundle\Tests\Functional\Entity\User; use Knp\Bundle\PaginatorBundle\KnpPaginatorBundle; @@ -41,6 +42,7 @@ public function registerBundles() new FrameworkBundle(), new SecurityBundle(), new DoctrineBundle(), + new FOSUserBundle(), new KnpPaginatorBundle(), new TwigBundle(), new HackzillaTicketBundle(), @@ -96,11 +98,20 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load $c->loadFromExtension('framework', [ 'secret' => 'MySecretKey', 'default_locale' => 'en', + 'session' => [ + 'handler_id' => 'session.handler.native_file', + 'storage_id' => 'session.storage.mock_file', + 'name' => 'MOCKSESSID', + ], 'translator' => [ 'fallbacks' => [ 'en', ], ], + 'form' => null, + 'validation' => [ + 'enabled' => true, + ], ]); // SecurityBundle config @@ -131,13 +142,23 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load ], 'orm' => [ 'default_entity_manager' => 'default', + 'auto_mapping' => true, + 'mappings' => [ + 'HackzillaTicketBundle' => [ + 'dir' => __DIR__.'/Entity', + 'prefix' => 'Hackzilla\Bundle\TicketBundle\Tests\Functional\Entity', + 'alias' => 'HackzillaTicketBundle', + 'type' => 'annotation', + ], + ], ], ]); // TwigBundle config $twigConfig = [ - 'strict_variables' => '%kernel.debug%', - 'autoescape' => 'name', + 'strict_variables' => '%kernel.debug%', + 'exception_controller' => null, + 'autoescape' => 'name', ]; // "default_path" configuration is available since version 3.4. if (version_compare(self::VERSION, '3.4', '>=')) { @@ -145,6 +166,20 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load } $c->loadFromExtension('twig', $twigConfig); + // FOSUserBundle config + $c->loadFromExtension('fos_user', [ + 'user_class' => User::class, + 'db_driver' => 'orm', + 'firewall_name' => 'api', + 'from_email' => [ + 'address' => 'no-reply@example.com', + 'sender_name' => 'HackzillaTicketBundle', + ], + 'service' => [ + 'mailer' => 'fos_user.mailer.noop', + ], + ]); + // HackzillaBundle config $c->loadFromExtension('hackzilla_ticket', [ 'user_class' => User::class, @@ -152,13 +187,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load ]); if ($this->useVichUploaderBundle) { - // FrameworkBundle config - // "framework.form" is required since "vich_uploader.namer_directory_property" - // service uses "form.property_accessor" service. - $c->loadFromExtension('framework', [ - 'form' => null, - ]); - // VichUploaderBundle config $c->loadFromExtension('vich_uploader', [ 'db_driver' => 'orm', diff --git a/composer.json b/composer.json index 0a08d1b6..5fda9303 100644 --- a/composer.json +++ b/composer.json @@ -28,30 +28,31 @@ "php": "^5.6 || ^7.0", "doctrine/doctrine-bundle": "^1.4 || ^2.0", "doctrine/orm": "^2.4.8", - "knplabs/knp-paginator-bundle": "^2.6 || ^3.0 || ^4.0 || ^5.0", - "symfony/config": "^2.8 || ^3.0 || ^4.0", - "symfony/console": "^2.8 || ^3.0 || ^4.0", - "symfony/dependency-injection": "^2.8 || ^3.0 || ^4.0", - "symfony/event-dispatcher": "^2.8 || ^3.0 || ^4.0", - "symfony/form": "^2.8 || ^3.0 || ^4.0", - "symfony/framework-bundle": "^2.8.1 || ^3.0 || ^4.0", - "symfony/http-foundation": "^2.8 || ^3.0 || ^4.0", - "symfony/http-kernel": "^2.8 || ^3.0 || ^4.0", - "symfony/options-resolver": "^2.8 || ^3.0 || ^4.0", - "symfony/security-bundle": "^2.8 || ^3.0 || ^4.0", - "symfony/translation": "^2.8 || ^3.0 || ^4.0", - "symfony/twig-bundle": "^2.8 || ^3.0 || ^4.0", - "symfony/validator": "^2.8 || ^3.0 || ^4.0", - "symfony/yaml": "^2.8 || ^3.0 || ^4.0", + "knplabs/knp-paginator-bundle": "^2.6 || ^3.4 || ^4.0 || ^5.0", + "symfony/config": "^2.8 || ^3.4 || ^4.0", + "symfony/console": "^2.8 || ^3.4 || ^4.0", + "symfony/dependency-injection": "^2.8 || ^3.4 || ^4.0", + "symfony/event-dispatcher": "^2.8 || ^3.4 || ^4.0", + "symfony/form": "^2.8 || ^3.4 || ^4.0", + "symfony/framework-bundle": "^2.8.1 || ^3.4 || ^4.0", + "symfony/http-foundation": "^2.8 || ^3.4 || ^4.0", + "symfony/http-kernel": "^2.8 || ^3.4 || ^4.0", + "symfony/options-resolver": "^2.8 || ^3.4 || ^4.0", + "symfony/security-bundle": "^2.8 || ^3.4 || ^4.0", + "symfony/translation": "^2.8 || ^3.4 || ^4.0", + "symfony/twig-bundle": "^2.8 || ^3.4 || ^4.0", + "symfony/validator": "^2.8 || ^3.4 || ^4.0", + "symfony/yaml": "^2.8 || ^3.4 || ^4.0", "twig/twig": "^1.34 || ^2.0" }, "require-dev": { "ext-pdo_sqlite": "*", "friendsofphp/php-cs-fixer": "^1.4 || ^2.0", + "friendsofsymfony/user-bundle": "^1.3 || ^2.1", "phpstan/phpstan": "^0.12.32", "phpunit/phpunit": ">=5.4.3,<8.0", "symfony/phpunit-bridge": "^3.2 || ^4.0", - "symfony/security": "^2.8 || ^3.0 || ^4.0" + "symfony/security": "^2.8 || ^3.4 || ^4.0" }, "suggest": { "friendsofsymfony/user-bundle": "In order to ease user management",