Symfony 4: How to disable profiler in test-env through command line - symfony

I am trying for quite some time now to disable the profiler in the test-environment. The only way it works is manually setting APP_ENV=test in file .env but I want to do this through the command line, not by editing a file.
Here's everything I tried:
I tried editing bin/console like described in Chris Brown's answer in this thread: Load different .env file with a Symfony 4 command (I also added the file .env.test, and according to xdebug it loads the appropriate file and runs through the appropriate code and also the variables $env and $debug get the appropriate value when I run the server with --env=test --no-debug)
I tried setting profiler: enabled: false like described in flu's answer in this thread: How to disable profiler in Symfony2 in production? (in config/packages/test/framework.yaml)
I tried setting the profiler line in bundles.php to
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true],
and to
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => false, 'test_cached' => false],
I tried those solutions separately and also all together, still the profiler keeps popping up. Does anybody have an idea?
EDIT:
After applying Alister Bulman's answer the command gives me this:
#php bin/console -e test debug:config framework profiler
Current configuration for "framework.profiler"
==============================================
enabled: true
collect: false
only_exceptions: false
only_master_requests: false
dsn: 'file:%kernel.cache_dir%/profiler'
EDIT 2:
Thanks to Jared Farrish I just found out the browser is receiving the website in "dev" mode although the server is started in test environment on cli. Obviously editing bin/console and public/index.php is not enough, they're not called when the server receives a request from the browser.
EDIT 3:
So I found out the http request goes first to public/index.php, but whatever I do, I cannot seem to make anything available there which was defined in bin/console although the whole server is started there in the first place. Anyone an idea how this can be done?

The profile can be enabled, or disabled in the framework configuration.
> bin/console -e dev debug:config framework profiler
Current configuration for "framework.profiler"
==============================================
only_exceptions: false
enabled: true
collect: true
only_master_requests: false
dsn: 'file:%kernel.cache_dir%/profiler'
In a newly generated project, these are best set (for the test environment) in the config/packages/test/framework.yaml file.
framework:
profiler:
enabled: false
collect: false
# optionally others
Documentation for the framework config (profiler, and the rest) is at https://symfony.com/doc/current/reference/configuration/framework.html#profiler

I found it myself. What I did was use a functionality of php.ini which is called "auto_prepend_file" where you can specify a PHP file which gets executed automatically before the actual PHP content is executed. So in there I put a path to a file with following content:
<?php
$_ENV['APP_ENV'] = 'test';
$_ENV['APP_DEBUG'] = 0;

Related

Drupal 8 disable template (page & node) cache

I have tried several articles to disable the page and template cache in Drupal 8. I am not using drush and find it very annoying I have to manually clear the cache after every change.
sites/default/default.services.yaml
List item
debug: true
cache: false
auto_reload: true
create sites/settings.php & sites/settings.local.php
$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
$settings['cache']['bins']['page'] = 'cache.backend.null';
in development.services.yml add the following
1. twig.config:
debug: true
auto_reload: true
cache: false
Rebuild the cache
http://yoursite/core/rebuild.php or drush cr
Disable cache in configuration -> performance
Be sure to disable dev tools cache
If I make an adjustment to page.html.twig nothing happens til I clear the cache, any other ideas would be great. This would be the latest version of Drupal 8
Good day!
Try to add in you yml file:
services:
cache.backend.null:
class: Drupal\Core\Cache\NullBackendFactory
Hope it will help you!
With all the steps above I forgot to do one thing
Move the settings.local.php inside sites/default
Uncomment the following in settings.php
if (file_exists(DIR . '/settings.local.php')) {
include DIR . '/settings.local.php';
}
You can install the Mix module to disable caches without editing settings*.php and *services.yml files. Just go to /admin/config/mix page and use the "Enable development mode" checkbox to switch between Dev/Prod modes. Here is a screenshot about Dev mode vs. Prod mode

Codeception error: Log path is not defined by key "paths: _logs"

I've just installed Codeception (using Composer) with Symfony 2.3 in a Vagrant box running on Windows 8.1. When I try to run tests using bin/codecept run or bin/codecept run acceptance, I get this error:
Log path is not defined by key "paths: _logs"
I do have a tests/_logs folder present. The codeception.yml is posted below. The weird thing is, when I change the name of _logs folder to anything else (for example 'log'), with a corresponding change to the "log" parameter in codeception.yml, I still get the same error message that refers to "_logs". Even if I delete the _logs directory and/or remove the reference to it in codeception.yml, I get the same error message. I tried reinstalling Codeception, restarting Vagrant, rebooting the computer, and still getting the same error.
My two teammates are able to run tests with the same code and with the same Vagrant box with no problems. The difference is that one of them is using a Mac OS and the other one is using a PC with Linux. Could this problem be related to Windows?
Here's my codeception.yml file:
paths:
tests: tests
log: tests/_logs
data: tests/_data
helpers: tests/_helpers
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit_Framework_TestSuite
colors: true
memory_limit: 1024M
log: true
modules:
config:
Db:
dsn: 'mysql:dbname=s2_at_test;host=127.0.0.1'
user: 's2_at_test'
password: #hidden#
dump: tests/_data/dump.sql
populate: true
cleanup: true

Why am I getting "Cannot redeclare class" on Symfony2 + vagrant + moved vendors optimalization setup?

Recently I've been working on improveing my vagrant enviroment and I've stumbled upon Running the Symfony application on Vagrant without NFS below 100ms blog post.
I've moved the vendor dir outside the VM shared directory, as suggested, by createing /tmp/app/vendor dir inside the VM and setting
export COMPOSER_VENDOR_DIR=/tmp/app/vendor
export COMPOSER_BIN_DIR=/tmp/app/bin
export SF2_ENV=vagrant
enviroment variables before running composer install.
Now, with vendors correctly installed to another path, I've modified the app/autoload.php file to detect if the app is running inside the VM by looking for the SF2_ENV enviroment variable:
if (array_key_exists('SF2_ENV', $_SERVER) && $_SERVER['SF2_ENV'] === 'vagrant') {
// vagrant enviroment detected
$loader = require sys_get_temp_dir().'/app/vendor/autoload.php';
} else {
// default
$loader = require __DIR__.'/../vendor/autoload.php';
}
This worked fine for one project, however on another project I kept getting the
PHP Fatal error: Cannot redeclare class Gedmo\Loggable\Entity\MappedSuperclass\AbstractLogEntry in /var/www/public_html/vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity/MappedSuperclass/AbstractLogEntry.php on line 13
error when trying to initialize the app cache php app/console cache:clear -e=prod.
Why was this happening?
Note: I've anwsered myself, as this is a Q&A style question (a note to my future self).
I am posting this as a reminder to my future self or anyone else interested. The problem was becouse in the second project I used Gedmo library and in my config.yml I defined:
doctrine:
orm:
entity_managers:
default:
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
mappings:
gedmo_translatable:
type: annotation
prefix: Gedmo\Translatable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
alias: GedmoTranslatable
is_bundle: false
So, the problem was clearly the %kernel.root_dir% part, which was hardcoded.
Solution
I've simply changed it to %vendor_dir% and defined this parameter in my parameters.yml - for production as vendor_dir: '%kernel.root_dir%/../vendor' and for local (dev) as vendor_dir: /tmp/app/vendor.
I already have problem with symfony2 project on Vagrant. But I resolve this without change location of /vendor directory.
Just disable the nfs share and locate your projects directly on /var/www
you can use this on vagrantFile :
config.vm.synced_folder '.', '/vagrant', disabled: true
Work with your Vagrant as like you work with a remote server...
What happening when you deploying in production environment your autoload.php file ? it's not very useful to change this only for dev environment (I don't speak only for this file but general idea).

How to disable default nginx site when using Chef and Vagrant?

I am using Berkshelf, Chef and Vagrant and I am trying to configure a custom site running on nginx. I am using the opscode nginx recipe and then writing my own recipe for the custom site. When I run vagrant up I get the an error about not disabling the default nginx site. I've found several different suggestions but nothing seems to be working.
The error:
STDOUT:
STDERR: nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites- enabled/kyleboon.me:2
nginx: configuration file /etc/nginx/nginx.conf test failed
My Berksfile:
site :opscode
metadata
cookbook 'nginx'
The 'roles/web.json' role I defined:
{
"name": "web",
"chef_type": "role",
"json_class": "Chef::Role",
"description": "The base role for systems that serve HTTP traffic",
"default_attributes": {
"nginx": {
"default_site_enabled": false
},
"app": {
"name": "kyleboon.me",
"web_dir": "/var/data/www/kyleboon.me"
},
"user":{
"name": "vagrant"
}
},
"run_list": [
"recipe[nginx]",
"recipe[kyleboon.me]"
]
}
Here is the recipes/default/default.rb for the nginx site I am adding:
nginx_site 'default' do
action :disable
end
%w(public logs).each do |dir|
directory "#{node.app.web_dir}/#{dir}" do
owner node.user.name
mode "0755"
recursive true
end
end
template "#{node.nginx.dir}/sites-available/kyleboon.me" do
source "site.erb"
mode 0777
owner node.nginx.user
group node.nginx.user
end
nginx_site "kyleboon.me"
cookbook_file "#{node.app.web_dir}/public/index.html" do
source "index.html"
mode 0755
owner node.user.name
end
(P.S. I know the file permissions need to be changed, I've just been fiddling with lots of things, I'll update those once I get everything else working)
And here is attributes/default.rb:
override['nginx']['enable_default_site'] = false
You can see I have tried to disable the default site in the web.json, the attributes and the recipe itself but none of them stick.
I don't have a node or solo node defined and I'm not sure if that's an issue. My main problem with vagrant so far has been the endless possibilities for how to do things. No two examples are done in the same way and I'm not sure what is considered the 'best' or 'right' way to go.
You can disable any nginx site by name using the nginx_site and its name. The problem you are having is because the nginx_site definition is actually looking for the enable parameter to be set to true or false not the action parameter set to :disabled.
To disable the default site add to your recipe:
nginx_site 'default' do
enable false
end
This is working for me as of version 1.7.1 of the nginx opscode cookbook. I dont know if this will work with the version provided by community as it appears to be several months old.
To get the latest version add to your Berksfile:
cookbook 'nginx', git: 'https://github.com/opscode-cookbooks/nginx'
Hope that helps :)
I'm getting the same error, but I don't have the default site enabled. Instead, it's coming from /etc/nginx/conf.d/default.conf! I had to resort to
file "/etc/nginx/conf.d/default.conf" do
action :delete
end
This is coming from the RHEL package that the nginx cookbook is installing on my box.

is it possible to keep my dev environment but show all the error n save the logs on symfony 1.4?

Ive been trying to to set correctly the test environment on symfony 1.4 but not success, I was wondering if is any way to make symfony show the errors or log them.
What I tried to make my test env was on my index.php file of symfony/web/ I set this
$configuration = ProjectConfiguration::getApplicationConfiguration('orangehrm', 'test', true);
I have the logs enabled, but still what I only see when I get an error is "An internal error occurred. Please contact your system administrator. " Any idea?
I am working with symfony 1.4
My apache log file is also empty.
In the config settings file (/apps/frontend/config/settings.yml), you must enable error_reporting and web_debug parameters for your "test" environment. For example :
test:
.settings:
error_reporting: <?php echo (E_ALL ^ E_DEPRECATED)."\n" ?>
web_debug: true
cache: false
no_script_name: false
etag: false

Resources