summaryrefslogtreecommitdiffstats
path: root/3rdparty/simpletest/extensions/coverage/test/coverage_utils_test.php
blob: b900c5d2c4353ec58e8c8aa53f3b6bc536cd847c (plain)
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
<?php
require_once dirname(__FILE__) . '/../../../autorun.php';

class CoverageUtilsTest extends UnitTestCase {
    function skip() {
        $this->skipIf(
        		!file_exists('DB/sqlite.php'),
                'The Coverage extension needs to have PEAR installed');
    }
	
	function setUp() {
    	require_once dirname(__FILE__) .'/../coverage_utils.php';
	}
	
    function testMkdir() {
        CoverageUtils::mkdir(dirname(__FILE__));
        try {
            CoverageUtils::mkdir(__FILE__);
            $this->fail("Should give error about cannot create dir of a file");
        } catch (Exception $expected) {
        }
    }

    function testIsPackageClassAvailable() {
        $coverageSource = dirname(__FILE__) .'/../coverage_calculator.php';
        $this->assertTrue(CoverageUtils::isPackageClassAvailable($coverageSource, 'CoverageCalculator'));
        $this->assertFalse(CoverageUtils::isPackageClassAvailable($coverageSource, 'BogusCoverage'));
        $this->assertFalse(CoverageUtils::isPackageClassAvailable('bogus-file', 'BogusCoverage'));
        $this->assertTrue(CoverageUtils::isPackageClassAvailable('bogus-file', 'CoverageUtils'));
    }

    function testParseArgumentsMultiValue() {
        $actual = CoverageUtils::parseArguments(array('scriptname', '--a=b', '--a=c'), True);
        $expected = array('extraArguments' => array(), 'a' => 'c', 'a[]' => array('b', 'c'));
        $this->assertEqual($expected, $actual);
    }

    function testParseArguments() {
        $actual = CoverageUtils::parseArguments(array('scriptname', '--a=b', '-c', 'xxx'));
        $expected = array('a' => 'b', 'c' => '', 'extraArguments' => array('xxx'));
        $this->assertEqual($expected, $actual);
    }

    function testParseDoubleDashNoArguments() {
        $actual = CoverageUtils::parseArguments(array('scriptname', '--aa'));
        $this->assertTrue(isset($actual['aa']));
    }

    function testParseHyphenedExtraArguments() {
        $actual = CoverageUtils::parseArguments(array('scriptname', '--alpha-beta=b', 'gamma-lambda'));
        $expected = array('alpha-beta' => 'b', 'extraArguments' => array('gamma-lambda'));
        $this->assertEqual($expected, $actual);
    }

    function testAddItemAsArray() {
        $actual = array();
        CoverageUtils::addItemAsArray($actual, 'bird', 'duck');
        $this->assertEqual(array('bird[]' => array('duck')), $actual);

        CoverageUtils::addItemAsArray(&$actual, 'bird', 'pigeon');
        $this->assertEqual(array('bird[]' => array('duck', 'pigeon')), $actual);
    }

    function testIssetOr() {
        $data = array('bird' => 'gull');
        $this->assertEqual('lab', CoverageUtils::issetOr($data['dog'], 'lab'));
        $this->assertEqual('gull', CoverageUtils::issetOr($data['bird'], 'sparrow'));
    }
}
?>