This repository was archived by the owner on Dec 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathSetIndexTest.php
More file actions
73 lines (56 loc) · 1.97 KB
/
SetIndexTest.php
File metadata and controls
73 lines (56 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace Pinq\Tests\Integration\Collection;
class SetIndexTest extends CollectionTest
{
/**
* @dataProvider everything
*/
public function testThatSettingAnIndexWillOverrideTheElementInTheCollection(\Pinq\ICollection $collection, array $data)
{
reset($data);
$key = key($data);
if ($key === null) {
return;
}
$instance = new \stdClass();
$collection[$key] = $instance;
$data[$key] = $instance;
$this->assertMatches($collection, $data);
}
/**
* @dataProvider emptyData
*/
public function testThatSetIndexWithNoKeyAppendsTheValueWithTheNextLargestIntGreaterThanOrEqualToZeroLikeAnArray(\Pinq\ICollection $collection, array $data)
{
$collection->clear();
$collection[-5] = 'foo';
$collection[] = 'bar';
$collection[7] = 'baz';
$collection[] = 'qux';
$this->assertSame('foo', $collection[-5]);
$this->assertSame('bar', $collection[0]);
$this->assertSame('baz', $collection[7]);
$this->assertSame('qux', $collection[8]);
unset($collection[8]);
$this->assertFalse(isset($collection[8]));
$collection[] = 'qux1';
$this->assertSame('qux1', $collection[8]);
unset($collection[8], $collection[7]);
$collection[] = 'boo';
$this->assertSame('boo', $collection[1]);
}
/**
* @dataProvider emptyData
*/
public function testThatDateTimeIndexesAreComparedByValue(\Pinq\ICollection $collection, array $data)
{
$dateTime = new \DateTime('2-1-2001');
$anotherDateTime = new \DateTime('2-1-2000');
$collection[$dateTime] = 1;
$collection[$anotherDateTime] = 2;
$collection[clone $anotherDateTime] = 3;
$this->assertSame(1, $collection[$dateTime]);
$this->assertSame(3, $collection[$anotherDateTime]);
$this->assertSame(3, $collection[clone $anotherDateTime]);
}
}