1 | <?php |
||
14 | class Assert |
||
15 | { |
||
16 | /** |
||
17 | * Fluent custom array assertion to simplify your tests. |
||
18 | * |
||
19 | * Sample usage: |
||
20 | * <code> |
||
21 | * $animals = array('cat', 'dog', 'pig'); |
||
22 | * Assert::thatArray($animals)->hasSize(3)->contains('cat'); |
||
23 | * Assert::thatArray($animals)->containsOnly('pig', 'dog', 'cat'); |
||
24 | * Assert::thatArray($animals)->containsExactly('cat', 'dog', 'pig'); |
||
25 | * Assert::thatArray(array('id' => 123, 'name' => 'john'))->containsKeyAndValue(array('id' => 123)); |
||
26 | * </code> |
||
27 | * |
||
28 | * @param array $actual |
||
29 | * @return ArrayAssert |
||
30 | */ |
||
31 | public static function thatArray(array $actual) |
||
32 | { |
||
33 | return ArrayAssert::that($actual); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Fluent custom model assertion to simplify your tests. |
||
38 | * |
||
39 | * Sample usage: |
||
40 | * <code> |
||
41 | * Assert::thatModel(new User(['name' => 'bob']))->hasSameAttributesAs(new User(['name' => 'bob'])); |
||
42 | * </code> |
||
43 | * |
||
44 | * @param Model $actual |
||
45 | * @return ModelAssert |
||
46 | */ |
||
47 | public static function thatModel(Model $actual) |
||
48 | { |
||
49 | return ModelAssert::that($actual); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Fluent custom session assertion to simplify your tests. |
||
54 | * |
||
55 | * Sample usage: |
||
56 | * <code> |
||
57 | * Session::push('key1', 'key2', 'value1'); |
||
58 | * Assert::thatSession()->hasSize(1)->contains('value1'); |
||
59 | * </code> |
||
60 | * |
||
61 | * Class Assert |
||
62 | * @package Ouzo\Tests |
||
63 | */ |
||
64 | public static function thatSession() |
||
65 | { |
||
66 | return ArrayAssert::that(isset($_SESSION) ? $_SESSION : array()); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Fluent custom string assertion to simplify your tests. |
||
71 | * |
||
72 | * Sample usage: |
||
73 | * <code> |
||
74 | * Assert::thatString("Frodo")->startsWith("Fro")->endsWith("do")->contains("rod")->doesNotContain("fro")->hasSize(5)->matches('/Fro\w+/'); |
||
75 | * </code> |
||
76 | * |
||
77 | * @param $string |
||
78 | * @return StringAssert |
||
79 | */ |
||
80 | public static function thatString($string) |
||
81 | { |
||
82 | return StringAssert::that($string); |
||
83 | } |
||
84 | } |
||
85 |