Completed
Pull Request — master (#184)
by
unknown
01:50
created

CustomAssertion::string()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
1
<?php
2
/**
3
 * Assert
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the MIT license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * If you did not receive a copy of the license and are unable to
10
 * obtain it through the world-wide-web, please send an email
11
 * to [email protected] so I can send you a copy immediately.
12
 */
13
14
namespace Assert\Tests;
15
16
use Assert\Assert;
17
use Assert\Assertion;
18
use Assert\InvalidArgumentException;
19
use Assert\LazyAssertionException;
20
21
class CustomAssertionClassTest extends \PHPUnit_Framework_TestCase
22
{
23
    protected function setUp()
24
    {
25
        CustomAssertion::clearCalls();
26
    }
27
28
    /**
29
     * @test
30
     */
31
    public function it_uses_custom_exception_class()
0 ignored issues
show
Coding Style introduced by
Method name "CustomAssertionClassTest::it_uses_custom_exception_class" is not in camel caps format
Loading history...
32
    {
33
        $this->setExpectedException(CustomException::class);
34
        CustomAssertion::integer('foo');
35
    }
36
37
    /**
38
     * @test
39
     */
40
    public function it_uses_custom_assertion_class_for_assertion_chains()
0 ignored issues
show
Coding Style introduced by
Method name "CustomAssertionClassTest::it_uses_custom_assertion_class_for_assertion_chains" is not in camel caps format
Loading history...
41
    {
42
        $string = 's' . uniqid();
43
        CustomAssert::that($string)->string();
44
        $this->assertSame([['string', $string]], CustomAssertion::getCalls());
45
46
        $this->setExpectedException(CustomException::class);
47
        CustomAssert::that($string)->integer();
48
    }
49
50
    /**
51
     * @test
52
     */
53
    public function it_uses_custom_exception_for_lazy_assertion_chains()
0 ignored issues
show
Coding Style introduced by
Method name "CustomAssertionClassTest::it_uses_custom_exception_for_lazy_assertion_chains" is not in camel caps format
Loading history...
54
    {
55
        $this->setExpectedException(CustomLazyAssertionException::class);
56
        CustomAssert::lazy()
57
            ->that('foo', 'foo')->integer()
58
            ->verifyNow()
59
        ;
60
    }
61
62
    /**
63
     * @test
64
     */
65
    public function it_uses_custom_exception_for_lazy_assertion_chains_when_first_assertion_does_not_fail()
0 ignored issues
show
Coding Style introduced by
Method name "CustomAssertionClassTest::it_uses_custom_exception_for_lazy_assertion_chains_when_first_assertion_does_not_fail" is not in camel caps format
Loading history...
66
    {
67
        $this->setExpectedException(CustomLazyAssertionException::class);
68
        CustomAssert::lazy()
69
            ->that('foo', 'foo')->string()
70
            ->that('bar', 'bar')->integer()
71
            ->verifyNow()
72
        ;
73
    }
74
}
75
76
class CustomException extends InvalidArgumentException
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
77
{
78
}
79
80
class CustomLazyAssertionException extends LazyAssertionException
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
81
{
82
}
83
84
class CustomAssertion extends Assertion
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
85
{
86
    protected static $exceptionClass = CustomException::class;
87
    private static $calls = [];
88
89
    public static function clearCalls()
90
    {
91
        self::$calls = [];
92
    }
93
94
    public static function getCalls()
95
    {
96
        return self::$calls;
97
    }
98
99
    public static function string($value, $message = null, $propertyPath = null)
100
    {
101
        self::$calls[] = ['string', $value];
102
        return parent::string($value, $message, $propertyPath);
103
    }
104
}
105
106
class CustomAssert extends Assert
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
107
{
108
    protected static $assertionClass = CustomAssertion::class;
109
    protected static $lazyAssertionExceptionClass = CustomLazyAssertionException::class;
110
}
111