Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F65761605
PhutilUtilsTestCase.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jun 6, 01:23
Size
4 KB
Mime Type
text/x-php
Expires
Sat, Jun 8, 01:23 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18123371
Attached To
rPHU libphutil
PhutilUtilsTestCase.php
View Options
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Test cases for functions in utils.php.
*
* @group testcase
*/
final
class
PhutilUtilsTestCase
extends
ArcanistPhutilTestCase
{
public
function
testMFilter_nullMethod_throwException
()
{
$list
=
array
();
try
{
$actual
=
mfilter
(
$list
,
null
);
$this
->
assertFailure
(
'Method call should have thrown an '
.
'InvalidArgumentException.'
);
}
catch
(
InvalidArgumentException
$ex
)
{
if
(
$ex
->
getMessage
()
!=
'Argument method is not a string.'
)
{
throw
$ex
;
}
}
}
public
function
testMFilter_withEmptyValue_filtered
()
{
$a
=
new
MFilterTestHelper
(
'o'
,
'p'
,
'q'
);
$b
=
new
MFilterTestHelper
(
'o'
,
''
,
'q'
);
$c
=
new
MFilterTestHelper
(
'o'
,
'p'
,
'q'
);
$list
=
array
(
'a'
=>
$a
,
'b'
=>
$b
,
'c'
=>
$c
,
);
$actual
=
mfilter
(
$list
,
'getI'
);
$expected
=
array
(
'a'
=>
$a
,
'c'
=>
$c
,
);
$this
->
assertEqual
(
$expected
,
$actual
);
}
public
function
testMFilter_withEmptyValueNegate_filtered
()
{
$a
=
new
MFilterTestHelper
(
'o'
,
'p'
,
'q'
);
$b
=
new
MFilterTestHelper
(
'o'
,
''
,
'q'
);
$c
=
new
MFilterTestHelper
(
'o'
,
'p'
,
'q'
);
$list
=
array
(
'a'
=>
$a
,
'b'
=>
$b
,
'c'
=>
$c
,
);
$actual
=
mfilter
(
$list
,
'getI'
,
true
);
$expected
=
array
(
'b'
=>
$b
,
);
$this
->
assertEqual
(
$expected
,
$actual
);
}
public
function
testIFilter_invalidIndex_throwException
()
{
$list
=
array
();
try
{
$actual
=
ifilter
(
$list
,
null
);
$this
->
assertFailure
(
'Method call should have thrown an '
.
'InvalidArgumentException.'
);
}
catch
(
InvalidArgumentException
$ex
)
{
if
(
$ex
->
getMessage
()
!=
'Argument index is not a scalar.'
)
{
throw
$ex
;
}
}
}
public
function
testIFilter_withEmptyValue_filtered
()
{
$list
=
array
(
'a'
=>
array
(
'h'
=>
'o'
,
'i'
=>
'p'
,
'j'
=>
'q'
,),
'b'
=>
array
(
'h'
=>
'o'
,
'i'
=>
''
,
'j'
=>
'q'
,),
'c'
=>
array
(
'h'
=>
'o'
,
'i'
=>
'p'
,
'j'
=>
'q'
,),
'd'
=>
array
(
'h'
=>
'o'
,
'i'
=>
0
,
'j'
=>
'q'
,),
'e'
=>
array
(
'h'
=>
'o'
,
'i'
=>
null
,
'j'
=>
'q'
,),
'f'
=>
array
(
'h'
=>
'o'
,
'i'
=>
false
,
'j'
=>
'q'
,),
);
$actual
=
ifilter
(
$list
,
'i'
);
$expected
=
array
(
'a'
=>
array
(
'h'
=>
'o'
,
'i'
=>
'p'
,
'j'
=>
'q'
,),
'c'
=>
array
(
'h'
=>
'o'
,
'i'
=>
'p'
,
'j'
=>
'q'
,),
);
$this
->
assertEqual
(
$expected
,
$actual
);
}
public
function
testIFilter_indexNotExists_allFiltered
()
{
$list
=
array
(
'a'
=>
array
(
'h'
=>
'o'
,
'i'
=>
'p'
,
'j'
=>
'q'
,),
'b'
=>
array
(
'h'
=>
'o'
,
'i'
=>
''
,
'j'
=>
'q'
,),
);
$actual
=
ifilter
(
$list
,
'NoneExisting'
);
$expected
=
array
();
$this
->
assertEqual
(
$expected
,
$actual
);
}
public
function
testIFilter_withEmptyValueNegate_filtered
()
{
$list
=
array
(
'a'
=>
array
(
'h'
=>
'o'
,
'i'
=>
'p'
,
'j'
=>
'q'
,),
'b'
=>
array
(
'h'
=>
'o'
,
'i'
=>
''
,
'j'
=>
'q'
,),
'c'
=>
array
(
'h'
=>
'o'
,
'i'
=>
'p'
,
'j'
=>
'q'
,),
'd'
=>
array
(
'h'
=>
'o'
,
'i'
=>
0
,
'j'
=>
'q'
,),
'e'
=>
array
(
'h'
=>
'o'
,
'i'
=>
null
,
'j'
=>
'q'
,),
'f'
=>
array
(
'h'
=>
'o'
,
'i'
=>
false
,
'j'
=>
'q'
,),
);
$actual
=
ifilter
(
$list
,
'i'
,
true
);
$expected
=
array
(
'b'
=>
array
(
'h'
=>
'o'
,
'i'
=>
''
,
'j'
=>
'q'
,),
'd'
=>
array
(
'h'
=>
'o'
,
'i'
=>
0
,
'j'
=>
'q'
,),
'e'
=>
array
(
'h'
=>
'o'
,
'i'
=>
null
,
'j'
=>
'q'
,),
'f'
=>
array
(
'h'
=>
'o'
,
'i'
=>
false
,
'j'
=>
'q'
,),
);
$this
->
assertEqual
(
$expected
,
$actual
);
}
public
function
testIFilter_indexNotExists_notFiltered
()
{
$list
=
array
(
'a'
=>
array
(
'h'
=>
'o'
,
'i'
=>
'p'
,
'j'
=>
'q'
,),
'b'
=>
array
(
'h'
=>
'o'
,
'i'
=>
''
,
'j'
=>
'q'
,),
);
$actual
=
ifilter
(
$list
,
'NoneExisting'
,
true
);
$expected
=
array
(
'a'
=>
array
(
'h'
=>
'o'
,
'i'
=>
'p'
,
'j'
=>
'q'
,),
'b'
=>
array
(
'h'
=>
'o'
,
'i'
=>
''
,
'j'
=>
'q'
,),
);
$this
->
assertEqual
(
$expected
,
$actual
);
}
public
function
testmergev_merging_basicallyWorksCorrectly
()
{
$this
->
assertEqual
(
array
(
1
,
2
,
3
,
4
,
5
),
array_mergev
(
array
(
array
(
1
,
2
),
array
(
3
),
array
(),
array
(
4
,
5
),
)));
}
}
Event Timeline
Log In to Comment