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
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 have created a number of selenium IDE files that I converted to phpunit format in Firefox IDE 2.9.1.1 (on a Windows box), using Options -> Format converter. Those converted files define a class "Example" that is derived from class PHPUnit_Extensions_SeleniumTestCase. I now know that this class needs to be changed to PHPUnit_Extensions_Selenium2TestCase. The problem is, I cannot get this to run with recent versions of phpunit.
I am running these tests on a Fedora 24 VM which is using php 5.6.30, java 1.8.0_121-b14, and firefox 51.0.1-2. I have tried to get these to run using selenium standalone server 3.0.1 (and now 3.1.0), and phpunit 5.7.13. I have the latest php facebook WebDriver installed. The error I keep getting is that the above mentioned class is not found. I did a grep on that class and this is what I found:
[root#localhost bin]# grep -r "PHPUnit_Extensions_Selenium2TestCase" .
Binary file ./phpunit/phpunit-4.6.7.phar matches
Binary file ./phpunit/phpunit-4.7.6.phar matches
So, it appears that this class does not exist in phpunit 5.7 and above (which are in that directory), nor does it exist in html-runner.phar, which is in the same directory. The seleniumhq.org site says to use html runner if you convert from IDE, but I can find no examples of how to use the html-runner.phar file (and no documentation).
Can someone please tell me what I should change the class name to, to get this test to work?
UPDATE:
I now know that if I want to use phpunit and selenium server to drive a firefox browser, I have to get selenium talking to geckodriver. I have installed:
geckodriver 0.14.0 at /usr/local/bin/geckodriver
selenium server 3.0.1 at /usr/local/bin/selenium
phpunit-5.7.13.phar installed at /usr/local/bin/phpunit
I used composer to add webdrivers (facebook 1.3.0 :
[root#localhost composer]# cat composer.json
{
"require": {
"facebook/webdriver": "^1.3",
"phpunit/phpunit": ">=3.7",
"phpunit/phpunit-selenium": ">=1.2"
}
}
php composer.phar install
They were added to the PATH:
[bjt#localhost projects]$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/local/bin/selenium:/usr/local/bin/phpunit:/usr/local/bin/composer:/usr/local/bin/geckodriver
I have a small test file:
?php
require_once('/usr/local/bin/composer/vendor/autoload.php');
class test extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser("*firefox");
$this->setBrowserUrl("https://fakeurl.com/");
}
public function testMyTestCase()
{
$this->open("/");
}
}
Starting the selenium server:
java -jar /usr/local/bin/selenium/selenium-standalone-3.0.1.jar
When I run the test:
/usr/local/bin/phpunit/phpunit-5.7.13.phar --verbose test.php
Yields this error:
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: The best matching driver provider Firefox/Marionette driver can't create a new driver instance for Capabilities [{browserName=*firefox}]
So, it appears that geckodriver is not talking to selenium server. If I try to force the issue by changing the execution of the server:
java -Dwebdriver.gecko.driver="/usr/local/bin/geckodriver/geckodriver" -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar
or
sudo java -Dwebdriver.gecko.driver="/usr/local/bin/geckodriver/geckodriver" -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar
It makes no difference. I'm hoping someone can point out what I am missing. I'm at a dead end.
I am currently working through the same process of getting this to work and would like to point out a few things:
htmlrunner is meant to run the test cases saved directly from the Selenium IDE in the default format, which is html.
Make sure you can run firefox from the terminal running the selenium server.
You added two different selenium php bindings. The facebook one and the phpunit-selenium. I currently have it working with only the facebook binding and phpunit extending the class PHPUnit_Framework_TestCase. I would recommend using the example provided within github for facebook/webdriver without phpunit to verify that your selenium config is working, then add phpunit.
I was upgrading my Symfony 2 project, which works with the lws_memcache Bundle.
Now my I get the following error:
ClassNotFoundException in LoggingMemcache.php line 4:
Attempted to load class "MemcachePool" from the global namespace.
Did you forget a "use" statement?
The File lies in the vendor of the lws_memcache Bundle, so I can't change the code.
My memcached Server is on the version 1.4.14, the bundle itself is the newest verison.
This is what my IDE (PHPStorm 8) shows me when I hover over the Class \MemcachePool in the vendor code.
Multiple definitions exist for class MemcachePool less... (Strg+F1)
Undefined class: Declaration of referenced class is not found in
built-in library and project files. Multiple declarations: this
version of IDE will have problems with completion, member resolution
and inheritance analysis for all classes that have multiple
definitions in project files (regardless of includes).
Is there something I can do about it?
LswMemcacheBundle bundle is compatible with memcache 3.0.6 or higher. I was having the same error with php-memcache 2.2.x.
Try upgrading your php-memcache to the new one (3.0.8), but first you need to edit the formula and setup the flags brew edit php56-memcache :
. 20 safe_phpize
. 21
+ 22 ENV['MACOSX_DEPLOYMENT_TARGET'] = '10.11'
+ 23 ENV['CFLAGS'] = '-fgnu89-inline'
+ 24 ENV['LDFLAGS'] = '-fgnu89-inline'
+ 25 ENV['CXXFLAGS'] = '-fgnu89-inline'
+ 26
. 27 system "./configure", "--prefix=#{prefix}",
. 28 phpconfig
. 29 system "make"
$ brew uninstall homebrew/php/php56-memcache
$ brew install homebrew/php/php56-memcache --devel
Then restart php-fpm + nginx.
Make sure your config file has a memcache session pool defined.
Try rebooting the server.
I had the same issue when installing LwsMemcache in my symfony project. I received the exact same error on production as the one above, but on my dev box, It was a different error (can't remember what it said), but had to do with php5 and memcache not working together.
restarting the services for nginx and php5-fpm did not work. I had to reboot and it works fine.
Hi I am currently running through the ZF2 User Guide trying to run a PHPUnit Test on the skeleton application as outlined here http://zf2.readthedocs.org/en/latest/user-guide/unit-testing.html.
But even though I have not edited the Module and have copied all the files from the tutorial every time I run the PHPUnit Test in Zend Studio I get this error
Error:
Fatal error: Class 'ApplicationTest\Bootstrap' not found in C:\Program Files (x86)\Zend\Apache2\htdocs\exerciseDB\module\Application\test\ApplicationTest\Controller\IndexControllerTest.php on line 24
But when I click on the Bootstrap::getServiceManager(); on line 24 Zend Studio takes me to the correct method.
File Stucture:
module
|_Application
|_config
|_language
|_src
|_test
|_ApplicationTest
| |_Controller
| |_IndexControllerTest.php
|_Bootstrap.php
|_phpunit.xml.dist
|_TestConfig.php.dist
Can anyine tell me where I am going wrong?
This was a really annoying bug that is somewhat of an irritation. Your phpunit config seems to be changed slightly from the one on the skeleton application. To give you direct answer that fixed my issue I did the following...
module
|_Application
|_config
|_language
|_src
|_tests
|_ZendApplicationModule
| |_Framework
| |TestCase.php
| |_IndexControllerTest.php
| |_SampleTest.php
|_Bootstrap.php
|_phpunit.xml.dist
|_TestConfig.php.dist
With the base setup as outlined above from the skeleton APP I had to add
require_once 'Framework/TestCase.php';
To SampleTest.php
For your actual fix you will need to require_once the file that is generating the issue. That should fix it.
Also make sure to update your autoload_classmap.php
I ran into the same issue where phpunit was not seeing my "module/Application/test/phpunit.xml.dist" file (I had it miss-spelled)
Try adding the file directly to the command line:
phpunit --bootstrap Bootstrap.php .
I had the issue as well.
I solved it by running phpunit from the root of my ZF2 project with the following arguments:
./vendor/bin/phpunit
--bootstrap ./module/Rest/test/Bootstrap.php
One can also specify the Test suite to use:
./vendor/bin/phpunit
--bootstrap ./module/Rest/test/Bootstrap.php
./module/Rest/test/RestTest/Controller/RestControllerTest.php
more details here
I wish to install the bundle into my symfony project. However, I am coming across a few issues. Please accept my ignorance if the answer is trivial but I've tried searching for a solution but alas, I've found nothing.
In my deps file, I have:
[doctrine-couchdb]
git=http://github.com/doctrine/couchdb-odm.git
[DoctrineCouchDBBundle]
git=http://github.com/doctrine/DoctrineCouchDBBundle.git
target=/bundles/Symfony/Bundle/DoctrineCouchDBBundle
I run the bin/vendors install command
In my autoload.php file I have:
'Doctrine\\ODM\\CouchDB'=> __DIR__.'/../vendor/doctrine-couchdb/lib',
I've registered the bundle:
new Doctrine\Bundle\CouchDBBundle\DoctrineCouchDBBundle()
When I run php app/console I get the error:
Fatal error: Class 'Doctrine\Bundle\CouchDBBundle\DoctrineCouchDBBundle' not found in /var/www/symfony2.test/app/AppKernel.php on line 22
I've noticed that for MongoDB ODM you have:
[doctrine-mongodb]
git=http://github.com/doctrine/mongodb.git
is there not a doctrine-couchdb repo? Have you used this bundle?
I changed target to
target= /bundles/Doctrine/Bundle/CouchDBBundle
so now looks like this
[DoctrineCouchDBBundle]
git=http://github.com/doctrine/DoctrineCouchDBBundle.git
target=/bundles/Doctrine/Bundle/CouchDBBundle
because I noticed that name space for couchdb bundle is
namespace Doctrine\Bundle\CouchDBBundle;
therefore adding
new Doctrine\Bundle\CouchDBBundle\DoctrineCouchDBBundle()
to AppKernel will fail, if installation location does not match namespace/class_name.
Detailed setup and configuration here DoctrineCouchDBBundle Git Hub Issue Log
For those that are new to Symfony 2 bundling architecture, you probably wonder what configuration keys are mandatory and available for bundles. Info can be obtained from:
bundle_dir/bundle_name/.../configuration.php
Update :
1.) Check that you also have installed and autoloaded Doctrine\CouchDB
2.) in your git installation
target=/bundles/Symfony/Bundle/DoctrineCouchDBBundle should probably be
target=/bundles/Doctrine/Bundle/DoctrineCouchDBBundle (notice Symfony => Doctrine)
3.) Then change
'Doctrine' => __DIR__.'/../vendor/doctrine/lib',
to
'Doctrine' => array(__DIR__.'/../vendor/doctrine/lib', __DIR__.'/../vendor/bundles'),
Off the top of my head I'd assume either these things:
1.) Cache
2.) 'Doctrine\\ODM\\CouchDB'=> __DIR__.'/../vendor/doctrine-couchdb/lib',
should be above any higher level namespaces ('Doctrine', 'Doctrine\Common')
so it should look like this:
'Doctrine\\ODM\\CouchDB'=> __DIR__.'/../vendor/doctrine-couchdb/lib',
'Doctrine\\DBAL' => __DIR__.'/../vendor/doctrine-dbal/lib',
'Doctrine' => __DIR__.'/../vendor/doctrine/lib',
3.) some configuration missing in config.yml