1 | <?php |
||
8 | class PEMBundleTest extends PHPUnit_Framework_TestCase |
||
9 | { |
||
10 | /** |
||
11 | * |
||
12 | * @return PEMBundle |
||
13 | */ |
||
14 | public function testBundle() |
||
15 | { |
||
16 | $bundle = PEMBundle::fromFile(TEST_ASSETS_DIR . "/cacert.pem"); |
||
17 | $this->assertInstanceOf(PEMBundle::class, $bundle); |
||
18 | return $bundle; |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * @depends testBundle |
||
23 | * |
||
24 | * @param PEMBundle $bundle |
||
25 | */ |
||
26 | public function testAll(PEMBundle $bundle) |
||
27 | { |
||
28 | $this->assertContainsOnlyInstancesOf(PEM::class, $bundle->all()); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @depends testBundle |
||
33 | * |
||
34 | * @param PEMBundle $bundle |
||
35 | */ |
||
36 | public function testFirst(PEMBundle $bundle) |
||
37 | { |
||
38 | $this->assertInstanceOf(PEM::class, $bundle->first()); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @depends testBundle |
||
43 | * |
||
44 | * @param PEMBundle $bundle |
||
45 | */ |
||
46 | public function testCount(PEMBundle $bundle) |
||
47 | { |
||
48 | $this->assertCount(150, $bundle); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @depends testBundle |
||
53 | * |
||
54 | * @param PEMBundle $bundle |
||
55 | */ |
||
56 | public function testIterator(PEMBundle $bundle) |
||
57 | { |
||
58 | $values = array(); |
||
59 | foreach ($bundle as $pem) { |
||
60 | $values[] = $pem; |
||
61 | } |
||
62 | $this->assertContainsOnlyInstancesOf(PEM::class, $values); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @depends testBundle |
||
67 | * |
||
68 | * @param PEMBundle $bundle |
||
69 | */ |
||
70 | public function testString(PEMBundle $bundle) |
||
71 | { |
||
72 | $this->assertInternalType("string", $bundle->string()); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @depends testBundle |
||
77 | * |
||
78 | * @param PEMBundle $bundle |
||
79 | */ |
||
80 | public function testToString(PEMBundle $bundle) |
||
81 | { |
||
82 | $this->assertInternalType("string", strval($bundle)); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @expectedException UnexpectedValueException |
||
87 | */ |
||
88 | public function testInvalidPEM() |
||
89 | { |
||
90 | PEMBundle::fromString("invalid"); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @expectedException UnexpectedValueException |
||
95 | */ |
||
96 | public function testInvalidPEMData() |
||
97 | { |
||
98 | $str = <<<DATA |
||
99 | -----BEGIN TEST----- |
||
100 | %%% |
||
101 | -----END TEST----- |
||
102 | DATA; |
||
103 | PEMBundle::fromString($str); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @expectedException RuntimeException |
||
108 | */ |
||
109 | public function testInvalidFile() |
||
110 | { |
||
111 | PEMBundle::fromFile(TEST_ASSETS_DIR . "/nonexistent"); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @expectedException LogicException |
||
116 | */ |
||
117 | public function testFirstEmptyFail() |
||
118 | { |
||
119 | $bundle = new PEMBundle(); |
||
120 | $bundle->first(); |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * @depends testBundle |
||
125 | * |
||
126 | * @param PEMBundle $bundle |
||
127 | */ |
||
128 | public function testWithPEMs(PEMBundle $bundle) |
||
129 | { |
||
130 | $bundle = $bundle->withPEMs(new PEM("TEST", "data")); |
||
131 | $this->assertCount(151, $bundle); |
||
132 | } |
||
133 | } |
||
134 |