Fixed project for symfony 5.1

feature/symfony_upgrade
Hecht 4 years ago
parent 7594b5af67
commit 334f734012

20
.env

@ -15,14 +15,18 @@
###> symfony/framework-bundle ### ###> symfony/framework-bundle ###
APP_ENV=dev APP_ENV=dev
APP_SECRET=2e4a817309fb576a536b62a60eaf2aaa APP_SECRET=296bba2d9c7a4f6eee2c7611d66a8aec
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2 #TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
#TRUSTED_HOSTS='^(localhost|example\.com)$' #TRUSTED_HOSTS='^(localhost|example\.com)$'
###< symfony/framework-bundle ### ###< symfony/framework-bundle ###
###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11&charset=utf8"
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name?serverVersion=5.7
###< doctrine/doctrine-bundle ###
###> symfony/swiftmailer-bundle ### ###> symfony/mailer ###
# For Gmail as a transport, use: "gmail://username:password@localhost" # MAILER_DSN=smtp://localhost
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode=" ###< symfony/mailer ###
# Delivery is disabled by default via "null://localhost"
MAILER_URL=null://localhost
###< symfony/swiftmailer-bundle ###

8
.gitignore vendored

@ -1,8 +1,8 @@
###> symfony/framework-bundle ### ###> symfony/framework-bundle ###
/.env.local /.env.local
/.env.local.php /.env.local.php
/.env.*.local /.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/ /public/bundles/
/var/ /var/
/vendor/ /vendor/
@ -13,10 +13,4 @@
.phpunit.result.cache .phpunit.result.cache
/phpunit.xml /phpunit.xml
###< symfony/phpunit-bridge ### ###< symfony/phpunit-bridge ###
###> symfony/web-server-bundle ###
/.web-server-pid
###< symfony/web-server-bundle ###
.project .project

@ -4,7 +4,8 @@
use App\Kernel; use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug; use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL; echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
@ -14,8 +15,8 @@ set_time_limit(0);
require dirname(__DIR__).'/vendor/autoload.php'; require dirname(__DIR__).'/vendor/autoload.php';
if (!class_exists(Application::class)) { if (!class_exists(Application::class) || !class_exists(Dotenv::class)) {
throw new LogicException('You need to add "symfony/framework-bundle" as a Composer dependency.'); throw new LogicException('You need to add "symfony/framework-bundle" and "symfony/dotenv" as Composer dependencies.');
} }
$input = new ArgvInput(); $input = new ArgvInput();
@ -27,7 +28,7 @@ if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0'); putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
} }
require dirname(__DIR__).'/config/bootstrap.php'; (new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
if ($_SERVER['APP_DEBUG']) { if ($_SERVER['APP_DEBUG']) {
umask(0000); umask(0000);

@ -2,39 +2,57 @@
"type": "project", "type": "project",
"license": "proprietary", "license": "proprietary",
"require": { "require": {
"php": "^7.1.3", "php": ">=7.2.5",
"ext-ctype": "*", "ext-ctype": "*",
"ext-iconv": "*", "ext-iconv": "*",
"friendsofsymfony/rest-bundle": "^2.4", "composer/package-versions-deprecated": "^1.11",
"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.1",
"doctrine/doctrine-migrations-bundle": "^3.0",
"doctrine/orm": "^2.7",
"friendsofsymfony/rest-bundle": "^3.0",
"phpdocumentor/reflection-docblock": "^5.2",
"sensio/framework-extra-bundle": "^5.1", "sensio/framework-extra-bundle": "^5.1",
"symfony/asset": "4.4.*", "symfony/asset": "5.1.*",
"symfony/console": "4.4.*", "symfony/console": "5.1.*",
"symfony/expression-language": "4.4.*", "symfony/dotenv": "5.1.*",
"symfony/flex": "^1.1", "symfony/expression-language": "5.1.*",
"symfony/form": "4.4.*", "symfony/flex": "^1.3.1",
"symfony/framework-bundle": "4.4.*", "symfony/form": "5.1.*",
"symfony/framework-bundle": "5.1.*",
"symfony/http-client": "5.1.*",
"symfony/intl": "5.1.*",
"symfony/mailer": "5.1.*",
"symfony/mime": "5.1.*",
"symfony/monolog-bundle": "^3.1", "symfony/monolog-bundle": "^3.1",
"symfony/orm-pack": "*", "symfony/notifier": "5.1.*",
"symfony/process": "4.4.*", "symfony/process": "5.1.*",
"symfony/security-bundle": "4.4.*", "symfony/property-access": "5.1.*",
"symfony/serializer-pack": "*", "symfony/property-info": "5.1.*",
"symfony/swiftmailer-bundle": "^3.1", "symfony/security-bundle": "5.1.*",
"symfony/translation": "4.4.*", "symfony/serializer": "5.1.*",
"symfony/twig-bundle": "4.4.*", "symfony/string": "5.1.*",
"symfony/validator": "4.4.*", "symfony/translation": "5.1.*",
"symfony/web-link": "4.4.*", "symfony/twig-bundle": "^5.1",
"symfony/yaml": "4.4.*" "symfony/validator": "5.1.*",
"symfony/web-link": "5.1.*",
"symfony/yaml": "5.1.*",
"twig/extra-bundle": "^2.12|^3.0",
"twig/twig": "^2.12|^3.0"
}, },
"require-dev": { "require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", "doctrine/doctrine-fixtures-bundle": "^3.3",
"symfony/debug-pack": "*", "symfony/browser-kit": "^5.1",
"symfony/dotenv": "4.4.*", "symfony/css-selector": "^5.1",
"symfony/debug-bundle": "^5.1",
"symfony/maker-bundle": "^1.0", "symfony/maker-bundle": "^1.0",
"symfony/profiler-pack": "*", "symfony/phpunit-bridge": "^5.1",
"symfony/test-pack": "*", "symfony/stopwatch": "^5.1",
"symfony/web-server-bundle": "4.4.*" "symfony/var-dumper": "^5.1",
"symfony/web-profiler-bundle": "^5.1"
}, },
"config": { "config": {
"optimize-autoloader": true,
"preferred-install": { "preferred-install": {
"*": "dist" "*": "dist"
}, },
@ -54,6 +72,7 @@
"paragonie/random_compat": "2.*", "paragonie/random_compat": "2.*",
"symfony/polyfill-ctype": "*", "symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*", "symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*",
"symfony/polyfill-php71": "*", "symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*", "symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*" "symfony/polyfill-php56": "*"
@ -76,7 +95,7 @@
"extra": { "extra": {
"symfony": { "symfony": {
"allow-contrib": false, "allow-contrib": false,
"require": "4.4.*" "require": "5.1.*"
} }
} }
} }

3044
composer.lock generated

File diff suppressed because it is too large Load Diff

@ -13,38 +13,8 @@ if (!class_exists(Dotenv::class)) {
if (is_array($env = @include dirname(__DIR__).'/.env.local.php') && (!isset($env['APP_ENV']) || ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env['APP_ENV']) === $env['APP_ENV'])) { if (is_array($env = @include dirname(__DIR__).'/.env.local.php') && (!isset($env['APP_ENV']) || ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env['APP_ENV']) === $env['APP_ENV'])) {
(new Dotenv(false))->populate($env); (new Dotenv(false))->populate($env);
} else { } else {
$path = dirname(__DIR__).'/.env';
$dotenv = new Dotenv(false);
// load all the .env files // load all the .env files
if (method_exists($dotenv, 'loadEnv')) { (new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env');
$dotenv->loadEnv($path);
} else {
// fallback code in case your Dotenv component is not 4.2 or higher (when loadEnv() was added)
if (file_exists($path) || !file_exists($p = "$path.dist")) {
$dotenv->load($path);
} else {
$dotenv->load($p);
}
if (null === $env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) {
$dotenv->populate(array('APP_ENV' => $env = 'dev'));
}
if ('test' !== $env && file_exists($p = "$path.local")) {
$dotenv->load($p);
$env = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env;
}
if (file_exists($p = "$path.$env")) {
$dotenv->load($p);
}
if (file_exists($p = "$path.$env.local")) {
$dotenv->load($p);
}
}
} }
$_SERVER += $_ENV; $_SERVER += $_ENV;

@ -2,18 +2,16 @@
return [ return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true], Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
FOS\RestBundle\FOSRestBundle::class => ['all' => true], FOS\RestBundle\FOSRestBundle::class => ['all' => true],
Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true],
]; ];

@ -1,4 +0,0 @@
# See https://symfony.com/doc/current/email/dev_environment.html
swiftmailer:
# send all emails to a specific address
#delivery_addresses: ['me@example.com']

@ -5,19 +5,14 @@ doctrine:
# IMPORTANT: You MUST configure your server version, # IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file) # either here or in the DATABASE_URL env var (see .env file)
#server_version: '5.7' #server_version: '5.7'
# only needed for MySQL
charset: utf8mb4
default_table_options:
collate: utf8mb4_unicode_ci
orm: orm:
auto_generate_proxy_classes: true auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true auto_mapping: true
mappings: mappings:
App: App:
is_bundle: false is_bundle: false
type: annotation type: yml
dir: '%kernel.project_dir%/src/Entity' dir: '%kernel.project_dir%/config/orm'
prefix: 'App\Entity' prefix: 'App\Entity'
alias: App alias: App

@ -1,15 +1,22 @@
# Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html # Read the documentation: https://symfony.com/doc/master/bundles/FOSRestBundle/index.html
fos_rest: null fos_rest:
# param_fetcher_listener: true disable_csrf_role: ROLE_API
param_fetcher_listener: true
body_listener: true
# allowed_methods_listener: true # allowed_methods_listener: true
# routing_loader: true # routing_loader: true
# view: view:
# view_response_listener: true view_response_listener: force
# exception: exception:
# codes: enabled: true
# App\Exception\MyException: 403 codes:
# messages: 'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
# App\Exception\MyException: Forbidden area. 'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
# format_listener: messages:
# rules: 'Symfony\Component\Routing\Exception\ResourceNotFoundException': true
# - { path: ^/api, prefer_extension: true, fallback_format: json, priorities: [ json, html ] } format_listener:
rules:
- { path: ^/api, prefer_extension: true, fallback_format: json, priorities: [ json, xml ] }
- { path: ^/, prefer_extension: true, fallback_format: html, priorities: [ html ] }
serializer:
groups: ['Default']

@ -1,3 +1,4 @@
# see https://symfony.com/doc/current/reference/configuration/framework.html
framework: framework:
secret: '%env(APP_SECRET)%' secret: '%env(APP_SECRET)%'
#csrf_protection: true #csrf_protection: true
@ -7,6 +8,7 @@ framework:
# Remove or comment this section to explicitly disable session support. # Remove or comment this section to explicitly disable session support.
session: session:
handler_id: null handler_id: null
cookie_secure: auto
cookie_samesite: lax cookie_samesite: lax
#esi: true #esi: true

@ -0,0 +1,3 @@
framework:
mailer:
dsn: '%env(MAILER_DSN)%'

@ -0,0 +1,16 @@
framework:
notifier:
#chatter_transports:
# slack: '%env(SLACK_DSN)%'
# telegram: '%env(TELEGRAM_DSN)%'
#texter_transports:
# twilio: '%env(TWILIO_DSN)%'
# nexmo: '%env(NEXMO_DSN)%'
channel_policy:
# use chat/slack, chat/telegram, sms/twilio or sms/nexmo
urgent: ['email']
high: ['email']
medium: ['email']
low: ['email']
admin_recipients:
- { email: admin@example.com }

@ -2,26 +2,14 @@ doctrine:
orm: orm:
auto_generate_proxy_classes: false auto_generate_proxy_classes: false
metadata_cache_driver: metadata_cache_driver:
type: service type: pool
id: doctrine.system_cache_provider pool: doctrine.system_cache_pool
query_cache_driver: query_cache_driver:
type: service type: pool
id: doctrine.system_cache_provider pool: doctrine.system_cache_pool
result_cache_driver: result_cache_driver:
type: service type: pool
id: doctrine.result_cache_provider pool: doctrine.result_cache_pool
services:
doctrine.result_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '@doctrine.result_cache_pool'
doctrine.system_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '@doctrine.system_cache_pool'
framework: framework:
cache: cache:

@ -1,3 +1,7 @@
framework: framework:
router: router:
utf8: true utf8: true
# Configure how to generate URLs in non-HTTP contexts, such as CLI commands.
# See https://symfony.com/doc/current/routing.html#generating-urls-in-commands
#default_uri: http://localhost

@ -8,6 +8,7 @@ security:
security: false security: false
main: main:
anonymous: true anonymous: true
lazy: true
provider: users_in_memory provider: users_in_memory
# activate different ways to authenticate # activate different ways to authenticate

@ -1,3 +0,0 @@
swiftmailer:
url: '%env(MAILER_URL)%'
spool: { type: 'memory' }

@ -1,2 +0,0 @@
swiftmailer:
disable_delivery: true

@ -1,4 +1,3 @@
framework: framework:
validation: validation:
# As of Symfony 4.3 you can disable the NotCompromisedPassword Validator not_compromised_password: false
# not_compromised_password: false

@ -1,4 +1,2 @@
twig: twig:
default_path: '%kernel.project_dir%/templates' default_path: '%kernel.project_dir%/templates'
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'

@ -1,3 +1,8 @@
framework: framework:
validation: validation:
email_validation_mode: html5 email_validation_mode: html5
# Enables validator auto-mapping support.
# For instance, basic validation constraints will be inferred from Doctrine's metadata.
#auto_mapping:
# App\Entity\: []

@ -0,0 +1,5 @@
<?php
if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
}

@ -0,0 +1,3 @@
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
prefix: /_error

@ -1,3 +0,0 @@
_errors:
resource: '@TwigBundle/Resources/config/routing/errors.xml'
prefix: /_error

@ -10,20 +10,21 @@ services:
_defaults: _defaults:
autowire: true # Automatically injects dependencies in your services. autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
# makes classes in src/ available to be used as services # makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name # this creates a service per class whose id is the fully-qualified class name
App\: App\:
resource: '../src/*' resource: '../src/'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}' exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Tests/'
# controllers are imported separately to make sure services can be injected # controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class # as action arguments even if you don't extend any base controller class
App\Controller\: App\Controller\:
resource: '../src/Controller' resource: '../src/Controller/'
tags: ['controller.service_arguments'] tags: ['controller.service_arguments']
# add more service definitions when explicit configuration is needed # add more service definitions when explicit configuration is needed

@ -1,10 +1,13 @@
<?php <?php
use App\Kernel; use App\Kernel;
use Symfony\Component\Debug\Debug; use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__).'/config/bootstrap.php'; require dirname(__DIR__).'/vendor/autoload.php';
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
if ($_SERVER['APP_DEBUG']) { if ($_SERVER['APP_DEBUG']) {
umask(0000); umask(0000);

@ -4,13 +4,10 @@ namespace App\Controller;
use App\Repository\HeroRepository; use App\Repository\HeroRepository;
use FOS\RestBundle\Controller\Annotations as Rest; use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController; use FOS\RestBundle\Controller\AbstractFOSRestController;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
/** class HeroController extends AbstractFOSRestController
* @Rest\RouteResource("Hero")
*/
class HeroController extends FOSRestController
{ {
protected $heroRepository; protected $heroRepository;
@ -20,6 +17,7 @@ class HeroController extends FOSRestController
} }
/** /**
* @Rest\Route("api/heroes")
* @Rest\View() * @Rest\View()
*/ */
public function cgetAction() public function cgetAction()

@ -4,13 +4,10 @@ namespace App\Controller;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use FOS\RestBundle\Controller\Annotations as Rest; use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController; use FOS\RestBundle\Controller\AbstractFOSRestController;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
/** class UserController extends AbstractFOSRestController
* @Rest\RouteResource("User")
*/
class UserController extends FOSRestController
{ {
protected $userRepository; protected $userRepository;
@ -20,6 +17,7 @@ class UserController extends FOSRestController
} }
/** /**
* @Rest\Route("api/users")
* @Rest\View() * @Rest\View()
*/ */
public function cgetAction() public function cgetAction()

@ -4,8 +4,8 @@ namespace App\DataFixtures;
use App\Entity\Hero; use App\Entity\Hero;
use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Persistence\ObjectManager;
use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Doctrine\DataFixtures\DependentFixtureInterface;
class HeroFixtures extends Fixture implements DependentFixtureInterface class HeroFixtures extends Fixture implements DependentFixtureInterface
{ {

@ -3,17 +3,15 @@ namespace App\DataFixtures;
use App\Entity\User; use App\Entity\User;
use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class UserFixtures extends Fixture class UserFixtures extends Fixture
{ {
public const ADMIN_USER_REFERENCE = 'admin-user'; public const ADMIN_USER_REFERENCE = 'admin-user';
public const ADMIN_USER_TOKEN = 'ItsHammerTime!';
public const DUDE_USER_REFERENCE = 'dummy-user'; public const DUDE_USER_REFERENCE = 'dummy-user';
public const DUDE_USER_TOKEN = 'ItsDuderzeit!';
private $passwordEncoder; private $passwordEncoder;
@ -27,13 +25,13 @@ class UserFixtures extends Fixture
$userAdmin = new User(); $userAdmin = new User();
$userAdmin->setUsername('admin'); $userAdmin->setUsername('admin');
$this->setPassword($userAdmin, '123456789'); $this->setPassword($userAdmin, '123456789');
$userAdmin->setApiToken(self::ADMIN_USER_TOKEN); $userAdmin->setApiToken('ItsHammerTime!');
$manager->persist($userAdmin); $manager->persist($userAdmin);
$userDude = new User(); $userDude = new User();
$userDude->setUsername('dude'); $userDude->setUsername('dude');
$this->setPassword($userDude, '1234'); $this->setPassword($userDude, '1234');
$userDude->setApiToken(self::DUDE_USER_TOKEN); $userDude->setApiToken('ItsDuderzeit!');
$manager->persist($userDude); $manager->persist($userDude);
$manager->flush(); $manager->flush();

@ -3,59 +3,36 @@
namespace App; namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel; use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder; use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
class Kernel extends BaseKernel class Kernel extends BaseKernel
{ {
use MicroKernelTrait; use MicroKernelTrait;
const CONFIG_EXTS = '.{php,xml,yaml,yml}'; protected function configureContainer(ContainerConfigurator $container): void
public function getCacheDir()
{ {
return $this->getProjectDir().'/var/cache/'.$this->environment; $container->import('../config/{packages}/*.yaml');
$container->import('../config/{packages}/'.$this->environment.'/*.yaml');
if (is_file(\dirname(__DIR__).'/config/services.yaml')) {
$container->import('../config/services.yaml');
$container->import('../config/{services}_'.$this->environment.'.yaml');
} elseif (is_file($path = \dirname(__DIR__).'/config/services.php')) {
(require $path)($container->withPath($path), $this);
} }
public function getLogDir()
{
return $this->getProjectDir().'/var/log';
} }
public function registerBundles() protected function configureRoutes(RoutingConfigurator $routes): void
{ {
$contents = require $this->getProjectDir().'/config/bundles.php'; $routes->import('../config/{routes}/'.$this->environment.'/*.yaml');
foreach ($contents as $class => $envs) { $routes->import('../config/{routes}/*.yaml');
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
}
}
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) if (is_file(\dirname(__DIR__).'/config/routes.yaml')) {
{ $routes->import('../config/routes.yaml');
$container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php')); } elseif (is_file($path = \dirname(__DIR__).'/config/routes.php')) {
// Feel free to remove the "container.autowiring.strict_mode" parameter (require $path)($routes->withPath($path), $this);
// if you are using symfony/dependency-injection 4.0+ as it's the default behavior
$container->setParameter('container.autowiring.strict_mode', true);
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir().'/config';
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
} }
protected function configureRoutes(RouteCollectionBuilder $routes)
{
$confDir = $this->getProjectDir().'/config';
$routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
} }
} }

@ -4,7 +4,7 @@ namespace App\Repository;
use App\Entity\Hero; use App\Entity\Hero;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface; use Doctrine\Persistence\ManagerRegistry;
/** /**
* @method Hero|null find($id, $lockMode = null, $lockVersion = null) * @method Hero|null find($id, $lockMode = null, $lockVersion = null)
@ -14,7 +14,7 @@ use Symfony\Bridge\Doctrine\RegistryInterface;
*/ */
class HeroRepository extends ServiceEntityRepository class HeroRepository extends ServiceEntityRepository
{ {
public function __construct(RegistryInterface $registry) public function __construct(ManagerRegistry $registry)
{ {
parent::__construct($registry, Hero::class); parent::__construct($registry, Hero::class);
} }

@ -4,7 +4,7 @@ namespace App\Repository;
use App\Entity\User; use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface; use Doctrine\Persistence\ManagerRegistry;
/** /**
* @method User|null find($id, $lockMode = null, $lockVersion = null) * @method User|null find($id, $lockMode = null, $lockVersion = null)
@ -14,7 +14,7 @@ use Symfony\Bridge\Doctrine\RegistryInterface;
*/ */
class UserRepository extends ServiceEntityRepository class UserRepository extends ServiceEntityRepository
{ {
public function __construct(RegistryInterface $registry) public function __construct(ManagerRegistry $registry)
{ {
parent::__construct($registry, User::class); parent::__construct($registry, User::class);
} }

@ -27,12 +27,12 @@
"version": "v2.8.0" "version": "v2.8.0"
}, },
"doctrine/doctrine-bundle": { "doctrine/doctrine-bundle": {
"version": "1.6", "version": "2.0",
"recipe": { "recipe": {
"repo": "github.com/symfony/recipes", "repo": "github.com/symfony/recipes",
"branch": "master", "branch": "master",
"version": "1.6", "version": "2.0",
"ref": "2ede24c63b72e96be0b28819052033f887024927" "ref": "a9f2463b9f73efe74482f831f03a204a41328555"
}, },
"files": [ "files": [
"config/packages/doctrine.yaml", "config/packages/doctrine.yaml",
@ -41,9 +41,6 @@
"src/Repository/.gitignore" "src/Repository/.gitignore"
] ]
}, },
"doctrine/doctrine-cache-bundle": {
"version": "1.3.5"
},
"doctrine/doctrine-fixtures-bundle": { "doctrine/doctrine-fixtures-bundle": {
"version": "3.0", "version": "3.0",
"recipe": { "recipe": {
@ -93,6 +90,9 @@
"doctrine/reflection": { "doctrine/reflection": {
"version": "v1.0.0" "version": "v1.0.0"
}, },
"doctrine/sql-formatter": {
"version": "1.1.1"
},
"easycorp/easy-log-handler": { "easycorp/easy-log-handler": {
"version": "1.0", "version": "1.0",
"recipe": { "recipe": {
@ -120,9 +120,6 @@
"config/packages/fos_rest.yaml" "config/packages/fos_rest.yaml"
] ]
}, },
"jdorn/sql-formatter": {
"version": "v1.2.17"
},
"laminas/laminas-code": { "laminas/laminas-code": {
"version": "3.4.1" "version": "3.4.1"
}, },
@ -162,6 +159,9 @@
"psr/container": { "psr/container": {
"version": "1.0.0" "version": "1.0.0"
}, },
"psr/event-dispatcher": {
"version": "1.0.0"
},
"psr/link": { "psr/link": {
"version": "1.0.0" "version": "1.0.0"
}, },
@ -177,9 +177,6 @@
"ref": "fb7e19da7f013d0d422fa9bce16f5c510e27609b" "ref": "fb7e19da7f013d0d422fa9bce16f5c510e27609b"
} }
}, },
"swiftmailer/swiftmailer": {
"version": "v6.1.3"
},
"symfony/asset": { "symfony/asset": {
"version": "v4.1.7" "version": "v4.1.7"
}, },
@ -196,24 +193,20 @@
"version": "v4.1.7" "version": "v4.1.7"
}, },
"symfony/console": { "symfony/console": {
"version": "3.3", "version": "5.1",
"recipe": { "recipe": {
"repo": "github.com/symfony/recipes", "repo": "github.com/symfony/recipes",
"branch": "master", "branch": "master",
"version": "3.3", "version": "5.1",
"ref": "5b06148c10d442bf536a4d3017cadb3a99fd9135" "ref": "c6d02bdfba9da13c22157520e32a602dbee8a75c"
}, },
"files": [ "files": [
"bin/console", "bin/console"
"config/bootstrap.php"
] ]
}, },
"symfony/css-selector": { "symfony/css-selector": {
"version": "v4.1.7" "version": "v4.1.7"
}, },
"symfony/debug": {
"version": "v4.1.7"
},
"symfony/debug-bundle": { "symfony/debug-bundle": {
"version": "4.1", "version": "4.1",
"recipe": { "recipe": {
@ -223,12 +216,12 @@
"ref": "f8863cbad2f2e58c4b65fa1eac892ab189971bea" "ref": "f8863cbad2f2e58c4b65fa1eac892ab189971bea"
} }
}, },
"symfony/debug-pack": {
"version": "v1.0.6"
},
"symfony/dependency-injection": { "symfony/dependency-injection": {
"version": "v4.1.7" "version": "v4.1.7"
}, },
"symfony/deprecation-contracts": {
"version": "v2.2.0"
},
"symfony/doctrine-bridge": { "symfony/doctrine-bridge": {
"version": "v4.1.7" "version": "v4.1.7"
}, },
@ -272,24 +265,28 @@
"version": "v4.1.7" "version": "v4.1.7"
}, },
"symfony/framework-bundle": { "symfony/framework-bundle": {
"version": "3.4", "version": "5.1",
"recipe": { "recipe": {
"repo": "github.com/symfony/recipes", "repo": "github.com/symfony/recipes",
"branch": "master", "branch": "master",
"version": "3.4", "version": "5.1",
"ref": "903c28f0ce372b8414cc569a8832428737e8abd1" "ref": "6ee1194b036378b21884e7f57b6a2ac721167f16"
}, },
"files": [ "files": [
"config/bootstrap.php",
"config/packages/cache.yaml", "config/packages/cache.yaml",
"config/packages/framework.yaml", "config/packages/framework.yaml",
"config/packages/test/framework.yaml", "config/packages/test/framework.yaml",
"config/preload.php",
"config/routes/dev/framework.yaml",
"config/services.yaml", "config/services.yaml",
"public/index.php", "public/index.php",
"src/Controller/.gitignore", "src/Controller/.gitignore",
"src/Kernel.php" "src/Kernel.php"
] ]
}, },
"symfony/http-client": {
"version": "v5.1.7"
},
"symfony/http-client-contracts": { "symfony/http-client-contracts": {
"version": "v2.3.1" "version": "v2.3.1"
}, },
@ -299,12 +296,21 @@
"symfony/http-kernel": { "symfony/http-kernel": {
"version": "v4.1.7" "version": "v4.1.7"
}, },
"symfony/inflector": {
"version": "v4.1.7"
},
"symfony/intl": { "symfony/intl": {
"version": "v4.1.7" "version": "v4.1.7"
}, },
"symfony/mailer": {
"version": "4.3",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "4.3",
"ref": "15658c2a0176cda2e7dba66276a2030b52bd81b2"
},
"files": [
"config/packages/mailer.yaml"
]
},
"symfony/maker-bundle": { "symfony/maker-bundle": {
"version": "1.0", "version": "1.0",
"recipe": { "recipe": {
@ -335,12 +341,21 @@
"config/packages/test/monolog.yaml" "config/packages/test/monolog.yaml"
] ]
}, },
"symfony/notifier": {
"version": "5.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "5.0",
"ref": "c31585e252b32fe0e1f30b1f256af553f4a06eb9"
},
"files": [
"config/packages/notifier.yaml"
]
},
"symfony/options-resolver": { "symfony/options-resolver": {
"version": "v4.1.7" "version": "v4.1.7"
}, },
"symfony/orm-pack": {
"version": "v1.0.5"
},
"symfony/panther": { "symfony/panther": {
"version": "v0.2.0" "version": "v0.2.0"
}, },
@ -359,6 +374,9 @@
"tests/bootstrap.php" "tests/bootstrap.php"
] ]
}, },
"symfony/polyfill-intl-grapheme": {
"version": "v1.18.1"
},
"symfony/polyfill-intl-icu": { "symfony/polyfill-intl-icu": {
"version": "v1.10.0" "version": "v1.10.0"
}, },
@ -371,9 +389,6 @@
"symfony/polyfill-mbstring": { "symfony/polyfill-mbstring": {
"version": "v1.10.0" "version": "v1.10.0"
}, },
"symfony/polyfill-php72": {
"version": "v1.10.0"
},
"symfony/polyfill-php73": { "symfony/polyfill-php73": {
"version": "v1.18.1" "version": "v1.18.1"
}, },
@ -383,9 +398,6 @@
"symfony/process": { "symfony/process": {
"version": "v4.1.7" "version": "v4.1.7"
}, },
"symfony/profiler-pack": {
"version": "v1.0.3"
},
"symfony/property-access": { "symfony/property-access": {
"version": "v4.1.7" "version": "v4.1.7"
}, },
@ -393,12 +405,12 @@
"version": "v4.1.7" "version": "v4.1.7"
}, },
"symfony/routing": { "symfony/routing": {
"version": "4.2", "version": "5.1",
"recipe": { "recipe": {
"repo": "github.com/symfony/recipes", "repo": "github.com/symfony/recipes",
"branch": "master", "branch": "master",
"version": "4.2", "version": "5.1",
"ref": "683dcb08707ba8d41b7e34adb0344bfd68d248a7" "ref": "b4f3e7c95e38b606eef467e8a42a8408fc460c43"
}, },
"files": [ "files": [
"config/packages/prod/routing.yaml", "config/packages/prod/routing.yaml",
@ -407,12 +419,12 @@
] ]
}, },
"symfony/security-bundle": { "symfony/security-bundle": {
"version": "3.3", "version": "5.1",
"recipe": { "recipe": {
"repo": "github.com/symfony/recipes", "repo": "github.com/symfony/recipes",
"branch": "master", "branch": "master",
"version": "3.3", "version": "5.1",
"ref": "38d658ce68375d66d2cddc88892af8f08701e6e7" "ref": "0a4bae19389d3b9cba1ca0102e3b2bccea724603"
}, },
"files": [ "files": [
"config/packages/security.yaml" "config/packages/security.yaml"
@ -433,34 +445,14 @@
"symfony/serializer": { "symfony/serializer": {
"version": "v4.1.7" "version": "v4.1.7"
}, },
"symfony/serializer-pack": {
"version": "v1.0.1"
},
"symfony/service-contracts": { "symfony/service-contracts": {
"version": "v2.2.0" "version": "v2.2.0"
}, },
"symfony/stopwatch": { "symfony/stopwatch": {
"version": "v4.1.7" "version": "v4.1.7"
}, },
"symfony/swiftmailer-bundle": { "symfony/string": {
"version": "2.5", "version": "v5.1.7"
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "2.5",
"ref": "ae4d22af30bbd484506bc1817c5a3ef72c855b93"
},
"files": [
"config/packages/dev/swiftmailer.yaml",
"config/packages/swiftmailer.yaml",
"config/packages/test/swiftmailer.yaml"
]
},
"symfony/templating": {
"version": "v4.1.7"
},
"symfony/test-pack": {
"version": "v1.0.4"
}, },
"symfony/translation": { "symfony/translation": {
"version": "3.3", "version": "3.3",
@ -482,27 +474,26 @@
"version": "v4.1.7" "version": "v4.1.7"
}, },
"symfony/twig-bundle": { "symfony/twig-bundle": {
"version": "3.3", "version": "5.0",
"recipe": { "recipe": {
"repo": "github.com/symfony/recipes", "repo": "github.com/symfony/recipes",
"branch": "master", "branch": "master",
"version": "3.3", "version": "5.0",
"ref": "1da1987340b5ba64b16383906d678b989e3d096e" "ref": "fab9149bbaa4d5eca054ed93f9e1b66cc500895d"
}, },
"files": [ "files": [
"config/packages/test/twig.yaml", "config/packages/test/twig.yaml",
"config/packages/twig.yaml", "config/packages/twig.yaml",
"config/routes/dev/twig.yaml",
"templates/base.html.twig" "templates/base.html.twig"
] ]
}, },
"symfony/validator": { "symfony/validator": {
"version": "4.1", "version": "4.3",
"recipe": { "recipe": {
"repo": "github.com/symfony/recipes", "repo": "github.com/symfony/recipes",
"branch": "master", "branch": "master",
"version": "4.1", "version": "4.3",
"ref": "21ab70175caf1e4b273791364fb30d27f1153546" "ref": "d902da3e4952f18d3bf05aab29512eb61cabd869"
}, },
"files": [ "files": [
"config/packages/test/validator.yaml", "config/packages/test/validator.yaml",
@ -527,18 +518,12 @@
"ref": "6bdfa1a95f6b2e677ab985cd1af2eae35d62e0f6" "ref": "6bdfa1a95f6b2e677ab985cd1af2eae35d62e0f6"
} }
}, },
"symfony/web-server-bundle": {
"version": "3.3",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "3.3",
"ref": "dae9b39fd6717970be7601101ce5aa960bf53d9a"
}
},
"symfony/yaml": { "symfony/yaml": {
"version": "v4.1.7" "version": "v4.1.7"
}, },
"twig/extra-bundle": {
"version": "v3.0.5"
},
"twig/twig": { "twig/twig": {
"version": "v2.5.0" "version": "v2.5.0"
}, },

@ -2,17 +2,13 @@
namespace App\Tests\Controller; namespace App\Tests\Controller;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\DomCrawler\Crawler;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
class ClientRequestBuilder class ClientRequestBuilder
{ {
/** protected KernelBrowser $client;
*
* @var Client
*/
private $client;
/** /**
* *
@ -44,7 +40,7 @@ class ClientRequestBuilder
*/ */
private $acceptType; private $acceptType;
public function __construct(Client $client) public function __construct(KernelBrowser $client)
{ {
$this->client = $client; $this->client = $client;
$this->parameters = []; $this->parameters = [];
@ -52,7 +48,7 @@ class ClientRequestBuilder
$this->acceptType = 'application/json'; $this->acceptType = 'application/json';
} }
public static function create(Client $client): ClientRequestBuilder public static function create(KernelBrowser $client): ClientRequestBuilder
{ {
return new ClientRequestBuilder($client); return new ClientRequestBuilder($client);
} }

@ -5,16 +5,13 @@ namespace App\Tests\Controller;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\NullOutput;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
class RestTestBase extends WebTestCase class RestTestBase extends WebTestCase
{ {
/** protected KernelBrowser $client;
* @var Client
*/
protected $client;
protected function setUp() protected function setUp()
{ {

@ -15,7 +15,7 @@ class UserControllerTest extends RestTestBase
->setMethod('GET') ->setMethod('GET')
->setUri('/api/users') ->setUri('/api/users')
->setAcceptType('application/json') ->setAcceptType('application/json')
->addServerParameter('HTTP_X-AUTH-TOKEN', UserFixtures::ADMIN_USER_TOKEN) ->addServerParameter('HTTP_X-AUTH-TOKEN', UserFixtures::ADMIN_USER_REFERENCE)
->request(); ->request();
$response = $this->client->getResponse(); $response = $this->client->getResponse();

Loading…
Cancel
Save