I'm creating a Symfony 3.4 application.
Then I started to write some tests, which totally pass locally :
/**
* Two steps :
* 1) Checks if page goes on 200 status
* 2) Posts sample datas
*/
public function testDistanceAmongSequencesAction()
{
/**
* 1 - Access to the page OK
*/
$this->client->request('GET', '/minitools/distance-among-sequences');
static::assertEquals(200, $this->client->getResponse()->getStatusCode());
}
But when I push my code and execute it with Travis CI, it fails automatically : 3) MinitoolsBundleTest\Controller\MinitoolsControllerTest::testDistanceAmongSequencesAction
Failed asserting that 500 matches expected 200.
He is my .travis.yml file :
language: php
sudo: required
dist: trusty
php:
- '7.1.16'
services:
- mysql
script:
- composer self-update
- composer install --no-interaction --no-suggest
- bin/console server:run &
- vendor/bin/phpunit
The PHP version is the same as mine. I think the VM Travis can't access to y path, but why ? Thank you for your help !
OK, in my controller I called the TWIG templates using # annotation, and Travis doesn't understand it. So I modified each call and moved the TWIG into app/ressources. Thanks.
Related
I want to create a new entity in my ORO platform application by using the make:entity command from the MakerBundle.
I expect it to create an entity in my bundle Acme\Bundle\TestBundle which I set in my config_dev.yml by using:
maker:
root_namespace: 'Acme\Bundle\TestBundle'
So I execute
bin/console make:entity Test
which returns
! [NOTE] It looks like your app may be using a namespace other than "Acme\Bundle\TestBundle".
!
! To configure this and make your life easier, see:
! https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html#configuration
created: src/Acme/Bundle/TestBundle/Entity/Test.php
created: src/Acme/Bundle/TestBundle/Repository/TestRepository.php
[ERROR] Only annotation mapping is supported by make:entity, but the
<info>Acme\Bundle\TestBundle\Entity\Test</info> class uses a different format. If you would like
this command to generate the properties & getter/setter methods, add your mapping configuration, and then
re-run this command with the <info>--regenerate</info> flag.
I've tried to run the command once again, which works. But obviously this is not the way how it's meant to work. So how can I fix this mapping error?
I started with the standard Symfony 5 project by using Symfony new myapp.
I add the config file in config/packages/dev/maker.yaml
maker:
root_namespace: 'App\Core'
To generate the entity in the src/Core folder, I got the following error:
➜ symfony console make:entity Post
created: src/Core/Entity/Post.php
created: src/Core/Repository/PostRepository.php
[ERROR] Only annotation mapping is supported by make:entity, but the <info>App\Core\Entity\Post</info> class uses
a different format. If you would like this command to generate the properties & getter/setter methods, add your
mapping configuration, and then re-run this command with the <info>--regenerate</info> flag.
To avoid showing the error in the console, I install the patch created by vklux / maker-bundle-force-annotation
Step 1: install package
composer require cweagans/composer-patches
Step 2: apply the patch in composer.json
{
// {...} composer.json content
"extra": {
"patches": {
"symfony/maker-bundle": {
"Provide flag to force annotation in make entity command": "https://raw.githubusercontent.com/vklux/maker-bundle-force-annotation/master/maker-force-annotation-flag.patch"
}
}
}
}
Step 3: composer update
composer update
Step 4: try make:entity with the additional command option
➜ symfony console make:entity Post --force-annotation
created: src/Core/Entity/Post.php
created: src/Core/Repository/PostRepository.php
Entity generated! Now let's add some fields!
You can always add more fields later manually or by re-running this command.
New property name (press <return> to stop adding fields):
>
✅ 🚀 👍 Everything works fine now.
It's a bug in the doctrine version please try this version good luck
composer req doctrine/doctrine-bundle:2.2
I found a solution to create new entities with Symfony maker using doctrine/doctrine-bundle version higher than 2.2.4
These steps worked for me with:
"doctrine/doctrine-bundle": "^2.7"
PHP 8.1 (I migrate from php 7.4 in my case)
STEP 1: replace type: annotation by type: attribute inside doctrine.yaml
STEP 2: Enter entity root with namespace:
symfony console make:entity App\Entity\test
I'm running Symfony Insight with a gitlab CI in order to improve my code quality.
I recently added google recaptcha, which needs a public (used in twig) and a private token (used in controller).
To do a clean job, I added them both as environment variables, added the pub one as twig global variable, and i get the private one with getenv.
I a am now getting the "A Symfony application should be bootable" error on symfony insight, with the following stacktrace :
Symfony\Component\DependencyInjection\Exception\EnvNotFoundException: Environment variable not found: "RECAPTCHA_PUBLIC_KEY". in /home/foobar/code/vendor/symfony/dependency-injection/EnvVarProcessor.php:97
Note that everything is working properly on both local and php unit tests (also ran by CI)
I'm guessing that the insight isn't finding the env var when trying to initiate the global twig variable.
Here is my .env.dist file : (the keys are google testing key, not my real ones, don't worry)
###> google-recaptcha ###
RECAPTCHA_PRIVATE_KEY=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
RECAPTCHA_PUBLIC_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
###< google-recaptcha ###
Here is my twig variable declaration :
globals:
recaptcha_public_key: '%env(RECAPTCHA_PUBLIC_KEY)%'
And my gitlab-ci insight config:
insight:
stage: insight
image: php:7.1
tags:
- symfony4
script:
- curl -o insight.phar -s https://get.insight.symfony.com/insight.phar
- php insight.phar analyze --no-interaction --no-ansi cc8f0c98-ce1b-4b1e-acc4-9dfafd4bafc4 -v --reference=$CI_COMMIT_SHA --user-uuid=23888e4d-ec4f-479b-90c6-ee454c7bfc88 --api-token=b1dcbef05392e237a5ee5d29ea348b9ab7179245b0f086c3490478b0ae643272 --fail-condition="counts.critical > 0 or counts.major > 0"
only:
- develop
- master
variables:
MYSQL_DATABASE: higalsymf
DATABASE_HOST: mysql
MYSQL_ROOT_PASSWORD: root
The first idea: you can insert tokens in variables section in gitlab-ci.yml.
Second idea is add command cp .env.dist .env in section before_script in gitlab-ci.yml.
I'm trying to deploy a PHP web application using Magallanes.
This is my actual task config:
tasks:
pre-deploy:
- composer/install
on-deploy:
- filesystem/link-shared-files:
linked_folders:
- web/fileadmin
- web/uploads
- web/typo3temp
- web/typo3conf/l10n
post-release:
- general/manually:
- vendor/bin/typo3cms install:fixfolderstructure
- vendor/bin/typo3cms install:generatepackagestates --activate-default=true
- vendor/bin/typo3cms cache:flush true
- vendor/bin/typo3cms database:updateschema "*.add,*.change"
- vendor/bin/typo3cms cache:warmup
post-deploy:
While using:
pre-deploy:
- composer/install
Composer will always be called with composer install --dev. Is there a way to call composer with --no-dev instead of --dev?
PS: I already tried - composer/install --no-dev, which generates the following error:
Starting Pre-Deployment tasks:
Task "Composer/installNoDev" not found.
Update
Because I needed some more parameters, I used general/manually. My solution is now:
tasks:
pre-deploy:
- general/manually:
- php7.0 /usr/local/bin/composer install --no-dev --no-progress --optimize-autoloader
But on the other hand my, original question was something different. So Chris's answere seems to be correct.
I think this will work:
pre-deploy:
- composer/install: {dev: false}
I couldn't find this in the documentation, but the source references a 'dev' parameter that seems to control --dev / --no-dev:
public function run()
{
$dev = $this->getParameter('dev', true);
return $this->runCommand($this->getComposerCmd() . ' install' . ($dev ? ' --dev' : ' --no-dev'));
}
The documentation is a bit more helpful about setting parameters, but I'm not sure if it will correctly read false as a Boolean value.
Hi i am quit new in Laravel PHPUnit, getting the following error :
Laravel : phpunit cannot open file ExampleTest.php
I don't have idea why i am getting this error. I installed PHPUnit globally and when i run "phpunit" in terminal it runs fine. But I want to run it on specific file like :
phpunit ExampleTest
Thanks In Advance.
Make sure you are on the project root and referencing the file inside the tests folder.
Example:
phpunit tests/ExampleTest.php
I am working in Windows. Try to use the full path:
C:\Desktop\code\blog\vendor\bin>phpunit C:\Desktop\code\blog\tests\Feature\ExampleTest.php
PHPUnit 7.2.6 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 1.46 seconds, Memory: 10.00MB
OK (1 test, 1 assertion)
This started happening when I upgrade phpUnit, I had to update phpStorm to fix it.
try it like this:
vendor\bin\phpunit tests\Unit\ExampleTest.php
it will work surly
but first install phpunit globally.
Maybe you call wrong to your test.
Try like this :
php artisan test --filter YourTestClassName
I know that I have downloaded a Symfony2 project and started with but I have updated my vendor several times and I want to know which version of symfony I have
Any idea ?
Run app/console --version (for Symfony3: bin/console --version), it should give you a pretty good idea. On a random project of mine, the output is:
Symfony version 2.2.0-DEV - app/dev/debug
If you can't access the console, try reading symfony/src/Symfony/Component/HttpKernel/Kernel.php, where the version is hardcoded, for instance:
const VERSION = '2.2.0';
Just in case you are wondering, console creates an instance of Symfony\Bundle\FrameworkBundle\Console\Application. In this class constructor, it uses Symfony\Component\HttpKernel\Kernel::VERSION to initialize its parent constructor.
Although there are already many good answers I'd like to add an option that hasn't been mentioned. Using the command:
php bin/console about
you can get many details about the current project. The first section is about Symfony itself and looks like this:
-------------------- -------------------------------------------
Symfony
-------------------- -------------------------------------------
Version 4.2.3
End of maintenance 07/2019
End of life 01/2020
-------------------- -------------------------------------------
I find the other information besides the version number very useful.
There are also other sections providing details about the (framework) Kernel, PHP, Environment.
Another way is to look at the source for Symfony\Component\HttpKernel\Kernel for where const VERSION is defined. Example on GitHub
Locally this would be located in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php.
Use the following command in your Terminal/Command Prompt:
php bin/console --version
This will give you your Symfony Version.
also you can check the version of symfony and versions of all other installed packages by running
composer show
or
composer show | grep sonata
to get versions of specific packages like sonata etc.
If you want to dynamicallly display your Symfony 2 version in pages, for example in footer, you can do it this way.
Create a service:
<?php
namespace Project\Bundle\DuBundle\Twig;
class SymfonyVersionExtension extends \Twig_Extension
{
public function getFunctions()
{
return array(
//this is the name of the function you will use in twig
new \Twig_SimpleFunction('symfony_version', array($this, 'b'))
);
}
public function getName()
{
//return 'number_employees';
return 'symfony_version_extension';
}
public function b()
{
$symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
return $symfony_version;
}
}
Register in service.yml
dut.twig.symfony_version_extension:
class: Project\Bundle\DutBundle\Twig\SymfonyVersionExtension
tags:
- { name: twig.extension }
#arguments: []
And you can call it anywhere. In Controller, wrap it in JSON, or in pages example footer
<p> Built With Symfony {{ symfony_version() }} Version MIT License</p>
Now every time you run composer update to update your vendor, symfony version will also automatically update in your template.I know this is overkill but this is how I do it in my projects and it is working.
we can find the symfony version using Kernel.php file but problem is the Location of Kernal Will changes from version to version (Better Do File Search in you Project Directory)
in symfony 3.0 :
my_project\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php
Check from Controller/ PHP File
$symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
echo $symfony_version; // this will return version; **o/p:3.0.4-DEV**
if you trying with version symfony
please try with
symfony 2 +
cmd>php app/console --version
symfony 3+
cmd>php bin/console --version
for example
D:project>php bin/console --version
Symfony 3.2.8 (kernel: app, env: dev, debug: true)
For Symfony 3.4
Check the constant in this file vendor/symfony/http-kernel/Kernel.php
const VERSION = '3.4.3';
OR
composer show | grep symfony/http-kernel
From inside your Symfony project, you can get the value in PHP this way:
$symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
Maybe the anwswers here are obsolete... in any case, for me running Symfony 4, it is easy
Just type symfony -V from the command line.
This page is the top Google result for search which version symfony using, and the top answers probably don't work anymore.
Apparently I'm on Symfony 5, after running symfony new aqua_note (from SymfonyCasts recommendation).
I had to ultimately run grep -r VERSION . | grep Kernel to see ./vendor/symfony/http-kernel/Kernel.php: public const VERSION = '5.4.2';... at least I think that's correct now.
if you are in app_dev, you can find symfony version at the bottom left corner of the page