News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Data Fixtures in Symfony2
February 27, 2014 @ 12:50:44

The SitePoint PHP blog has posted a tutorial from Taylor Ren looking at the use of fixtures in Symfony2. Fixtures allow you to create a set of test (or just initial) data to populate the database in an automated way.

Back when I first started to learn Symfony (1.x) with its Jobeet project, I thought the ability to load a bunch of test data into the database very useful. In this article, we will revisit this feature, which has been completely re-modeled and thus has a lot to teach us.

He uses two third-party libraries to give the Symfony application a bit more "power" - the DoctrineFixturesBundle and PHPUnit. The second is used for testing the results of the fixtures, not the actual loading process. He walks you through the creation of your first fixture file for a book-based example. The fixture uses the Doctrine functionality to create "place" data. He includes the command to run the fixture (via the Symfony app/console command) and what the result should look like. He comes back around and shows the same process with other general book data, also talking about primary keys and references.

0 comments voice your opinion now!
data fixture database symfony2 application tutorial example

Link: http://www.sitepoint.com/data-fixtures-symfony2/

Michelangelo van Dam:
Learning lessons at ZendUncon
November 13, 2012 @ 10:04:55

Michelangelo van Dam has shared something new he learned at the recent ZendCon conference about using fixtures with his PHPUnit testing.

In my previous post I already mentioned Sebastian Jerzy Wilczyński (@dj_sebastian_w) and his uncon session "Unit Testing for Databases using fixtures and phpunit". It made me wonder how much difference it would make if you use fixtures instead of testing database interactions using predefined sets of data. Since I work a lot with Zend Framework I was looking at how I could use fixtures and mock objects to follow Sebastian's guidelines. So I gave it a try. This is what I came up with.

He illustrates with some example code - a set of database data (the fixtures) and sample tests that use the Zend Framework's mapper and table gateway functionality to work with the tables. His test then mocks out the DbTable class for the "Order" object and forces a return of the database fixture data.

0 comments voice your opinion now!
phpunit database fixture mock zendframework unittest


Carl Vuorinen:
Controller testing with database fixtures in Zend Framework
November 05, 2012 @ 12:44:31

Carl Vuorinen has a recent post to his site showing you how to unit test your Zend Framework (v1) controllers with the help of database fixtures to provide the test with valid data.

So I started thinking that there must be a way to use fixtures for the database the same way as when testing models with PHPUnit Database extension (PHPUnit_Extensions_Database_TestCase). But since PHP does not have multiple inheritance, we can't extend both Zend_Test_PHPUnit_ControllerTestCase and PHPUnit_Extensions_Database_TestCase. So I started out to create a controller test case class that has support for fixtures the same way as the database test case. I mean, how hard can it be?

He dug into the code for the extension and finally came up with a working solution - an abstract class with "_setup" and "_setupDatabase" methods that create what you'll need to perform your tests. A sample test is included in the post to show you it in action.

0 comments voice your opinion now!
zendframework controller testing database fixture


Joshua Thijssen's Blog:
Symfony2 Implementing ACL rules in your Data Fixtures
July 04, 2012 @ 16:33:23

Joshua Thijssen has a new post to his blog looking at a method for setting up ACL rules in fixtures for your Symfony2-based applications.

Doctrine's DataFixtures are a great way to add test data to your application. It's fairly easy to get this going: Create a fixureLoader that extends DoctrineCommonDataFixturesAbstractFixture, had a load() method and off you go. However, sometimes you want your data also to be protected by Symfony 2′s ACL layer. Since there isn't a common way to do this, here is one way on how I implemented this.

His method uses the ContainerAware interface on the fixture loader instance to be able to get at the container for the fixture. This allows you to use the usual ACL handling methods of the framework to provide restrictions based on things like usernames and roles.

0 comments voice your opinion now!
symfony2 fixture acl rule container loader tutorial


Michael Nitschinger's Blog:
RFC li3_fixtures Rewrite
February 27, 2012 @ 09:23:37

Michael Nitchinger has a new post to his blog about a rewrite for the Lithium framework - changing up the li3_fixtures plugin to make it a bit more of what the community needs.

The li3_fixtures plugin was my first Lithium plugin ever, and while it works okay, I feel there is a lot I can do to make it better and more flexible. In this post I want to share my ideas for a new fixture plugin and also want to gather feedback from the community to make it even more awesome.

He gives three instance where fixtures can come in extremely useful - making effective model unit tests with predictable data, mocking models with shortcuts to the data and mocking out web services. Want to add in your own suggestions for his refactor? Comment on the post!

0 comments voice your opinion now!
lithium framework plugin fixture data model unittest webservice


Sebastian Bergmann's Blog:
Sharing Fixtures and Stubbing/Mocking Static Methods
February 15, 2010 @ 12:55:49

Sebastian Bergmann has two recent posts dealing with some of the more difficult topics in unit testing. One looks at sharing fixtures between tests and the other talks about stubbing and mocking static methods in your tests.

From the first of the two tutorials:

A good example of a fixture that makes sense to share across several tests is a database connection: you log into the database once and reuse the database connection instead of creating a new connection for each test. This makes your tests run faster.

This fixture sharing example uses the setUpBeforeClass and tearDownAfterClass methods to create and destroy the connection.

In the second article Sebastian shows how to mock up a sample static function and mock it with the "staticExpects" helper.

0 comments voice your opinion now!
phpunit unittest stub mock static share fixture


Sebastian Bergmann's Blog:
PHPUnit 3.4.0 (Release)
September 17, 2009 @ 11:32:36

Sebastian Bergmann has announced the release of the latest version of the popular PHP unit testing software - PHPUnit.

Among the features introduced in this new version, the most notable are the support for test dependencies and fixture reuse as well as the possibility to run tests in separate PHP processes for increased test isolation. Please have a look at the ChangeLog for a complete list of changes.

As a teaser, he also mentions the work being done on the code coverage features that will be included in the next release.

0 comments voice your opinion now!
phpunit release dependencies fixture reuse


PHP-Tools Blog:
Testing FIT
June 22, 2007 @ 07:45:00

On the PHP-Tools blog, Gerd Schauffelberger has posted about a new PEAR package he's just created to implement the FIT testing protocol.

Testing_FIT is the PHP and pearish version of Ward Cunningham's FIT http://fit.c2.com. As such it provides an easy to use framework for acceptance software tests.

The package is a simple download and install and gives you four basic fixtures to use Action-, Column-, Row- and Primitve-Fixture (and a Summary-Fixture for stats purposes).

0 comments voice your opinion now!
fit pear package testingfit fixture fit pear package testingfit fixture



Community Events





Don't see your event here?
Let us know!


release zendserver laravel api list deployment developer series community language symfony podcast development conference interview tips framework code introduction threedevsandamaybe

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework