Symfony3 - Cache component - Pool definition - symfony

I'ld like to use the new Symfony 3 Cache Component in a project.
I can use it if I define my services by hand like this:
app.cache.adapter.array:
class: 'Symfony\Component\Cache\Adapter\ArrayAdapter'
app.redis.client:
class: Predis\Client
factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection']
arguments: ["%redis_dsn%", {timeout: 5}]
app.cache.adapter.redis:
class: Symfony\Component\Cache\Adapter\RedisAdapter
abstract: true
arguments:
-
- "api"
- 0
app.cache.adapter.chain:
class: 'Symfony\Component\Cache\Adapter\ChainAdapter'
abstract: true
arguments:
- ['#app.cache.adapter.array', "#app.cache.adapter.redis"]
- 0
cache.api:
parent: "app.cache.adapter.chain"
But as soon as I use the cache.pool tag or the framework pools configuration to get data in the profiler, I've got an exception
framework:
cache:
pools:
cache.api:
adapter: "app.cache.adapter.chain"
public: true
default_lifetime: 0
clearer: ~
And here is the exception
(1/1) ContextErrorException
Catchable Fatal Error: Argument 1 passed to Symfony\Component\Cache\Adapter\ChainAdapter::__construct() must be of the type array, string given, called in /var/www/julien/htdocs/sccd/website/var/cache/dev/appDevDebugProjectContainer.php on line 4032 and defined
in ChainAdapter.php (line 37)
at ChainAdapter->__construct('+FJMe7Pj5l', 0)in appDevDebugProjectContainer.php (line 4032)
at appDevDebugProjectContainer->getCache_Api_RecorderInnerService()in appDevDebugProjectContainer.php (line 623)
at appDevDebugProjectContainer->getCache_ApiService()in classes.php (line 3292)
at Container->get('cache.api')in appDevDebugProjectContainer.php (line 2629)
Can anyone help me on this ?
I'm using the Symfony v3.3.11, and predis/predis v1.1.1 for redis connection.
Thanks

Related

Not able to execute lifecycle operation using script plugin

I'm trying to learn how to use script plugin. I'm following script plugin docs here but not able to make it work.
I've tried to use the plugin in two ways. The first, when cloudify.interface.lifecycle.start operation is mapped directly to a script:
tosca_definitions_version: cloudify_dsl_1_3
imports:
- 'http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml'
node_templates:
Import_Project:
type: cloudify.nodes.WebServer
capabilities:
scalable:
properties:
default_instances: 1
interfaces:
cloudify.interfaces.lifecycle:
start:
implementation: scripts/create_project.sh
inputs: {}
The second with a direct mapping:
tosca_definitions_version: cloudify_dsl_1_3
imports:
- 'http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml'
node_templates:
Import_Project:
type: cloudify.nodes.WebServer
capabilities:
scalable:
properties:
default_instances: 1
interfaces:
cloudify.interfaces.lifecycle:
start:
implementation: script.script_runner.tasks.run
inputs:
script_path: scripts/create_project.sh
I've created a directory named scripts and placed the below create_project.sh script in this directory:
#! /bin/bash -e
ctx logger info "Hello to this world"
hostname
I'm getting errors while validating the blueprint.
Error when operation is mapped directly to a script:
[2019-04-13 13:29:40.594] [DEBUG] DslParserExecClient - got output from dsl parser Could not extract plugin from operation mapping 'scripts/create_project.sh', which is declared for operation 'start'. In interface 'cloudify.interfaces.lifecycle' in node 'Import_Project' of type 'cloudify.nodes.WebServer'
in: /opt/cloudify-composer/backend/dev/workspace/2/tmp-27O0e1t813N6as
in line: 3, column: 2
path: node_templates.Import_Project
value: {'interfaces': {'cloudify.interfaces.lifecycle': {'start': {'implementation': 'scripts/create_project.sh', 'inputs': {}}}}, 'type': 'cloudify.nodes.WebServer', 'capabilities': {'scalable': {'properties': {'default_instances': 1}}}}
Error when using a direct mapping:
[2019-04-13 13:25:21.015] [DEBUG] DslParserExecClient - got output from dsl parser node 'Import_Project' has no relationship which makes it contained within a host and it has a plugin 'script' with 'host_agent' as an executor. These types of plugins must be installed on a host
in: /opt/cloudify-composer/backend/dev/workspace/2/tmp-279QCz2CV3Y81L
in line: 2, column: 0
path: node_templates
value: {'Import_Project': {'interfaces': {'cloudify.interfaces.lifecycle': {'start': {'implementation': 'script.script_runner.tasks.run', 'inputs': {'script_path': 'scripts/create_project.sh'}}}}, 'type': 'cloudify.nodes.WebServer', 'capabilities': {'scalable': {'properties': {'default_instances': 1}}}}}
What is missing to make this work?
I also found the Cloudify Script Plugin examples from their documentation do not work: https://docs.cloudify.co/4.6/working_with/official_plugins/configuration/script/
However, I found I can make the examples work by adding an executor line in parallel with the implementation line to override the host_agent executor as follows:
tosca_definitions_version: cloudify_dsl_1_3
imports:
- 'http://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml'
node_templates:
Import_Project:
type: cloudify.nodes.WebServer
capabilities:
scalable:
properties:
default_instances: 1
interfaces:
cloudify.interfaces.lifecycle:
start:
implementation: scripts/create_project.sh
executor: central_deployment_agent
inputs: {}

Unable to replace alias "mea.twig.JsExtension" , Symfony 3.4 service alias

services.yml
mea.twig.JsExtension:
alias: Mea\CoreBundle\Twig\MeaExtension
public: true
arguments: ["#service_container","#kernel", "#mea.metatags", "#mea.asset"]
tags:
- { name: twig.extension }
give error
InvalidArgumentException
Unable to replace alias "mea.twig.JsExtension" with actual definition "Mea\CoreBundle\Twig\MeaExtension".
in ReplaceAliasByActualDefinitionPass.php (line 57)
at ReplaceAliasByActualDefinitionPass->process(object(ContainerBuilder))
in Compiler.php (line 141)
at Compiler->compile(object(ContainerBuilder))
in ContainerBuilder.php (line 759)
at ContainerBuilder->compile()
in Kernel.php (line 643)
Symfony 3.4
There are 4 possible causes of it and they might be perfectly undersended by exceptions of Symfony\Component\DependencyInjection\Exception\InvalidArgumentException type:
ServiceNotFoundException;
ParameterNotFoundException;
EnvNotFoundException;
EnvParameterException.
I'm sure first exception is the the real cause of your problem.

Health endpoint not working in spring-boot-actuator service

Hi I am using spring boot version - 2.0.0.RC1. I have simple service running #port 9400.
My application.properties have below configuration:
spring.main.banner-mode = CONSOLE
spring.profiles.active = ${profile:local}
server.compression.enabled = true
server.compression.min-response-size = 1
server.compression.mime-types = application/json,application/xml,text/xml,text/plain
banner.charset = UTF-8
management.endpoints.health.show-details=true
management.server.address: 127.0.0.1
management.endpoints.web.expose: health,info,metrics,mappings,trace
management.endpoints.health.show-details: true
management.endpoints.health.time-to-live: 2000
management.security.enabled: false
management.health.defaults.enabled: false
management.health.diskspace.enabled: true
My build.gradle has :
dependencies {
// Spring Boot
compile group: 'org.springframework.boot', name: 'spring-boot-starter-webflux', version: springBootVersion
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: springBootVersion
}
My gradle.properties:
springBootVersion = 2.0.0.RC1
When I point to http://127.0.0.1:9400/health
I get error screen as attached snapshot.
What am I missing?
The show-details value that you are providing is not a valid one...
Anyway, in Spring Boot 2.0 the actuator endpoints (like the health) are remapped to /actuator/*.
Now, the health is located at /actuator/health.
More info at the release notes in https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0.0-RC2-Release-Notes#health-endpoint
Just add the following property in application.properties file:
management.health.defaults.enabled=false

No code coverage in functional test with Codeception and C3

I've written a basic functional test in Codeception and I'm not seeing any coverage in either the HTML or XML reports. The pass/fail reports are generated correctly.
<?php
class MyFirstCest {
public function _before(FunctionalTester $I) {
}
public function _after(FunctionalTester $I) {
}
// tests
public function tryToTestLoginPage(FunctionalTester $I) {
$I->amOnPage('/app/login/');
$I->seeInSource('html');
}
}
The output is:
There was 1 failure:
---------
1) MyFirstCest: Try to test login page
Test tests\functional\MyFirstCest.php:tryToTestLoginPage
Step See in source "html"
Fail Failed asserting that on page /app/login/
--> #!/usr/bin/env php
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined offset:
[Content too long to display. See complete response in 'C:\server\Apache24\htdocs\localhost\tests/_output\' directory]
--> contains "html".
The error occurs in codecept.phar, but I assume other people are able to use the same version (2.3.6) without errors.
codeception.yml:
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
settings:
shuffle: true
extensions:
enabled:
- Codeception\Extension\RunFailed
coverage:
enabled: true
blacklist:
include:
- tests\*
low_limit: 0
high_limit: 50
c3_url: 'http://localhost'
# remote: true
functional.suite.yml:
# Codeception Test Suite Configuration
#
# Suite for functional tests
# Emulate web requests and make application process them
# Include one of framework modules (Symfony2, Yii2, Laravel5) to use it
# Remove this suite if you don't use frameworks
actor: FunctionalTester
modules:
enabled:
- PhpBrowser:
url: 'http://localhost'
auth: ['admin', '123345']
curl:
CURLOPT_RETURNTRANSFER: true
cookies:
cookie-1:
Name: userName
Value: john.doe
cookie-2:
Name: authToken
Value: 1abcd2345
Domain: subdomain.domain.com
Path: /admin/
Expires: 1292177455
Secure: true
HttpOnly: false
coverage:
enabled: true
I'm running Codeception with:
php codecept.phar run --html report.html --coverage-html coverage --xml report.xml --coverage-xml coverage.xml functional
The output file says: Notice: Undefined offset: 0 in phar://C:/usr/bin/codecept.phar/src/Codeception/Command/Self‌​Update.php on line 44, which indicates a Codeception error, however, I'm sure other people get this to work without causing errors in Codeception, so I assume I've got a configuration error somewhere.

How to show PHP errors when unit testing my Symfony2 bundle?

Currently, when writing a unit test for my Symfony2 bundle, I explicitly set ini_set('display_errors', 1) to make sure I see any errors I made in writing my unit test. This is particularly helpful for fatal errors, such as those resulting from typos in method names.
Example:
# src/Foo/BarBundle/Tests/Security/RoutePermissionCheckerTest.php
namespace Foo\BarBundle\Tests\Security;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
class RoutePermissionCheckerTest extends TestCase
{
public function testIndex()
{
ini_set('display_errors', 1);
$this->nonExistentMethod();
}
}
Output:
Configuration read from /Users/maurits_dekkers/Sites/hobby/symfony/saas-seed/app/phpunit.xml.dist
...
Fatal error: Call to undefined method Bb\UserBundle\Tests\Security\RoutePermissionCheckerTest::nonExistentMethod() in /Users/maurits_dekkers/Sites/hobby/symfony/saas-seed/src/Bb/UserBundle/Tests/Security/RoutePermissionCheckerTest.php on line 18
Call Stack:
0.0314 635432 1. {main}() /Users/maurits_dekkers/pear/bin/phpunit:0
0.5501 1191328 2. PHPUnit_TextUI_Command::main() /Users/maurits_dekkers/pear/bin/phpunit:46
0.5502 1192056 3. PHPUnit_TextUI_Command->run() /Users/maurits_dekkers/pear/share/pear/PHPUnit/TextUI/Command.php:129
1.2241 7133440 4. PHPUnit_TextUI_TestRunner->doRun() /Users/maurits_dekkers/pear/share/pear/PHPUnit/TextUI/Command.php:176
1.2619 7653720 5. PHPUnit_Framework_TestSuite->run() /Users/maurits_dekkers/pear/share/pear/PHPUnit/TextUI/TestRunner.php:349
14.0128 37804208 6. PHPUnit_Framework_TestSuite->run() /Users/maurits_dekkers/pear/share/pear/PHPUnit/Framework/TestSuite.php:705
14.0130 37804608 7. PHPUnit_Framework_TestSuite->runTest() /Users/maurits_dekkers/pear/share/pear/PHPUnit/Framework/TestSuite.php:745
14.0130 37804608 8. PHPUnit_Framework_TestCase->run() /Users/maurits_dekkers/pear/share/pear/PHPUnit/Framework/TestSuite.php:775
14.0131 37804608 9. PHPUnit_Framework_TestResult->run() /Users/maurits_dekkers/pear/share/pear/PHPUnit/Framework/TestCase.php:783
14.0131 37805600 10. PHPUnit_Framework_TestCase->runBare() /Users/maurits_dekkers/pear/share/pear/PHPUnit/Framework/TestResult.php:648
14.0134 37846840 11. PHPUnit_Framework_TestCase->runTest() /Users/maurits_dekkers/pear/share/pear/PHPUnit/Framework/TestCase.php:838
14.0134 37848304 12. ReflectionMethod->invokeArgs() /Users/maurits_dekkers/pear/share/pear/PHPUnit/Framework/TestCase.php:983
14.0134 37848336 13. Bb\UserBundle\Tests\Security\RoutePermissionCheckerTest->testIndex() /Users/maurits_dekkers/pear/share/pear/PHPUnit/Framework/TestCase.php:983
However, there must be a better way by means of a configuration setting. I've tried adding an extra Monolog setting to my config_test.yml:
# app/config/config_test.yml
monolog:
handlers:
console:
type: console
bubble: false
level: info
but that does not result in PHP errors being reported during my unit test. The unit test simply stops running.
Is there an easy way to configure my Symfony2 project to always report errors during a unit test?
You might want to set the following parameters to true in your PHPUnit configuration file (app/config/phpunit.xml):
convertErrorsToException
convertNoticesToExceptions
convertNoticesToExceptions

Resources