-
Notifications
You must be signed in to change notification settings - Fork 4
/
ImplicitTeardownTest.php
58 lines (49 loc) · 1.5 KB
/
ImplicitTeardownTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
class ImplicitTeardownTest extends PHPUnit_Framework_TestCase
{
/**
* I keep the object on a field so that if In-Line Teardown is not
* executed, we'll see destruction messages at the end of the suite
* instead of after each test.
*/
private $fixtureToTeardown;
private static $classLevelFixtureToTeardown;
public function testExpectMethodForInlineTeardown()
{
$this->fixtureToTeardown = new MyClassWithDestructor(1);
self::$classLevelFixtureToTeardown = new MyClassWithDestructor(2);
$this->assertTrue(false, 'First test failure message.');
}
public function testSomethingElseWhichCouldResultInAFatalError()
{
// suppose your SUT code returns this or a scalar for a
// regression or bug
$object = null;
$this->assertInstanceOf('SplQueue', $object);
$this->assertEquals('dummy', $object->dequeue());
}
/**
* A workaround to being able to support expect() methods
*/
public function tearDown()
{
unset($this->fixtureToTeardown);
}
public static function tearDownAfterClass()
{
// you can't unset() a static property. Don't ask me why
self::$classLevelFixtureToTeardown = null;
}
}
class MyClassWithDestructor
{
private $id;
public function __construct($id)
{
$this->id = $id;
}
public function __destruct()
{
echo "The instance {$this->id} of MyClassWithDestructor has been destroyed.\n";
}
}