xref: /PHP-8.2/ext/spl/tests/dllist_005.phpt (revision a555cc0b)
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--EXPECT--
48Exception: Can't shift from an empty datastructure
49Exception: Can't shift from an empty datastructure
502
512
52[1]
53[2]
544
554
56int(1)
57int(2)
583
59