-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathAssertionChainFunctionsTest.php
More file actions
89 lines (76 loc) · 2.68 KB
/
AssertionChainFunctionsTest.php
File metadata and controls
89 lines (76 loc) · 2.68 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
<?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\AssertionChain;
use PHPUnit\Framework\TestCase;
/**
* Test case specific for the deprecated functions creating assertion chains.
*/
class AssertionChainFunctionsTest extends TestCase
{
public function testThatAssertionChainFunctionsReturnAnAssertionChain()
{
$this->assertInstanceOf(AssertionChain::class, \Assert\that(10)->notEmpty()->integer());
}
public function testThatAssertionChainFunctionsShiftsArgumentsBy1()
{
$this->assertInstanceOf(AssertionChain::class, \Assert\that(10)->eq(10));
}
/**
* @expectedException \Assert\InvalidArgumentException
* @expectedExceptionMessage Not Null and such
*/
public function testThatAssertionChainFunctionsKnowsDefaultErrorMessage()
{
\Assert\that(null, 'Not Null and such')->notEmpty();
}
public function testThatAssertionChainFunctionsSkipAssertionsOnValidNull()
{
$this->assertInstanceOf(AssertionChain::class, \Assert\that(null)->nullOr()->integer()->eq(10));
}
public function testThatAssertionChainFunctionsValidatesAllInputs()
{
$this->assertInstanceOf(AssertionChain::class, \Assert\that([1, 2, 3])->all()->integer());
}
public function testThatAssertionChainFunctionsValidateNegativeAssertions()
{
$this->assertInstanceOf(AssertionChain::class, \Assert\that('foo')->not()->isInstanceOf(\stdClass::class));
}
public function testAssertionChainFunctionsThatAllShortcut()
{
$this->assertInstanceOf(AssertionChain::class, \Assert\thatAll([1, 2, 3])->integer());
}
public function testAssertionChainFunctionsNullOrShortcut()
{
$this->assertInstanceOf(AssertionChain::class, \Assert\thatNullOr(null)->integer()->eq(10));
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Assertion 'unknownAssertion' does not exist.
*/
public function testThatAssertionChainFunctionsThrowsExceptionForUnknownAssertion()
{
\Assert\that(null)->unknownAssertion();
}
public function testAssertionChainFunctionSatisfyShortcut()
{
$this->assertInstanceOf(
AssertionChain::class,
\Assert\that(null)->satisfy(
function ($value) {
return \is_null($value);
}
)
);
}
}