Basics of writing tests using PHPUnit
We're not going to go into very much detail about how to use PHPUnit, and instead leave it to its in-depth documentation ( https://phpunit.de/manual/5.6/en/index.html ). For the purpose of this chapter, we should, however, have a quick look at some of the basics we're going to use for the purposes of testing RxPHP code.
There are some basic rules we should follow:
All tests for a single class,Â
MyClass
, go into a class calledÂMyClassTest
, which should inherit fromÂPHPUnit\Framework\TestCase
.Each test scenario is represented by a function prefixed withÂ
test
or annotated withÂ@test
annotation. This way it can be auto-discovered by PHPUnit.Each test function consists of one or more assertions usingÂ
assert*
methods (more on them later). If any one of them fails, the whole test scenario (one test function) is marked as failed. All assertions are inherited fromÂPHPUnit\Framework\TestCase
.We can specify dependencies between test scenarios usingÂ
@depends testname...