This Bundle provides base classes for functional tests. It also provides a DI aware mock builder for unit tests.
To run tests in parallel:
Some helper classes for writing functional tests in Symfony
Home Page: http://liip.ch
License: MIT License
This Bundle provides base classes for functional tests. It also provides a DI aware mock builder for unit tests.
To run tests in parallel:
Hello,
In my project, there are event listeners that create certain entities when other entities are created. So, I have fixtures that load the main entities, but event listeners take care of everything else automatically.
But LiipFunctionalTestBundle doesn't seem to like this. I expect it to drop the whole database and only load my fixtures on subsequent texts, but if any changes are made to that data, it seems to attempt to save those as well. That's not at all what I want it to do.
So for instance, I notice that if I have a "Transaction" entity I create in a test, lets say with field1 set to 50, then in test2, the entity will still exist, with field1 set to 50. What I really want is for that entity not to be saved at all, and especially not with its values saved.
I've debugged this as much as I could and tracked it down to the loadFixtures method. Before that method is called, the old entity does not exist. After it is called, it does exist. My fixtures are not loading the entity though.
Hello,
I have a Symfony2 project which accesses multiple databases and I've been unable to get it working with the otherwise wonderful LiipFunctionalTestBundle.
The application usually runs on PostGreSQL and I'm adding functional tests.
my config.test.yml looks like:
doctrine:
dbal:
default_connection: default
types:
point: Knp\DoctrineBehaviors\DBAL\Types\PointType
connections:
default:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.db
mapping_types:
point: point
stats:
driver: pdo_sqlite
path: %kernel.cache_dir%/test_stats.db
mapping_types:
point: point
test_stats.db is created but is 0 bytes
There is only one bundle that is set up to be in the stats db. Here's an extract from config.yml:
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: %database_name%
user: %database_user%
password: %database_password%
host: %database_host%
port: %database_port%
driver: %database_driver%
charset: UTF-8
stats:
dbname: %database_name_stats%
user: %database_user%
password: %database_password%
host: %database_host%
port: %database_port%
driver: %database_driver%
charset: UTF-8
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: default
entity_managers:
default:
result_cache_driver: apc
connection: default
mappings:
MyFAQBundle: ~
MyMailBundle: ~
stats:
connection: stats
mappings:
MyStatsBundle: ~
What I find is that test.db is all set up just fine, whereas test_stats.db is 0 bytes and no tables are created in there.
If I set everything up to use a single database everything works perfectly. I can see that the DriverChain in Doctrine definitely picks up MyStatsBundle\Entity but that's a separate chain to the main database.
Looking at https://github.com/liip/LiipFunctionalTestBundle/blob/master/Test/WebTestCase.php I am unsure as to whether it supports multiple databases or whether I'm totally missing the point?
I would appreciate any advice you can give me!
Thanks,
Hi,
Every time you attempt to use loginAs in Symfony 2.1, the actual request contains no session, which leads the entire operation to fail, because it never authenticates the user.
"Deprecated: getEntityManager is deprecated since Symfony 2.1. Use getManager"
see:
https://github.com/liip/LiipFunctionalTestBundle/blob/master/Test/WebTestCase.php#L242
$this->loadFixtures($classes, null, 'doctrine_mongodb', 1);
PHP Fatal error: Call to undefined method Doctrine\Common\DataFixtures\Purger\MongoDBPurger::setPurgeMode() in
...../vendor/liip/functional-test-bundle/Liip/FunctionalTestBundle/Test/WebTestCase.php on line 305
Would it be possible to tag a release?
Could be great if this bundle contains also the app
directory,
in order to execute functional tests when you are developing a bundle and you are not into a sandbox.
app/config/config.yml, app/config/security.yml, app/config/routing.yml
app/AppKernel.php
Hi,
Since I am using your bundle with entities where the identifier column is different that id
(e.g. code
), I encounter an error.
I declared this in my setUp:
$classes = [
'Acme\DemoBundle\Tests\DataFixtures\ORM\LoadUserData',
'Acme\DemoBundle\Tests\DataFixtures\ORM\LoadCountryData'
];
$this->loadFixtures($classes);
The identifier for the entity User
is id
, so the tests functioning properly. But with the entity Country
, my identifier field is code
. And I encounter this error:
PHP Fatal error: Call to undefined method Proxies\__CG__\Acme\DemoBundle\Entity\Country::getId() in vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php on line 67
PHP Stack trace:
PHP 1. {main}() /usr/local/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/local/bin/phpunit:586
PHP 3. PHPUnit_TextUI_Command->run() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:132
PHP 4. PHPUnit_TextUI_TestRunner->doRun() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:179
PHP 5. PHPUnit_Framework_TestSuite->run() vendor/phpunit/phpunit/src/TextUI/TestRunner.php:426
PHP 6. PHPUnit_Framework_TestCase->run() vendor/phpunit/phpunit/src/Framework/TestSuite.php:699
PHP 7. PHPUnit_Framework_TestResult->run() vendor/phpunit/phpunit/src/Framework/TestCase.php:760
PHP 8. PHPUnit_Framework_TestCase->runBare() vendor/phpunit/phpunit/src/Framework/TestResult.php:686
PHP 9. Acme\DemoBundle\Tests\Controller\UserControllerTest->setUp() vendor/phpunit/phpunit/src/Framework/TestCase.php:822
PHP 10. Liip\FunctionalTestBundle\Test\WebTestCase->loadFixtures() src/Acme/DemoBundle/Tests/Controller/UserControllerTest.php:29
PHP 11. Doctrine\Common\DataFixtures\ProxyReferenceRepository->save() vendor/liip/functional-test-bundle/Liip/FunctionalTestBundle/Test/WebTestCase.php:336
PHP 12. Doctrine\Common\DataFixtures\ProxyReferenceRepository->serialize() vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/ProxyReferenceRepository.php:132
I could fix this error by adding in my entity Country
a function called getId
and which returns $this->code
. But he see that the bug was fix in doctrine\data-fixtures in this commit.
I am using:
doctrine/data-fixtures v1.0.0
doctrine/doctrine-fixtures-bundle v2.2.0
liip/functional-test-bundle 1.0.2
That needs to be updated?
Thanks,
Kind regards.
session.storage.options is currently referenced in makeClient () in
liip\functional-test-bundle\Liip\FunctionalTestBundle\Test\WebTestCase.php
This parameter is deprecated in Symfony 2.1, see http://symfony.com/doc/current/cookbook/configuration/pdo_session_storage.html
"New in version 2.1: In Symfony2.1 the class and namespace are slightly modified. You can now find the session storage classes in the Session\Storage namespace: Symfony\Component\HttpFoundation\Session\Storage. Also note that in Symfony2.1 you should configure handler_id not storage_id like in Symfony2.0. Below, you'll notice that %session.storage.options% is not used anymore."
class MailerTest extends WebTestCase
{
protected $user;
protected $em;
protected $mailer;
protected function setUp()
{
parent::setUp();
$user = new User();
$user->setEmail('[email protected]');
$user->setUsername('isqad88');
$user->setPlainPassword('test');
$em = $this->getContainer()->get('doctrine')->getManager();
$em->persist($user);
$em->flush();
$this->user = $user;
$this->em = $em;
$this->mailer = new MessageMailer();
}
//...
public function tearDown()
{
$this->em->remove($this->user);
$this->em->flush();
parent::tearDown();
}
In my case I got error:
call undefined method remove() in tearDown(), it mean, that method setUp() is not called.
Currently, when doing e2e tests as in #136, every requests gets a new fresh SQLite instance. It would be good, if one good play scenarios with multiple requests where later requests see the changes done by earlier requests.
This could be implemented with two additional GET parameters:
When the _dbsession parameter is present than an SQLite db instance with this name is either created or reused.
When the _dbsessionend parameter is also present than the SQLite db instance with this name will be deleted at the end of the request. This might not be that important?
Hi,
I have config something like below, to use AcmeUsersBundle entities in AcmeDemoBundle I have added AcmeUsersBundle under default.
default:
connection: default
mappings:
AcmeDemoBundle : ~
AcmeUsersBundle : ~
users:
connection: ownership
mappings:
AcmeUsersBundle : ~
this->loadFixtures($classes, null, 'doctrine', ORMPurger::PURGE_MODE_TRUNCATE);
Tests tries to find Users database tables under default database as entities are shared, and truncate fails.
Also in case of cross database join, I had to use database name in mapping yml, e.g.
in Users.orm.yml
table: users.profile , it is with db name, so it will truncate Production database and not users_testing.profile.
What could be the solution ?
Hi,
Since I updated to symfony 2.2, i got some database locked errors :
Here is the output of console :
PHPUnit 3.7.14 by Sebastian Bergmann.
Configuration read from /data/www/root/boedito/app/phpunit.xml.dist
EE
Time: 01:04, Memory: 49.50Mb
There were 2 errors:
1) GMP\CommonAdminBundle\Tests\Command\ExportArticlesCommandTest::testExportArticlesLDT
PDOException: SQLSTATE[HY000]: General error: 5 cannot rollback transaction - SQL statements in progress
/data/www/root/boedito/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1038
/data/www/root/boedito/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:231
/data/www/root/boedito/app/cache/test/jms_diextra/doctrine/EntityManager_516c93ae3c28d.php:31
/data/www/root/boedito/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php:85
/data/www/root/boedito/vendor/liip/functional-test-bundle/Liip/FunctionalTestBundle/Test/WebTestCase.php:253
/data/www/root/boedito/src/GMP/CommonAdminBundle/Tests/Command/ExportArticlesCommandTest.php:22
2) GMP\CommonAdminBundle\Tests\Command\ImportQPSCommandTest::testImportLDT
Doctrine\DBAL\DBALException: An exception occurred while executing 'DROP TABLE articles':
SQLSTATE[HY000]: General error: 5 database is locked
/data/www/root/boedito/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:47
/data/www/root/boedito/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:646
/data/www/root/boedito/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/SchemaTool.php:630
/data/www/root/boedito/vendor/liip/functional-test-bundle/Liip/FunctionalTestBundle/Test/WebTestCase.php:228
/data/www/root/boedito/src/GMP/CommonAdminBundle/Tests/Command/ImportQPSCommandTest.php:24
Caused by
PDOException: SQLSTATE[HY000]: General error: 5 database is locked
/data/www/root/boedito/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:646
/data/www/root/boedito/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/SchemaTool.php:630
/data/www/root/boedito/vendor/liip/functional-test-bundle/Liip/FunctionalTestBundle/Test/WebTestCase.php:228
/data/www/root/boedito/src/GMP/CommonAdminBundle/Tests/Command/ImportQPSCommandTest.php:24
FAILURES!
Tests: 2, Assertions: 0, Errors: 2.
Prior to this update, everything was fine. I am currently looking into it.
Any help would be appreciated.
I used default phpunit configuration from symfony-sandbox. It try run tests from Liip\FunctionalTestBundle\Test\
$ phpunit -c app/
PHPUnit 3.5.7 by Sebastian Bergmann.
.F.......
Time: 0 seconds, Memory: 23.75Mb
There was 1 failure:
It seems, this bundle is mostly used for tests with PHPUnit and WebTestCase. We want to also do tests in a browser (e.g. via [1][2]). This means we need to include test setup information in the HTTP requests (via Query params?):
e.g.
localhost:8000/someroute?_login=admin&_fixtures=Bamarni\MainBundle\DataFixtures\ORM\LoadData,Me\MyBundle\DataFixtures\ORM\LoadData
And we need a listener to do this on KernelEvents::REQUEST(?).
[1] http://angular.github.io/protractor
[2] https://github.com/minkphp
I'll work on this next week unless somebody claims this would be a silly idea. Would you take a PR for this?
What do you think to add a function to valid json response?
Do you think this could be useful?
we used to use a modified function of the @willdurand assertJsonResponse function:
protected function assertJsonResponse($response, $statusCode = 200, $checkValidJson = true)
{
$this->assertEquals(
$statusCode, $response->getStatusCode(),
$response->getContent()
);
$this->assertTrue(
$response->headers->contains('Content-Type', 'application/json'),
$response->headers
);
if ($checkValidJson) {
$decode = json_decode($response->getContent());
$this->assertTrue(($decode != null && $decode != false),
$response->getContent()
);
}
}
source:
http://williamdurand.fr/2012/08/02/rest-apis-with-symfony2-the-right-way/
My functional tests extends this bundle's WebTestCase
and using the setUp()
method I'm loading in the needed fixtures before all tests. The test environment is using SQLite, so to take advantage of the backup file option. This works great โฆ in most cases. :)
However when I have a test that modifies the database somehow, those modifications doesn't seem to take effect when making client requests. For example I first GET / to see that it looks alright with the fixtures and then I make some changes like adding a blog post, before making another request to make sure it still renders as expected. But the blog post is nowhere to be found.
If I double check the database after making the request, the change is definitely still in there. I just can't make sense of that. It's like the request handling's using its own, separate database.
Does anyone know what could be wrong? Or how I could dig in to find the problem myself? Or maybe how I could approach this differently? Any help is greatly appreciated.
The README doesn't mention what happens when you don't use SQLite. Namely, it took awhile for me to figure out that in WebTestCase.php, the schema only gets created automatically if you're using SQLite.
Here's what I ended up hacking together to load my schema/fixtures under a test db (non-sqlite):
class AccountControllerTest extends WebTestCase
{
public function setUp()
{
$em = $this->getContainer()->get('doctrine')->getManager();
if (!isset($metadatas)) {
$metadatas = $em->getMetadataFactory()->getAllMetadata();
}
$schemaTool = new SchemaTool($em);
$schemaTool->dropDatabase();
if (!empty($metadatas)) {
$schemaTool->createSchema($metadatas);
}
$this->postFixtureSetup();
$classes = array(
'Acme\MyBundle\DataFixtures\ORM\LoadUserData',
);
$this->loadFixtures($classes);
}
//...
}
Even some mention in the README that non-sqlite databases must create their own schema would be useful.
It drives me insane to see red or yellow warnings in Eclipse. There shall be none!
I assume, these Loaders are there for backwards compatibility:
in WebTestCase.php
use Symfony\Bundle\DoctrineFixturesBundle\Common\DataFixtures\Loader as SymfonyFixturesLoader;
use Doctrine\Bundle\FixturesBundle\Common\DataFixtures\Loader as DoctrineFixturesLoader;
Are there still projects depending on these legacy loaders?
As of commit: aaf1095
I get the following error on the second run of my test suite, reverting to the previous revision works fine:
1) Ylly\Extension\ThemeBundle\Tests\Util\BaseThemeOverviewModelTest::testGetDom
RuntimeException: The proxy file "/home/daniel/www/yProx/apps/admin/cache/test/doctrine/orm/Proxies/YllyCmsBundleEntitySite.php" does not exist. If you still have objects serialized in the session, you need to clear the session manually.
I am using the latest "master" of doctrine-fixtures
If using loadFixtures() on a table in MySQL 5.5 with foreign key constraints, I get the following error:
SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint
Reverting to 03a1892 corrects the behavior.
Is it possible to pass references between fixtures ?
e.g.:
class LoadData1
{
function load(ObjectManager $manager)
{
$this->addReference('object', $object);
}
}
class LoadData2
{
function load(ObjectManager $manager)
{
$object = $this->getReference('object');
}
}
If I try it, I get this error message:
Notice: Undefined index: object in /.../vendor/doctrine-fixtures/lib/Doctrine/Common/DataFixtures/ReferenceRepository.php line 132
I think both fixtures does not have the same ReferenceRepository.
When I use LiipFunctionalTestBundle to test our project in Symfony2, I got Permission denied error.
below is my testsing enviroment and error message:
env:
OS:Windows 7 x32
PHP :5.3.5
PHPUnit: 3.5.14
OS:Windows 7 x64 sp1
PHP :5.3.6
PHPUnit: 3.5.14
config_test.yml:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.db
liip_functional_test:
cache_sqlite_db: true
but already get
D:\wamp\www\Project\vendor\symfony\src\Symfony\Component\HttpKernel\Debug\ErrorHandler.php:65
D:\wamp\www\Project\vendor\doctrine-dbal\lib\Doctrine\DBAL\Schema\SqliteSchemaManager.php:42
D:\wamp\www\Project\vendor\bundles\Liip\FunctionalTestBundle\Test\WebTestCase.php:142
D:\wamp\www\Project\src\ProjectBundle\Tests\Functional\UserFunctionalTest.php:20
Hi,
When I write unit test, I would like to put common used fixtures in the function setUp(),
and put some individual used fixtures in the test functions, but I found that the function loadFixtures()
would drop the previous database, so when calling loadFixtures() in the individual test functions,
it wouldn't find the common fixtures, how could I do to resolve this? thanks in advanced.
The DoctrineBundle bundle has been moved to the Doctrine organization. And the original DoctrineFixturesBundle is now have a different namescape.
This change breaks BC with the WebTestCase
Last night I ran composer update to update my vendors folder, and since then I'm getting the following error from LippFunctionalTestBundle when composer tries to run cache:clear:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
The service "liip_functional_test.query_count.query_count_client" has a dependency on a non-existent parameter "test.client.parameters".
I don't believe this to be a bug, but rather a need to update the documentation. I've been trying to get this error to go away, so I added:
test.client.parameters: ~
to parameters.yml
The error goes away, but the following then happens on cache:clear:
[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
The service "liip_functional_test.query_count.query_count_client" has a dependency on a non-existent service "test.client.history".
I'm not entirely sure how to configure this service, so it would be nice to have some directions in the documentation for the library.
I'm not a developer on this project, but rather an end user, and have been using this bundle for quite a while, and it's awesome.
I'd love to get my project running again, as since my last composer update, I am unable to even run cache:clear.
It would be great if we could handle master/slave connections. Currently it can not load database and tests fail when slaves connections are defined in the configuration.
Main configuration:
# app/config/config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: 127.0.0.1
port: null
dbname: my_database
user: root
password: 12345
charset: UTF8
slaves:
slave1:
host: null
port: null
dbname: my_database
user: root
password: 12345
charset: UTF8
Test configuration:
# app/config/config_test.yml
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.db
Liip\FunctionalTestBundle\Test\WebTestCase
expects this kind of parameters:
array(9) {
'dbname' =>
string(18) "my_database"
'host' =>
string(9) "127.0.0.1"
'port' =>
NULL
'user' =>
string(4) "root"
'password' =>
string(4) "12345"
'charset' =>
string(4) "UTF8"
'driver' =>
string(10) "pdo_sqlite"
'path' =>
string(53) "/my_project/app/cache/test/test.db"
'driverOptions' =>
array(0) {
}
}
Whereas in this context it receives something like that:
array(5) {
'driver' =>
string(10) "pdo_sqlite"
'slaves' =>
array(1) {
'slave1' =>
array(7) {
'dbname' =>
string(18) "my_database"
'host' =>
NULL
'port' =>
NULL
'user' =>
string(4) "root"
'password' =>
string(4) "12345"
'charset' =>
string(4) "UTF8"
'driver' =>
string(10) "pdo_sqlite"
}
}
'driverOptions' =>
array(0) {
}
'master' =>
array(8) {
'dbname' =>
string(18) "my_database"
'host' =>
string(9) "127.0.0.1"
'port' =>
NULL
'user' =>
string(4) "root"
'password' =>
string(4) "12345"
'charset' =>
string(4) "UTF8"
'path' =>
string(53) "/my_project/app/cache/test/test.db"
'driver' =>
string(10) "pdo_sqlite"
}
'wrapperClass' =>
string(47) "Doctrine\DBAL\Connections\MasterSlaveConnection"
}
And here is the output of PHPUnit:
There was 1 error:
1) Acme\Bundle\DemoBundle\Tests\FooTest::testBar
Undefined index: dbname
/my_project/www/vendor/liip/functional-test-bundle/Liip/FunctionalTestBundle/Test/WebTestCase.php:254
I remember seeing the same problem in doctrine/DoctrineBundle#144 (which is now fixed).
Set up something like this by default: http://blog.lyrixx.info/2013/04/12/symfony2-how-to-mock-services-during-functional-tests.html
Not sure how to best do this to not require a custom Kernel. Possibly make the Kernel class on the fly, extending the current Kernel or something?
It would be nice if the loadFixtures
method would return the reference repository containing any references that my loaders have created.
This is useful for some functional testing situations where I have an entity represented in the DOM somewhere with a id attribute specified. E.g.
<div id="person-1234">
<span class="name>John Smith</span>
</div>
In this situation my DOM id is created by concatenating the generated ORM id with the string "person".
The only way I can currently retrieve this id is to run a query against the database after the fixtures have been loaded. This can be a bit troublesome as it clutters the test code and often requires that I craft my test fixture data with alternate unique data.
The data fixtures executor maintains a reference repository where references to loaded fixture entities can be stored for later access by other fixtures etc. By returning this reference repository when calling loadFixtures
we can then access any entity providing we have added it to the reference repository in our fixture loaders.
I have a work in progress for a solution, but it doesn't feel quite right. WIP: http://github.com/jonotron/LiipFunctionalTestBundle/blob/reference-fixture/Test/WebTestCase.php
The easiest implementation issue is when sqlite caching is turned off, then we can just return the executor's reference repository. The more complicated issue is when sqlite caching is turned on, and no executor is actually created. For this we will need to serialize the reference repository for later reloading.
JMSSerializerBundle works great for this, but makes the tests run extremely slow unless you add annotations to exclude related objects (as JMSSerializer will happily traverse the object graph serializing almost the entire database). Furthermore, it requires that we add @Type
annotations to any entity and related entity that might be referenced and subsequently serialized/deserialized.
I am currently experimenting a little bit with this bundle and came along some shortcommings (maybe on my side)
The basic use case is that I want to load all my fixtures initially once, and at the end of some specific test cases (those where I change data in the Database) I would like to reset the database to its initial state. Maybe even by copying an the initially saved sqlite file. Maybe this is already possible but I didn't find the right way in the documentation and im also not 100% aware what cache_sqlite_db: true is doing.
Thanks,
Marc
This is kind of a strange error so I don't really know if this is related to this bundle or Doctrine or PDO or the way PDO uses the SQLite API or SQLite itself or what, but I get this error when running tests that extend Liip\FunctionalTestBundle\Test\WebTestCase. It only happens on the very first test that uses the db, other tests after that execute correctly. And it happens only after cache has been cleared, if the db files are in cache then there is no error.
On local dev machines we can of course run again if we get this error, but our Jenkins build clears the cache before running the tests, so our build always fails :(
Anyone else ever had this issue or have any idea what could be causing this?
Hi there!
In my app i create category records, which have a relation "parentCategory" to themselfes. Problem is, as far as i see: when you bundle tries to truncate the tables on setUp (don't know how this is done exactly) I get following error: "PDOException: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (symfony-pr10
.category
, CONSTRAINT category_ibfk_2
FOREIGN KEY (parentCategory_id
) REFERENCES category
(id
))"
do you have any idea how to fix this?
BR Stephan
Using Symfony 2.2 I am trying to make use of the WebTestCase#loginAs method.
$lovelettr = $em->getRepository('MyBundle:User')
->findByUsername('lovelettr')[0];
$this->loginAs($lovelettr, 'client');
$client = $this->makeClient();
This raises an InvalidArgumentException
with the message Missing session.storage.options#name
. What do I need to configure to enable this? I am not seeing it in the documentation.
I would like to mention that for those of us who store the session data using a PdoSessionHandler the session filesystem won't work.
In this case framework.session.storage_id should be set to session.storage.php_bridge (reference: http://symfony.com/doc/current/cookbook/session/php_bridge.html ).
If I understand correctly this is because Liip uses some deprecated session storage code (see #80 ). I didn't have time to dig deeper in the Liip code.
In case others try to find the weird exception, when leaving out
storage_id: session.storage.filesystem (i.e. having only handler_id: pdo)
I was getting this exception from the controller I was calling:
Failed to start the session because headers have already been sent by "Project\vendor\phpunit\phpunit\PHPUnit\Util\Printer.php" at line 172.
the WebTestCase class provide 2 public method , makeClient
and loginAs
which are not advertized though they prove quite useful as they cover the very common case of doing functionnal tests on pages that require authentication, it would be great if the documentation was mentioning them
Hi there,
Currently I am using this bundle to test command line with runCommand
method, but I cannot see the exception I am expecting(setExpectedException
is not working ), and the exit code. It seems that the exception has been caught by default. How can I see the exception I am expecting to see?
Thanks.
It doesnt make sense to rely on inheritance for adding features like fixture loading or html5 validation. The Bundle should instead provide a base class that gives convenient access to the DIC from which the user can then get services for the different tasks.
I have the situation where I have mutliple test environments, it'd be great to be able to specify what environment's cache directory the test db will be placed into.
From what I can tell it always uses 'test' at the moment.
Hi,
I am loading fixtures using LippFunctionalTestBundle, it deletes all test records and set auto increment id to the next one when it loads the data, I want to set --purge-with-truncate option so that instead of deleting doctrine should use truncate. is it possible ?
Enabling the Query Counter causes an exception from Doctrine's annotation reader because the @dataProvider
annotation is not ignored:
Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The annotation "@dataProvider" in method Acme\DemoBundle\Controller\FooControllerTest::testBar() was never imported. Did you maybe forget to add a "use" statement for this annotation?
Maybe it's worth a note in the docs? Currently I'm fixing this by adding an @IgnoreAnnotation
annotation to the test class:
Liip\FunctionalTestBundle\Test\WebTestCase as BaseWebTestCase;
/**
* @IgnoreAnnotation("dataProvider")
*/
class FooControllerTest extends BaseWebTestCase
{
/**
* @dataProvider provideData
*/
public function testWithData($first, $second)
{
// ...
}
public function provideData()
{
return array(
array(4, 5),
// ...
);
}
}
Please let me know what you think, I could do a PR.
Another working, but not so clean approach, somewhere before executing the tests, e.g. you own additional parent BaseWebTestCase
class:
use Liip\FunctionalTestBundle\Test\WebTestCase as BaseWebTestCase;
use Doctrine\Common\Annotations\AnnotationReader;
AnnotationReader::addGlobalIgnoredName('dataProvider');
class WebTestCase extends BaseWebTestCase
{
// ...
I think also applies to all other PHPUnit annoations like @depends
etc.
subj )
Hi,
I am currently using the LiipFunctionalTestBundle using the cached pdo_sqlite driver.
I tried to cache the database through the configuration, but it seems impossible to preserve this state when you rely on executors to be accessed after.
It seems around line 173 of WebTestCase you have a void return, while actually many samples can rely of Executor.
Executors in Doctrine DataFixtures are healthy to name instances to be reused later inside of tests or even in other fixtures. This is achievable using the following like in your fixture class:
$this->addReference('<fixture_reference_name>', $referenceValue);
whenever you wanna consume it on a test case, all you need to do is:
$executor = $this->loadFixtures(array(
'App\DataFixtures\LoadTestFixtureData'
));
$repository = $executor->getReferenceRepository();
$referenceValue = $repository->getReference('<fixture_reference_name>');
As you may see, this is very useful when you have ID auto generation, because you may be unable to define which ID is the actual value of your test.
I have no idea how is it possible to be fixed... sorry! =(
Hi,
I am just starting with this bundle and it might be possible that I am trying to use it wrong. As I understood I should loadFixtures() before I run a test against the DB. But 80% of my DB Tests, don't modify my database. Thats why I am searching for a way to build my database once on the start of my testsuite and then only reset it after it was modified.
Is this also possible with this bundle or do I need to use something different?
In a functional test I get:
PDOException: SQLSTATE[HY000]: General error: 1 no such function: Soundex
, which is not surprising because
The soundex(X) function ... is omitted from SQLite by default
Can this be overcome somehow?
My console command need to get entity_manager and get test db user table info.
When I used runCommand method to Tests my console command and already loadFixtures
But command print out no such record in db;
Have anyone know how to let command test get fixtures database records?
In the README, or the examples, there is no guidance about setting up the database schema during the test. When I run my test suite I get:
PDOException: SQLSTATE[HY000]: General error: 1 no such table: Model
What do you think is the best way of doing this? Doing a runCommand against app/console doctrine:schema:update
? If you can help me get it going I'll submit a pull.
Add this to composer.json
:
"liip/functional-test-bundle": "dev-master"
To AppKernel.php
:
$bundles[] = new Liip\FunctionalTestBundle\LiipFunctionalTestBundle();
To app/config/config_test.yml
liip_functional_test: ~
framework:
test: ~
session:
storage_id: session.storage.filesystem
Add this to src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php
:
use Liip\FunctionalTestBundle\Test\WebTestCase;
class DemoControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();
$this->loadFixtures(array());
Then run phpunit -c app/
and get this error:
Fatal error: Class 'Doctrine\Common\DataFixtures\ProxyReferenceRepository' not found in /home/dan/Work/Symfony/vendor/liip/functional-test-bundle/Liip/FunctionalTestBundle/Test/WebTestCase.php on line 187
Hi,
I am using mysql instead of sqlite during functional test,
because I want to get the production performance data like requst time..etc.
When I run the functional test, it shows error like this:
Time: 5 seconds, Memory: 34.75Mb
There was 1 error:
test
.role
, CONSTRAINT FK_57698A6A727ACA70
FOREIGN KEY (parent_id
) REFERENCES role
(id
))/Users/apple/work/ddbak/vendor/doctrine-dbal/lib/Doctrine/DBAL/Connection.php:713
/Users/apple/work/ddbak/vendor/doctrine-fixtures/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php:120
/Users/apple/work/ddbak/vendor/doctrine-fixtures/lib/Doctrine/Common/DataFixtures/Executor/AbstractExecutor.php:109
/Users/apple/work/ddbak/vendor/bundles/Liip/FunctionalTestBundle/Test/WebTestCase.php:198
/Users/apple/work/ddbak/src/Bundle/Tests/Functional/UserFunctionalTest.php:48
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
And when I use sqlite as testing db, it would run successfully,
so I think something go wrong while dropping table which is created by data fixture
with mysql as testing db.
Thanks in advanced.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.