File: interfaces_test.php

package info (click to toggle)
postfixadmin 2.3.5-2%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,200 kB
  • sloc: php: 25,767; xml: 14,485; perl: 964; sh: 664; python: 169; makefile: 84
file content (119 lines) | stat: -rw-r--r-- 3,720 bytes parent folder | download | duplicates (2)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
    // $Id: interfaces_test.php,v 1.10 2007/01/18 18:31:46 tswicegood Exp $
    if (function_exists('spl_classes')) {
        include(dirname(__FILE__) . '/support/spl_examples.php');
    }

    interface DummyInterface {
        function aMethod();
        function anotherMethod($a);
        function &referenceMethod(&$a);
    }

    Mock::generateSubclass('DummyInterface');
    Mock::generatePartial('DummyInterface', 'PartialDummyInterface', array());

    class TestOfMockInterfaces extends UnitTestCase {

        function testCanMockAnInterface() {
            $mock = new MockDummyInterface();
            $this->assertIsA($mock, 'SimpleMock');
            $this->assertIsA($mock, 'MockDummyInterface');
            $this->assertTrue(method_exists($mock, 'aMethod'));
            $this->assertTrue(method_exists($mock, 'anotherMethod'));
            $this->assertNull($mock->aMethod());
        }

        function testMockedInterfaceExpectsParameters() {
            $mock = new MockDummyInterface();
            $mock->anotherMethod();
            $this->assertError();
        }

        function testCannotPartiallyMockAnInterface() {
            $this->assertFalse(class_exists('PartialDummyInterface'));
        }
    }

    class TestOfSpl extends UnitTestCase {

        function testCanMockAllSplClasses() {
            if (! function_exists('spl_classes')) {
                return;
            }
            foreach(spl_classes() as $class) {
                $mock_class = "Mock$class";
                Mock::generate($class);
                $this->assertIsA(new $mock_class(), $mock_class);
            }
        }

        function testExtensionOfCommonSplClasses() {
            if (! function_exists('spl_classes')) {
                return;
            }
            Mock::generate('IteratorImplementation');
            $this->assertIsA(
                    new IteratorImplementation(),
                    'IteratorImplementation');
            Mock::generate('IteratorAggregateImplementation');
            $this->assertIsA(
                    new IteratorAggregateImplementation(),
                    'IteratorAggregateImplementation');
       }
    }

    class WithHint {
        function hinted(DummyInterface $object) { }
    }

    class ImplementsDummy implements DummyInterface {
        function aMethod() { }
        function anotherMethod($a) { }
        function &referenceMethod(&$a) { }
        function extraMethod($a = false) { }
    }
    Mock::generate('ImplementsDummy');

    class TestOfImplementations extends UnitTestCase {

        function testMockedInterfaceCanPassThroughTypeHint() {
            $mock = new MockDummyInterface();
            $hinter = new WithHint();
            $hinter->hinted($mock);
        }

        function testImplementedInterfacesAreCarried() {
            $mock = new MockImplementsDummy();
            $hinter = new WithHint();
            $hinter->hinted($mock);
        }
        
        function testNoSpuriousWarningsWhenSkippingDefaultedParameter() {
            $mock = new MockImplementsDummy();
            $mock->extraMethod();
        }
    }

    interface SampleClassWithConstruct {
        function __construct($something);
    }

    class TestOfInterfaceMocksWithConstruct extends UnitTestCase {
        function testBasicConstructOfAnInterface() {
            Mock::generate('SampleClassWithConstruct');
            $this->assertNoErrors();
        }
    }

	interface SampleInterfaceWithClone {
		function __clone();
	}

	class TestOfSampleInterfaceWithClone extends UnitTestCase {
		function testCanMockWithoutErrors() {
			Mock::generate('SampleInterfaceWithClone');
			$this->assertNoErrors();
		}
	}
?>