6. Unit Test
a method by which individual units of source
code [...] are tested to determine if they are fit
for use
http://en.wikipedia.org/wiki/Unit_testing
20. Preparing For Your Tests
setup() -> Before every tests
teardown() -> After every tests
setUpBeforeClass() + tearDownAfterClass()
Once per test case
36. More duplication
/** @test */
public function factOf1() {
$this->assertSame(1,
$this->facto->fact(1));
}
/** @test */
public function factOf2() {
$this->assertSame(2,
$this->facto->fact(2));
}
47. Setter Injection
class Foo {
public function setBar(Bar $bar) {
$this->bar = $bar;
}
public function doSomething() {
// Use $this->bar
}
}
48. Constructor Injection
class Foo {
public function __construct(
Bar $bar) {
$this->bar = $bar;
}
public function doSomething() {
// Use $this->bar
}
}
49. Pass the dependency directly
class Foo {
public function doSomething(
Bar $bar) {
// Use $bar
}
}
52. Check if a folder was created
$root = vfsStream::setup('dir');
$parentDir = $root->url('dir');
//Code creating sub folder
$SUT->createDir($parentDir, 'test');
$this->assertTrue(
$root->hasChild('test'));