Skip to content

Commit d5b8a72

Browse files
committed
test: fix tests as per new structures
1 parent 4af6bb2 commit d5b8a72

File tree

5 files changed

+84
-88
lines changed

5 files changed

+84
-88
lines changed

tests/UnderscoreArrayTest.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@
22

33
namespace Ahc\Underscore\Tests;
44

5-
use Ahc\Underscore\UnderscoreArray as _;
5+
use Ahc\Underscore\Underscore as _;
66

77
class UnderscoreArrayTest extends \PHPUnit_Framework_TestCase
88
{
99
public function test_first_last()
1010
{
1111
$array = range(rand(5, 10), rand(15, 20));
1212

13-
$this->assertSame($array[0], _::_($array)->first(), 'first');
14-
$this->assertSame(array_reverse($array)[0], _::_($array)->last(), 'last');
13+
$this->assertSame($array[0], underscore($array)->first(), 'first');
14+
$this->assertSame(array_reverse($array)[0], underscore($array)->last(), 'last');
1515

1616
$array = ['x' => ['first'], 'z' => 'last'];
1717

18-
$this->assertSame($array['x'], _::_($array)->head(), 'first');
19-
$this->assertSame($array['z'], _::_($array)->tail(), 'last');
18+
$this->assertSame($array['x'], underscore($array)->head(), 'first');
19+
$this->assertSame($array['z'], underscore($array)->tail(), 'last');
2020

2121
$array = range(1, 5);
2222

23-
$this->assertSame([1, 2, 3], _::_($array)->take(3), 'first 3');
24-
$this->assertSame([1, 2, 3, 4, 5], _::_($array)->first(6), 'first 6 (n + 1)');
25-
$this->assertSame([2 => 3, 3 => 4, 4 => 5], _::_($array)->drop(3), 'last 3');
26-
$this->assertSame([1, 2, 3, 4, 5], _::_($array)->last(6), 'last 6 (n + 1)');
23+
$this->assertSame([1, 2, 3], underscore($array)->take(3), 'first 3');
24+
$this->assertSame([1, 2, 3, 4, 5], underscore($array)->first(6), 'first 6 (n + 1)');
25+
$this->assertSame([2 => 3, 3 => 4, 4 => 5], underscore($array)->drop(3), 'last 3');
26+
$this->assertSame([1, 2, 3, 4, 5], underscore($array)->last(6), 'last 6 (n + 1)');
2727
}
2828

2929
public function test_compact()
3030
{
3131
$array = [0, 'a', '', [], 2, [1]];
3232

33-
$this->assertSame([1 => 'a', 4 => 2, 5 => [1]], _::_($array)->compact()->get(), 'first');
33+
$this->assertSame([1 => 'a', 4 => 2, 5 => [1]], underscore($array)->compact()->get(), 'first');
3434
}
3535

3636
public function test_flatten()
@@ -39,7 +39,7 @@ public function test_flatten()
3939

4040
$this->assertSame(
4141
[0, 'a', '', 1, 2, 'b', 3, 4, 'c', 5, 'd'],
42-
_::_($array)->flatten()->get(),
42+
underscore($array)->flatten()->get(),
4343
'flatten'
4444
);
4545
}
@@ -50,15 +50,15 @@ public function test_unique_uniq()
5050

5151
$this->assertSame(
5252
[0, 'a', '', 1, 6 => 2, 8 => 3],
53-
_::_($array)->unique()->get(),
53+
underscore($array)->unique()->get(),
5454
'unique'
5555
);
5656

5757
$array = ['a', '', 'a', 1, '', 0, 1, 'b', 3, 2];
5858

5959
$this->assertSame(
6060
['a', '', 3 => 1, 5 => 0, 7 => 'b', 8 => 3, 9 => 2],
61-
_::_($array)->uniq(function ($i) {
61+
underscore($array)->uniq(function ($i) {
6262
return $i;
6363
})->get(),
6464
'uniq'
@@ -71,13 +71,13 @@ public function test_difference_without()
7171

7272
$this->assertSame(
7373
[1 => 2, 'a' => 3],
74-
_::_($array)->difference([1, [4]])->get(),
74+
underscore($array)->difference([1, [4]])->get(),
7575
'difference'
7676
);
7777

7878
$this->assertSame(
7979
['a' => 3, 'b' => [4]],
80-
_::_($array)->without([1, 2])->get(),
80+
underscore($array)->without([1, 2])->get(),
8181
'without'
8282
);
8383
}
@@ -88,7 +88,7 @@ public function test_union()
8888

8989
$this->assertSame(
9090
[1, 2, 'a' => 4, 3, 'b' => [5]],
91-
_::_($array)->union([3, 'a' => 4, 'b' => [5]])->get(),
91+
underscore($array)->union([3, 'a' => 4, 'b' => [5]])->get(),
9292
'union'
9393
);
9494
}
@@ -99,7 +99,7 @@ public function test_intersection()
9999

100100
$this->assertSame(
101101
[1 => 2, 'a' => 3],
102-
_::_($array)->intersection([2, 'a' => 3, 3])->get(),
102+
underscore($array)->intersection([2, 'a' => 3, 3])->get(),
103103
'intersection'
104104
);
105105
}
@@ -110,7 +110,7 @@ public function test_zip()
110110

111111
$this->assertSame(
112112
[[1, 2], [2, 4], 'a' => [3, 5], 'b' => ['B', null]],
113-
_::_($array)->zip([2, 4, 'a' => 5])->get(),
113+
underscore($array)->zip([2, 4, 'a' => 5])->get(),
114114
'zip'
115115
);
116116
}
@@ -119,7 +119,7 @@ public function test_object()
119119
{
120120
$array = [[1, 2], 'a' => 3, 'b' => 'B'];
121121

122-
foreach (_::_($array)->object() as $index => $value) {
122+
foreach (underscore($array)->object() as $index => $value) {
123123
$this->assertTrue(is_object($value));
124124
$this->assertSame($index, $value->index);
125125
$this->assertSame($array[$index], $value->value);
@@ -128,7 +128,7 @@ public function test_object()
128128

129129
public function test_findIndex_findLastIndex()
130130
{
131-
$array = _::_([[1, 2], 'a' => 3, 'x' => 4, 'y' => 2, 'b' => 'B']);
131+
$array = underscore([[1, 2], 'a' => 3, 'x' => 4, 'y' => 2, 'b' => 'B']);
132132

133133
$this->assertSame(0, $array->findIndex());
134134
$this->assertSame('b', $array->findLastIndex());
@@ -143,25 +143,25 @@ public function test_findIndex_findLastIndex()
143143

144144
public function test_indexOf_lastIndexOf()
145145
{
146-
$array = _::_([[1, 2], 'a' => 2, 'x' => 4, 'y' => 2, 'b' => 'B']);
146+
$array = underscore([[1, 2], 'a' => 2, 'x' => 4, 'y' => 2, 'b' => 'B']);
147147

148148
$this->assertSame('a', $array->indexOf(2));
149149
$this->assertSame('y', $array->lastIndexOf(2));
150150
}
151151

152152
public function test_range()
153153
{
154-
$this->assertSame([4, 5, 6, 7, 8, 9], _::_()->range(4, 9)->get());
155-
$this->assertSame([10, 12, 14, 16, 18], _::_()->range(10, 18, 2)->get());
156-
$this->assertSame([20, 19, 18, 17, 16], _::_()->range(20, 16, -1)->get());
154+
$this->assertSame([4, 5, 6, 7, 8, 9], underscore()->range(4, 9)->get());
155+
$this->assertSame([10, 12, 14, 16, 18], underscore()->range(10, 18, 2)->get());
156+
$this->assertSame([20, 19, 18, 17, 16], underscore()->range(20, 16, -1)->get());
157157
}
158158

159159
public function test_sortedIndex()
160160
{
161161
$nums = [1, 3, 5, 8, 11];
162162
$new = 9;
163163

164-
$newIdx = _::_($nums)->sortedIndex($new, null);
164+
$newIdx = underscore($nums)->sortedIndex($new, null);
165165

166166
$this->assertSame(4, $newIdx);
167167

@@ -174,7 +174,7 @@ public function test_sortedIndex()
174174
];
175175

176176
$new = ['x' => 3, 'y' => 2];
177-
$newIdx = _::_($data)->sortedIndex($new, function ($row) {
177+
$newIdx = underscore($data)->sortedIndex($new, function ($row) {
178178
return $row['x'] + $row['y'];
179179
});
180180

tests/UnderscoreBaseTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,27 @@ public function test_keys_values()
5454
{
5555
$array = [[1, 2], 'a' => 3, 7, 'b' => 'B'];
5656

57-
$this->assertSame(array_keys($array), _::_($array)->keys()->get());
58-
$this->assertSame(array_values($array), _::_($array)->values()->get());
57+
$this->assertSame(array_keys($array), underscore($array)->keys()->get());
58+
$this->assertSame(array_values($array), underscore($array)->values()->get());
5959
}
6060

6161
public function test_pairs()
6262
{
6363
$array = ['a' => 3, 7, 'b' => 'B'];
6464

65-
$this->assertSame(['a' => ['a', 3], 0 => [0, 7], 'b' => ['b', 'B']], _::_($array)->pairs()->get());
65+
$this->assertSame(['a' => ['a', 3], 0 => [0, 7], 'b' => ['b', 'B']], underscore($array)->pairs()->get());
6666
}
6767

6868
public function test_invert()
6969
{
7070
$array = ['a' => 3, 7, 'b' => 'B'];
7171

72-
$this->assertSame(array_flip($array), _::_($array)->invert()->get());
72+
$this->assertSame(array_flip($array), underscore($array)->invert()->get());
7373
}
7474

7575
public function test_pick_omit()
7676
{
77-
$array = _::_(['a' => 3, 7, 'b' => 'B', 1 => ['c', 5]]);
77+
$array = underscore(['a' => 3, 7, 'b' => 'B', 1 => ['c', 5]]);
7878

7979
$this->assertSame([7, 'b' => 'B'], $array->pick([0, 'b'])->get());
8080
$this->assertSame(['b' => 'B', 1 => ['c', 5]], $array->pick(1, 'b')->get());
@@ -84,7 +84,7 @@ public function test_pick_omit()
8484

8585
public function test_clone_tap()
8686
{
87-
$main = _::_(['will', 'be', 'cloned']);
87+
$main = underscore(['will', 'be', 'cloned']);
8888
$clon = $main->clon();
8989

9090
$this->assertNotSame($main, $clon, 'hard equal');
@@ -111,7 +111,7 @@ public function test_mixin()
111111
});
112112
});
113113

114-
$und = _::_([10, 20, 30]);
114+
$und = underscore([10, 20, 30]);
115115

116116
$this->assertTrue(is_callable([$und, 'double']));
117117
$this->assertSame([20, 40, 60], $und->double()->toArray());
@@ -121,8 +121,8 @@ public function test_mixin()
121121

122122
public function test_valueOf()
123123
{
124-
$this->assertSame('[]', _::_()->valueOf());
125-
$this->assertSame('[1,2]', _::_([1, 2])->valueOf());
126-
$this->assertSame('["a","b"]', _::_(['a', 'b'])->valueOf());
124+
$this->assertSame('[]', underscore()->valueOf());
125+
$this->assertSame('[1,2]', underscore([1, 2])->valueOf());
126+
$this->assertSame('["a","b"]', underscore(['a', 'b'])->valueOf());
127127
}
128128
}

0 commit comments

Comments
 (0)