Create fixtures with specific data from DB for PhpUnit

We’re desiring to appy TDD with unit test script.
But developers feel so hard to make test data for their function.
So for long time, we use Db instead of fixtures!

That’s enough. Let’s get valid data from db for your test case from Db. it’s already solved by CakePHP with bake from commandline.

Step 1:

– surely, you need config db at database.php where you want to get data. – open cmd then go to directory of your app.
– type      cake bake

– you got the list of table you want.

cakephp bake fixture
cakephp bake fixture

Step 2:

– follow guideline of cake

+ enter number id of table

+ import schema: n

+ use record.. : n

+ build this fixture with data from TableName’s table? y

+ SQL condition (WHERE)

+ Limit number

cake bake selections
cake bake selections

It’s finish. You got fixtures with real data for your script . Plz merge it with the old one, dont overwrite test data of other developers!




Add a Comment

Your email address will not be published.