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
<?php
class AssertsTest extends PHPUnit_Framework_TestCase
{
public function testAsserts()
{
$module = new \Codeception\Module\Asserts(make_container());
$module->assertEquals(1, 1);
$module->assertContains(1, [1, 2]);
$module->assertSame(1, 1);
$module->assertNotSame(1, '1');
$module->assertRegExp('/^[\d]$/', '1');
$module->assertNotRegExp('/^[a-z]$/', '1');
$module->assertStringStartsWith('fo', 'foo');
$module->assertStringStartsNotWith('ba', 'foo');
$module->assertEmpty([]);
$module->assertNotEmpty([1]);
$module->assertNull(null);
$module->assertNotNull('');
$module->assertNotNull(false);
$module->assertNotNull(0);
$module->assertTrue(true);
$module->assertFalse(false);
$module->assertFileExists(__FILE__);
$module->assertFileNotExists(__FILE__ . '.notExist');
$module->assertInstanceOf('Exception', new Exception());
$module->assertInternalType('integer', 5);
$module->assertArrayHasKey('one', ['one' => 1, 'two' => 2]);
$module->assertArraySubset(['foo' => [1]], ['foo' => [1, 2]]);
$module->assertCount(3, [1, 2, 3]);
}
public function testExceptions()
{
$module = new \Codeception\Module\Asserts(make_container());
$module->expectException('Exception', function () {
throw new Exception;
});
$module->expectException(new Exception('here'), function () {
throw new Exception('here');
});
$module->expectException(new Exception('here', 200), function () {
throw new Exception('here', 200);
});
}
/**
* @expectedException PHPUnit_Framework_AssertionFailedError
*/
public function testExceptionFails()
{
$module = new \Codeception\Module\Asserts(make_container());
$module->expectException(new Exception('here', 200), function () {
throw new Exception('here', 2);
});
}
}