-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGuardAssertionTest.php
44 lines (35 loc) · 1.23 KB
/
GuardAssertionTest.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
<?php
class GuardAssertionTest extends PHPUnit_Framework_TestCase
{
public function testTheObjectWhichWasnt()
{
$object = null;
// from PHPUnit 3.5 you can also use $this->assertInstanceOf()
$this->assertTrue($object instanceof MyClass, 'The object is not an instance of MyClass.');
$this->assertEquals(42, $object->getSomeField());
}
public function testTheArrayWhichIsEmptyAndThenFull()
{
$arrayObject = $this->getACollection();
$this->assertEquals(0, count($arrayObject), 'The collection is not empty.');
$arrayObject[] = 42;
$this->assertEquals(1, count($arrayObject), 'The collection does not accept new elements.');
}
public function testTheDriverWhichIsNotAvailable()
{
$this->assertMysqlDatabaseIsAvailable();
$connection = new PDO('mysql:...');
}
private function getACollection()
{
return new ArrayObject();
}
private function assertMysqlDatabaseIsAvailable()
{
// for simplicity, let's say some configuration is missing
// and we check it here
if (true) {
$this->markTestSkipped('The MySQL database for testing is not available.');
}
}
}