Skip to content

Commit 0f40186

Browse files
committed
Cleanup
1 parent ebe4e8f commit 0f40186

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

src/types/iterator.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ impl<'a> FromZvalMut<'a> for &'a mut ZendIterator {
186186
#[cfg(feature = "embed")]
187187
mod tests {
188188
use crate::embed::Embed;
189-
use crate::types::iterator::IterKey;
190189

191190
#[test]
192191
fn test_generator() {
@@ -212,22 +211,27 @@ mod tests {
212211

213212
let (key, value) = iter.next().unwrap();
214213

215-
assert_eq!(key, IterKey::Long(0));
214+
assert_eq!(key.long(), Some(0));
216215
assert!(value.is_long());
217216
assert_eq!(value.long().unwrap(), 1);
218217

219218
let (key, value) = iter.next().unwrap();
220219

221-
assert_eq!(key, IterKey::Long(1));
220+
assert_eq!(key.long(), Some(1));
222221
assert!(value.is_long());
223222
assert_eq!(value.long().unwrap(), 2);
224223

225224
let (key, value) = iter.next().unwrap();
226225

227-
assert_eq!(key, IterKey::Long(2));
226+
assert_eq!(key.long(), Some(2));
228227
assert!(value.is_long());
229228
assert_eq!(value.long().unwrap(), 3);
230229

230+
let (key, value) = iter.next().unwrap();
231+
232+
assert!(key.is_object());
233+
assert!(value.is_object());
234+
231235
let next = iter.next();
232236

233237
assert!(next.is_none());
@@ -260,23 +264,28 @@ mod tests {
260264
let (key, value) = iter.next().unwrap();
261265

262266
assert!(!key.is_long());
263-
assert_eq!(key, IterKey::String("key".to_string()));
267+
assert_eq!(key.str(), Some("key"));
264268
assert!(value.is_string());
265-
assert_eq!(value.string().unwrap(), "foo");
269+
assert_eq!(value.str(), Some("foo"));
266270

267271
let (key, value) = iter.next().unwrap();
268272

269273
assert!(key.is_long());
270-
assert_eq!(key, IterKey::Long(10));
274+
assert_eq!(key.long(), Some(10));
271275
assert!(value.is_string());
272276
assert_eq!(value.string().unwrap(), "bar");
273277

274278
let (key, value) = iter.next().unwrap();
275279

276-
assert_eq!(key, IterKey::Long(2));
280+
assert_eq!(key.long(), Some(2));
277281
assert!(value.is_string());
278282
assert_eq!(value.string().unwrap(), "baz");
279283

284+
let (key, value) = iter.next().unwrap();
285+
286+
assert!(key.is_object());
287+
assert!(value.is_object());
288+
280289
let next = iter.next();
281290

282291
assert!(next.is_none());
@@ -288,22 +297,27 @@ mod tests {
288297

289298
let (key, value) = iter.next().unwrap();
290299

291-
assert_eq!(key, IterKey::String("key".to_string()));
300+
assert_eq!(key.str(), Some("key"));
292301
assert!(value.is_string());
293302
assert_eq!(value.string().unwrap(), "foo");
294303

295304
let (key, value) = iter.next().unwrap();
296305

297-
assert_eq!(key, IterKey::Long(10));
306+
assert_eq!(key.long(), Some(10));
298307
assert!(value.is_string());
299308
assert_eq!(value.string().unwrap(), "bar");
300309

301310
let (key, value) = iter.next().unwrap();
302311

303-
assert_eq!(key, IterKey::Long(2));
312+
assert_eq!(key.long(), Some(2));
304313
assert!(value.is_string());
305314
assert_eq!(value.string().unwrap(), "baz");
306315

316+
let (key, value) = iter.next().unwrap();
317+
318+
assert!(key.is_object());
319+
assert!(value.is_object());
320+
307321
let next = iter.next();
308322

309323
assert!(next.is_none());

src/types/iterator.test.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ function create_generator() {
44
yield 1;
55
yield 2;
66
yield 3;
7-
yield new class {};
7+
yield new class {} => new class {};
88
}
99

1010
class TestIterator implements \Iterator {
1111
private $count = 0;
1212

13-
public function current()
13+
public function current(): mixed
1414
{
1515
return match ($this->count) {
1616
0 => 'foo',
@@ -21,12 +21,12 @@ public function current()
2121
};
2222
}
2323

24-
public function next()
24+
public function next(): void
2525
{
2626
$this->count++;
2727
}
2828

29-
public function key()
29+
public function key(): mixed
3030
{
3131
return match ($this->count) {
3232
0 => 'key',
@@ -37,12 +37,12 @@ public function key()
3737
};
3838
}
3939

40-
public function valid()
40+
public function valid(): bool
4141
{
42-
return $this->count < 3;
42+
return $this->count < 4;
4343
}
4444

45-
public function rewind()
45+
public function rewind(): void
4646
{
4747
$this->count = 0;
4848
}

0 commit comments

Comments
 (0)