Repository navigation
Expand file tree
/
Copy pathCustomAssertionClassTest.php
More file actions
107 lines (93 loc) · 3.84 KB
/
Copy pathCustomAssertionClassTest.php
File metadata and controls
107 lines (93 loc) · 3.84 KB
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
<?php
/**
* Assert
*
* LICENSE
*
* This source file is subject to the MIT license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
namespace Assert\Tests;
use Assert\LazyAssertionException;
use Assert\Tests\Fixtures\CustomAssertion;
use PHPUnit\Framework\TestCase;
class CustomAssertionClassTest extends TestCase
{
/** @before */
protected function setUpBefore()
{
CustomAssertion::clearCalls();
}
public function testThatCustomAssertionUsesCustomException()
{
$this->expectException('Assert\Tests\Fixtures\CustomException');
CustomAssertion::integer('foo');
}
public function testThatCustomAssertionsUsesCustomExceptionForAssertionChains()
{
$this->expectException('Assert\Tests\Fixtures\CustomException');
$string = 's'.\uniqid();
Fixtures\CustomAssert::that($string)->string();
$this->assertSame([['string', $string]], CustomAssertion::getCalls());
Fixtures\CustomAssert::that($string)->integer();
}
public function testThatCustomAssertionsUsesCustomAssertionExceptionForLazyAssertionChains()
{
$this->expectException('Assert\Tests\Fixtures\CustomLazyAssertionException');
Fixtures\CustomAssert::lazy()
->that('foo', 'foo')->integer()
->verifyNow();
}
public function testThatCustomAssertionsUsesCustomAssertionExceptionWhenFirstAssertionDoesNotFail()
{
$this->expectException('Assert\Tests\Fixtures\CustomLazyAssertionException');
Fixtures\CustomAssert::lazy()
->that('foo', 'foo')->string()
->that('bar', 'bar')->integer()
->verifyNow();
}
public function testThatCustomLazyAssertionUsesCustomAssertion()
{
$string = 's'.\uniqid();
Fixtures\CustomAssert::lazy()
->that($string, 'foo')->string()
->verifyNow();
$this->assertSame([['string', $string]], CustomAssertion::getCalls());
}
public function testThatCustomLazyAssertionContainsOnlyCustomAssertionExceptions()
{
try {
Fixtures\CustomAssert::lazy()
->that('foo', 'foo')->integer()
->verifyNow();
} catch (LazyAssertionException $ex) {
$this->assertContainsOnlyInstancesOf(Fixtures\CustomException::class, $ex->getErrorExceptions());
}
}
/**
* @expectedExceptionMessageRegex /The following 4 assertions failed:\s+1) foo: Value "foo" is not an integer.\s+2) foo: Value "foo" is not an array.\s+3) bar: Value "123" expected to be string, type integer given.\s+4) bar: Value "123" is not an array./
*/
public function testThatCustomAssertionsExceptionsForLazyAssertionChainsTryAllTheAssertionsPerChain()
{
$this->expectException('Assert\Tests\Fixtures\CustomLazyAssertionException');
Fixtures\CustomAssert::lazy()
->that('foo', 'foo')->tryAll()->integer()->isArray()
->that(123, 'bar')->tryAll()->string()->isArray()
->verifyNow();
}
/**
* @expectedExceptionMessageRegex /The following 4 assertions failed:\s+1) foo: Value "foo" is not an integer.\s+2) foo: Value "foo" is not an array.\s+3) bar: Value "123" expected to be string, type integer given.\s+4) bar: Value "123" is not an array./
*/
public function testThatCustomAssertionsExceptionsForLazyAssertionChainsTryAllTheAssertions()
{
$this->expectException('Assert\Tests\Fixtures\CustomLazyAssertionException');
Fixtures\CustomAssert::lazy()
->tryAll()
->that('foo', 'foo')->integer()->isArray()
->that(123, 'bar')->string()->isArray()
->verifyNow();
}
}