Codeception Testing with Yii Framework 2.0 [Day 9]

Today’s Objective(s)

  1. Delve deeper into the “expect” function used in testModelBoolean()
  2. Try to use the entire $I->wantTo(‘load all values’); style of Codeception
  3. Research executing tests and viewing results from a browser
  4. Research best practices for Unit testing in Yii
  5. Research best pracices for acceptance/functional testing in Yii

Introduction

As fate would have it, I was in the completely wrong ball park with my stumbles on Thursday. The definition of the expect function I’ve been using in testModelBoolean isn’t defined in Codeception\Codeception, but rather in Codeception\Verify and for today’s post I’ll describe how I got about to figuring that out and list the assertions that can be done using the result of expect.

The how

Spent the greater portion of today working on another project, which I’ve actually restarted completely to incorporate some of the things I’ve learnt (It started out as a simple project, but has grown to something that could become buggy without proper testing and the layout was turning chaotic).

So I’ve been practicing writing Unit tests of my own for this project, in which I used a combination of basic asserts from PHPUnit and using the expect function. I used the following functions with success:

expect('expectation', $foo->bar)->contains('string');
expect('expectation', $foo->bar)->equals('string');

Of course the first one is a bit of a blunder, since I was using it to check the string but it’s a check that the type is string. I found that out when I tried “->contains(2)”, the test failed because of a type difference.

But I digress, after those successes I developed the theory that it was basically dropping the “assert” and lowering the case of the first letter (assertEquals), so I tried out “->internalType(‘array’)”. This gave a fatal error telling me that I had made a call to an undefined method “Codeception\Verify::internalType()”. Voila! There was the actual class staring me in the face.

Conclusion

I know I promised to make a list of the assertions that can be done, but will have to post that tomorrow… or rather later today, which is why I’m cutting this short. It’s supposed to be daily, and I’d like to keep it as close to that as possible :)

So we now know where the expect function comes from and with that can find out what exactly can be checked using it. I’ll get into that tomorrow/today. ;)

Upcoming Objective(s)

  1. List the assertions that can be done using the result of expect
  2. Try to use the entire $I->wantTo(‘load all values’); style of Codeception
  3. Research executing tests and viewing results from a browser
  4. Research best practices for Unit testing in Yii
  5. Research best pracices for acceptance/functional testing in Yii

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>