File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,21 @@ public function first(): PEM
120
120
return $ this ->_pems [0 ];
121
121
}
122
122
123
+ /**
124
+ * Get the last PEM in a bundle.
125
+ *
126
+ * @throws \LogicException If bundle contains no PEM objects
127
+ *
128
+ * @return PEM
129
+ */
130
+ public function last (): PEM
131
+ {
132
+ if (!count ($ this ->_pems )) {
133
+ throw new \LogicException ('No PEMs. ' );
134
+ }
135
+ return $ this ->_pems [count ($ this ->_pems ) - 1 ];
136
+ }
137
+
123
138
/**
124
139
* @see \Countable::count()
125
140
*
Original file line number Diff line number Diff line change @@ -41,6 +41,18 @@ public function testAll(PEMBundle $bundle)
41
41
public function testFirst (PEMBundle $ bundle )
42
42
{
43
43
$ this ->assertInstanceOf (PEM ::class, $ bundle ->first ());
44
+ $ this ->assertEquals ($ bundle ->all ()[0 ], $ bundle ->first ());
45
+ }
46
+
47
+ /**
48
+ * @depends testBundle
49
+ *
50
+ * @param PEMBundle $bundle
51
+ */
52
+ public function testLast (PEMBundle $ bundle )
53
+ {
54
+ $ this ->assertInstanceOf (PEM ::class, $ bundle ->last ());
55
+ $ this ->assertEquals ($ bundle ->all ()[149 ], $ bundle ->last ());
44
56
}
45
57
46
58
/**
@@ -117,6 +129,13 @@ public function testFirstEmptyFail()
117
129
$ bundle ->first ();
118
130
}
119
131
132
+ public function testLastEmptyFail ()
133
+ {
134
+ $ bundle = new PEMBundle ();
135
+ $ this ->expectException (LogicException::class);
136
+ $ bundle ->last ();
137
+ }
138
+
120
139
/**
121
140
* @depends testBundle
122
141
*
You can’t perform that action at this time.
0 commit comments