xref: /PHP-7.4/ext/spl/tests/dllist_005.phpt (revision ded3d984)
1--TEST--
2SPL: DoublyLinkedList: Queues
3--FILE--
4<?php
5$queue = new SplQueue();
6// errors
7try {
8    $queue->dequeue();
9} catch (RuntimeException $e) {
10    echo "Exception: ".$e->getMessage()."\n";
11}
12try {
13    $queue->shift();
14} catch (RuntimeException $e) {
15    echo "Exception: ".$e->getMessage()."\n";
16}
17
18// data consistency
19$a = 2;
20$queue->enqueue($a);
21echo $queue->dequeue()."\n";
22
23// peakable
24$queue->enqueue(1);
25$queue->enqueue(2);
26echo $queue->top()."\n";
27
28// iterable
29foreach ($queue as $elem) {
30    echo "[$elem]\n";
31}
32
33// countable
34$queue->enqueue(NULL);
35$queue->enqueue(NULL);
36echo count($queue)."\n";
37echo $queue->count()."\n";
38var_dump($queue->dequeue());
39var_dump($queue->dequeue());
40
41// clonable
42$queue->enqueue(2);
43$queue_clone = clone $queue;
44$queue_clone->dequeue();
45echo count($queue)."\n";
46?>
47===DONE===
48<?php exit(0); ?>
49--EXPECT--
50Exception: Can't shift from an empty datastructure
51Exception: Can't shift from an empty datastructure
522
532
54[1]
55[2]
564
574
58int(1)
59int(2)
603
61===DONE===
62