-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAssertAdapter.php
115 lines (94 loc) · 3.89 KB
/
AssertAdapter.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/*
* Copyright (c) Ouzo contributors, https://github.com/letsdrink/ouzo
* This file is made available under the MIT License (view the LICENSE file for more information).
*/
namespace Ouzo\Tests;
use PHPUnit\Framework\Assert as PHPUnit_Assert;
use PHPUnit\Framework\ExpectationFailedException;
use SebastianBergmann\Comparator\ComparisonFailure;
class AssertAdapter
{
public static function assertTrue(mixed $condition, string $message = ''): void
{
PHPUnit_Assert::assertTrue($condition, $message);
}
public static function assertFalse(mixed $condition, string $message = ''): void
{
PHPUnit_Assert::assertFalse($condition, $message);
}
public static function assertEquals(mixed $expected, mixed $actual, string $message = ''): void
{
PHPUnit_Assert::assertEquals($expected, $actual, $message);
}
public static function assertEqualsIgnoringCase(mixed $expected, mixed $actual, string $message = ''): void
{
PHPUnit_Assert::assertEqualsIgnoringCase($expected, $actual, $message);
}
public static function assertNotEquals(mixed $expected, mixed $actual, string $message = ''): void
{
PHPUnit_Assert::assertNotEquals($expected, $actual, $message);
}
public static function assertNull(mixed $actual, string $message = ''): void
{
PHPUnit_Assert::assertNull($actual, $message);
}
public static function assertNotNull(mixed $actual, string $message = ''): void
{
PHPUnit_Assert::assertNotNull($actual, $message);
}
public static function assertEmpty(mixed $actual, string $message = ''): void
{
PHPUnit_Assert::assertEmpty($actual, $message);
}
public static function assertNotEmpty(mixed $actual, string $message = ''): void
{
PHPUnit_Assert::assertNotEmpty($actual, $message);
}
public static function assertSame(mixed $expected, mixed $actual, string $message = ''): void
{
PHPUnit_Assert::assertSame($expected, $actual, $message);
}
public static function assertInstanceOf(mixed $expected, mixed $actual, string $message = ''): void
{
PHPUnit_Assert::assertInstanceOf($expected, $actual, $message);
}
public static function assertContains(mixed $needle, mixed $haystack, string $message = ''): void
{
PHPUnit_Assert::assertStringContainsString($needle, $haystack, $message);
}
public static function assertNotContains(mixed $needle, mixed $haystack, string $message = ''): void
{
PHPUnit_Assert::assertStringNotContainsString($needle, $haystack, $message);
}
public static function assertStringStartsWith(string $prefix, string $string, string $message = ''): void
{
PHPUnit_Assert::assertStringStartsWith($prefix, $string, $message);
}
public static function assertStringEndsWith(string $prefix, string $string, string $message = ''): void
{
PHPUnit_Assert::assertStringEndsWith($prefix, $string, $message);
}
public static function assertRegExp(string $pattern, string $string, string $message = ''): void
{
PHPUnit_Assert::assertMatchesRegularExpression($pattern, $string, $message);
}
public static function fail(string $message = ''): void
{
PHPUnit_Assert::fail($message);
}
public static function failWithDiff(string $description, mixed $expected, mixed $actual, string $expectedAsString, string $actualAsString): void
{
if (class_exists(ExpectationFailedException::class)) {
throw new ExpectationFailedException(
$description,
new ComparisonFailure($expected, $actual, $expectedAsString, $actualAsString)
);
} else {
throw new ExpectationFailedException(
$description,
new ComparisonFailure($expected, $actual, $expectedAsString, $actualAsString)
);
}
}
}