Now, how many operations left to test? Two, right?
Here is the test for the method append():
function testAppend() { $this->file->putContents("SimpleTest"); $this->assertTrue($this->file->append("NeverMind")); $this->assertWantedPattern('~nevermind$~i', $this->file->getContents()); } |
Note that we didn't test the method putContents() again since it was tested before (tests are performed in the order they had been written in).
We use a new assertion method that is assertWantedPattern() which will try to match the regular expression pattern in the first argument against the second argument.
We want to make sure that the word "NeverMind" is found at the end of the file so the $ sign in regexp will help us.
And finally, our last test:
function testDelete() { $this->assertTrue($this->file->delete()); $this->assertFalse(file_exists($this->filename)); } |
There is no new assertion type used here and what I want to test is clear, so I need not say anything here, do I? It's pretty obvious :)