Page MenuHomec4science

PhutilUtilsTestCase.php
No OneTemporary

File Metadata

Created
Sun, May 12, 01:46

PhutilUtilsTestCase.php

<?php
/*
* Copyright 2011 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
*/
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);
}
}

Event Timeline