1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace MyTester; |
6
|
|
|
|
7
|
|
|
use stdClass; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Test suite for class Assert |
11
|
|
|
* |
12
|
|
|
* @author Jakub Konečný |
13
|
|
|
*/ |
14
|
|
|
final class AssertTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Test assertion functions |
18
|
|
|
*/ |
19
|
|
|
public function testAssertion(): void |
20
|
|
|
{ |
21
|
|
|
$this->assertSame("abc", "abc"); |
22
|
|
|
$this->assertNotSame("abc", "def"); |
23
|
|
|
$this->assertTrue(true); |
24
|
|
|
$this->assertTruthy(1); |
25
|
|
|
$this->assertFalse(false); |
26
|
|
|
$this->assertFalsey(0); |
27
|
|
|
$this->assertNull(null); |
28
|
|
|
$this->assertNotNull("abc"); |
29
|
|
|
$testArray = ["abc"]; |
30
|
|
|
$this->assertContains("abc", $testArray); |
31
|
|
|
$this->assertNotContains("def", $testArray); |
32
|
|
|
$this->assertCount(1, $testArray); |
33
|
|
|
$this->assertNotCount(0, $testArray); |
34
|
|
|
$this->assertType("array", $testArray); |
35
|
|
|
$this->assertType(__CLASS__, $this); |
36
|
|
|
$this->assertType("string", "abc"); |
37
|
|
|
$this->assertType("bool", true); |
38
|
|
|
$this->assertType("int", 42); |
39
|
|
|
$this->assertType("null", null); |
40
|
|
|
$this->assertType("object", new stdClass()); |
41
|
|
|
$this->assertType("scalar", 42); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Test custom assertions and custom messages |
46
|
|
|
*/ |
47
|
|
|
public function testCustomAssertion(): void |
48
|
|
|
{ |
49
|
|
|
$this->assert("5 > 2", "5 is not greater that 2."); |
50
|
|
|
$this->assert("5 >= 2", "5 is not greater or equal to 2."); |
51
|
|
|
$this->assert("2 < 5", "2 is not lesser than 5."); |
52
|
|
|
$this->assert("2 <= 5", "2 is not lesser or equal to 5."); |
53
|
|
|
$this->assert("abc != def", "abc is def."); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|