Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 5d95fa1

Browse files
committed
Merge branch 'hotfix/39' into develop
Forward port #39
2 parents 887d36e + 965f6d6 commit 5d95fa1

9 files changed

+51
-90
lines changed

src/Parameters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function toArray()
7070
*/
7171
public function toString()
7272
{
73-
return http_build_query($this);
73+
return http_build_query($this->toArray());
7474
}
7575

7676
/**

test/FastPriorityQueueTest.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@
99

1010
namespace ZendTest\Stdlib;
1111

12+
use Zend\Stdlib\Exception\InvalidArgumentException;
1213
use Zend\Stdlib\FastPriorityQueue;
1314

1415
/**
1516
* @group Zend_Stdlib
1617
*/
1718
class FastPriorityQueueTest extends \PHPUnit_Framework_TestCase
1819
{
20+
/**
21+
* @var FastPriorityQueue
22+
*/
23+
protected $queue;
24+
25+
/**
26+
* @var string[]
27+
*/
28+
protected $expected;
29+
1930
public function setUp()
2031
{
2132
$this->queue = new FastPriorityQueue();
@@ -42,7 +53,7 @@ protected function getDataPriorityQueue()
4253
];
4354
}
4455

45-
protected function insertDataQueue($queue)
56+
protected function insertDataQueue(FastPriorityQueue $queue)
4657
{
4758
foreach ($this->getDataPriorityQueue() as $value => $priority) {
4859
$queue->insert($value, $priority);
@@ -117,17 +128,7 @@ public function testCanRetrieveQueueAsArray()
117128

118129
public function testIteratorFunctions()
119130
{
120-
$this->queue->rewind();
121-
122-
$i = 0;
123-
while ($this->queue->valid()) {
124-
$key = $this->queue->key();
125-
$value = $this->queue->current();
126-
$this->assertEquals($this->expected[$i], $value);
127-
$this->queue->next();
128-
++$i;
129-
}
130-
$this->assertFalse($this->queue->valid());
131+
$this->assertEquals($this->expected, iterator_to_array($this->queue));
131132
}
132133

133134
public function testRewindOperation()
@@ -154,11 +155,9 @@ public function testSetExtractFlag()
154155
$this->assertEquals($expected, $this->queue->extract());
155156
}
156157

157-
/**
158-
* @expectedException Zend\Stdlib\Exception\InvalidArgumentException
159-
*/
160158
public function testSetInvalidExtractFlag()
161159
{
160+
$this->setExpectedException(InvalidArgumentException::class, 'The extract flag specified is not valid');
162161
$this->queue->setExtractFlags('foo');
163162
}
164163

@@ -232,11 +231,7 @@ public function testRewindShouldNotRaiseErrorWhenQueueIsEmpty()
232231
$queue = new FastPriorityQueue();
233232
$this->assertTrue($queue->isEmpty());
234233

235-
set_error_handler(function ($errno, $errstr) {
236-
$this->fail(sprintf('Error was raised by rewind() operation: %s', $errstr));
237-
}, E_WARNING);
238234
$queue->rewind();
239-
restore_error_handler();
240235
}
241236

242237
public function testRemoveShouldFindItemEvenIfMultipleItemsAreInQueue()

test/PriorityListTest.php

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ public function testLIFOOnly()
101101
$this->list->insert('foobar', new \stdClass());
102102
$this->list->insert('barbaz', new \stdClass());
103103

104-
$orders = [];
105-
106-
foreach ($this->list as $key => $value) {
107-
$orders[] = $key;
108-
}
104+
$orders = array_keys(iterator_to_array($this->list));
109105

110106
$this->assertEquals(['barbaz', 'foobar', 'baz', 'bar', 'foo'], $orders);
111107
}
@@ -116,11 +112,7 @@ public function testPriorityOnly()
116112
$this->list->insert('bar', new \stdClass(), 0);
117113
$this->list->insert('baz', new \stdClass(), 2);
118114

119-
$order = [];
120-
121-
foreach ($this->list as $key => $value) {
122-
$orders[] = $key;
123-
}
115+
$orders = array_keys(iterator_to_array($this->list));
124116

125117
$this->assertEquals(['baz', 'foo', 'bar'], $orders);
126118
}
@@ -131,11 +123,7 @@ public function testLIFOWithPriority()
131123
$this->list->insert('bar', new \stdClass(), 0);
132124
$this->list->insert('baz', new \stdClass(), 1);
133125

134-
$orders = [];
135-
136-
foreach ($this->list as $key => $value) {
137-
$orders[] = $key;
138-
}
126+
$orders = array_keys(iterator_to_array($this->list));
139127

140128
$this->assertEquals(['baz', 'bar', 'foo'], $orders);
141129
}
@@ -147,11 +135,7 @@ public function testFIFOWithPriority()
147135
$this->list->insert('bar', new \stdClass(), 0);
148136
$this->list->insert('baz', new \stdClass(), 1);
149137

150-
$orders = [];
151-
152-
foreach ($this->list as $key => $value) {
153-
$orders[] = $key;
154-
}
138+
$orders = array_keys(iterator_to_array($this->list));
155139

156140
$this->assertEquals(['baz', 'foo', 'bar'], $orders);
157141
}
@@ -165,11 +149,7 @@ public function testFIFOOnly()
165149
$this->list->insert('foobar', new \stdClass());
166150
$this->list->insert('barbaz', new \stdClass());
167151

168-
$orders = [];
169-
170-
foreach ($this->list as $key => $value) {
171-
$orders[] = $key;
172-
}
152+
$orders = array_keys(iterator_to_array($this->list));
173153

174154
$this->assertEquals(['foo', 'bar', 'baz', 'foobar', 'barbaz'], $orders);
175155
}
@@ -180,11 +160,7 @@ public function testPriorityWithNegativesAndNull()
180160
$this->list->insert('bar', new \stdClass(), 1);
181161
$this->list->insert('baz', new \stdClass(), -1);
182162

183-
$orders = [];
184-
185-
foreach ($this->list as $key => $value) {
186-
$orders[] = $key;
187-
}
163+
$orders = array_keys(iterator_to_array($this->list));
188164

189165
$this->assertEquals(['bar', 'foo', 'baz'], $orders);
190166
}

test/PriorityQueueTest.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,8 @@ public function testSerializationAndDeserializationShouldMaintainState()
3737
$count = count($this->queue);
3838
$this->assertSame($count, count($unserialized), 'Expected count ' . $count . '; received ' . count($unserialized));
3939

40-
$expected = [];
41-
foreach ($this->queue as $item) {
42-
$expected[] = $item;
43-
}
44-
$test = [];
45-
foreach ($unserialized as $item) {
46-
$test[] = $item;
47-
}
40+
$expected = iterator_to_array($this->queue);
41+
$test = iterator_to_array($unserialized);
4842
$this->assertSame($expected, $test, 'Expected: ' . var_export($expected, 1) . "\nReceived:" . var_export($test, 1));
4943
}
5044

@@ -101,10 +95,7 @@ public function testCanRemoveItemFromQueue()
10195
{
10296
$this->queue->remove('baz');
10397
$expected = ['bar', 'foo', 'bat'];
104-
$test = [];
105-
foreach ($this->queue as $item) {
106-
$test[] = $item;
107-
}
98+
$test = array_values(iterator_to_array($this->queue));
10899
$this->assertEquals($expected, $test);
109100
}
110101

test/SplPriorityQueueTest.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
*/
1717
class SplPriorityQueueTest extends \PHPUnit_Framework_TestCase
1818
{
19+
/**
20+
* @var SplPriorityQueue
21+
*/
22+
protected $queue;
23+
1924
public function setUp()
2025
{
2126
$this->queue = new SplPriorityQueue();
@@ -34,10 +39,7 @@ public function testMaintainsInsertOrderForDataOfEqualPriority()
3439
$queue->insert('bat', 1000);
3540

3641
$expected = ['foo', 'bar', 'baz', 'bat'];
37-
$test = [];
38-
foreach ($queue as $datum) {
39-
$test[] = $datum;
40-
}
42+
$test = array_values(iterator_to_array($queue));
4143
$this->assertEquals($expected, $test);
4244
}
4345

@@ -48,14 +50,8 @@ public function testSerializationAndDeserializationShouldMaintainState()
4850
$count = count($this->queue);
4951
$this->assertSame($count, count($unserialized), 'Expected count ' . $count . '; received ' . count($unserialized));
5052

51-
$expected = [];
52-
foreach ($this->queue as $item) {
53-
$expected[] = $item;
54-
}
55-
$test = [];
56-
foreach ($unserialized as $item) {
57-
$test[] = $item;
58-
}
53+
$expected = iterator_to_array($this->queue);
54+
$test = iterator_to_array($unserialized);
5955
$this->assertSame($expected, $test, 'Expected: ' . var_export($expected, 1) . "\nReceived:" . var_export($test, 1));
6056
}
6157

test/SplQueueTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
*/
1717
class SplQueueTest extends \PHPUnit_Framework_TestCase
1818
{
19+
/**
20+
* @var SplQueue
21+
*/
22+
protected $queue;
23+
1924
public function setUp()
2025
{
2126
$this->queue = new SplQueue();
@@ -31,14 +36,8 @@ public function testSerializationAndDeserializationShouldMaintainState()
3136
$count = count($this->queue);
3237
$this->assertSame($count, count($unserialized));
3338

34-
$expected = [];
35-
foreach ($this->queue as $item) {
36-
$expected[] = $item;
37-
}
38-
$test = [];
39-
foreach ($unserialized as $item) {
40-
$test[] = $item;
41-
}
39+
$expected = iterator_to_array($this->queue);
40+
$test = iterator_to_array($unserialized);
4241
$this->assertSame($expected, $test);
4342
}
4443

test/SplStackTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
*/
1717
class SplStackTest extends \PHPUnit_Framework_TestCase
1818
{
19+
/**
20+
* @var SplStack
21+
*/
22+
protected $stack;
23+
1924
public function setUp()
2025
{
2126
$this->stack = new SplStack();
@@ -32,14 +37,8 @@ public function testSerializationAndDeserializationShouldMaintainState()
3237
$count = count($this->stack);
3338
$this->assertSame($count, count($unserialized));
3439

35-
$expected = [];
36-
foreach ($this->stack as $item) {
37-
$expected[] = $item;
38-
}
39-
$test = [];
40-
foreach ($unserialized as $item) {
41-
$test[] = $item;
42-
}
40+
$expected = iterator_to_array($this->stack);
41+
$test = iterator_to_array($unserialized);
4342
$this->assertSame($expected, $test);
4443
}
4544

test/StringUtilsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace ZendTest\Stdlib;
1111

12+
use Exception;
1213
use PHPUnit_Framework_TestCase as TestCase;
1314
use Zend\Stdlib\ErrorHandler;
1415
use Zend\Stdlib\StringUtils;

test/StringWrapper/CommonStringWrapperTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
namespace ZendTest\Stdlib\StringWrapper;
1111

1212
use PHPUnit_Framework_TestCase as TestCase;
13+
use Zend\Stdlib\StringWrapper\StringWrapperInterface;
1314

1415
abstract class CommonStringWrapperTest extends TestCase
1516
{
17+
/**
18+
* @return StringWrapperInterface
19+
*/
1620
abstract protected function getWrapper($encoding = null, $convertEncoding = null);
1721

1822
public function strlenProvider()

0 commit comments

Comments
 (0)