~tcuthbert/wordpress/openstack-objectstorage

« back to all changes in this revision

Viewing changes to vendor/phpunit/phpunit-mock-objects/tests/MockObject/class.phpt

  • Committer: Jacek Nykis
  • Date: 2015-02-11 15:35:31 UTC
  • Revision ID: jacek.nykis@canonical.com-20150211153531-hmy6zi0ov2qfkl0b
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--TEST--
 
2
PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE, TRUE)
 
3
--FILE--
 
4
<?php
 
5
class Foo
 
6
{
 
7
    public function bar(Foo $foo)
 
8
    {
 
9
    }
 
10
 
 
11
    public function baz(Foo $foo)
 
12
    {
 
13
    }
 
14
}
 
15
 
 
16
require __DIR__ . '/../../vendor/autoload.php';
 
17
 
 
18
$generator = new PHPUnit_Framework_MockObject_Generator;
 
19
 
 
20
$mock = $generator->generate(
 
21
  'Foo',
 
22
  array(),
 
23
  'MockFoo',
 
24
  TRUE,
 
25
  TRUE
 
26
);
 
27
 
 
28
print $mock['code'];
 
29
?>
 
30
--EXPECTF--
 
31
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
 
32
{
 
33
    private $__phpunit_invocationMocker;
 
34
    private $__phpunit_originalObject;
 
35
 
 
36
    public function __clone()
 
37
    {
 
38
        $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
 
39
    }
 
40
 
 
41
    public function bar(Foo $foo)
 
42
    {
 
43
        $arguments = array($foo);
 
44
        $count     = func_num_args();
 
45
 
 
46
        if ($count > 1) {
 
47
            $_arguments = func_get_args();
 
48
 
 
49
            for ($i = 1; $i < $count; $i++) {
 
50
                $arguments[] = $_arguments[$i];
 
51
            }
 
52
        }
 
53
 
 
54
        $result = $this->__phpunit_getInvocationMocker()->invoke(
 
55
          new PHPUnit_Framework_MockObject_Invocation_Object(
 
56
            'Foo', 'bar', $arguments, $this, TRUE
 
57
          )
 
58
        );
 
59
 
 
60
        return $result;
 
61
    }
 
62
 
 
63
    public function baz(Foo $foo)
 
64
    {
 
65
        $arguments = array($foo);
 
66
        $count     = func_num_args();
 
67
 
 
68
        if ($count > 1) {
 
69
            $_arguments = func_get_args();
 
70
 
 
71
            for ($i = 1; $i < $count; $i++) {
 
72
                $arguments[] = $_arguments[$i];
 
73
            }
 
74
        }
 
75
 
 
76
        $result = $this->__phpunit_getInvocationMocker()->invoke(
 
77
          new PHPUnit_Framework_MockObject_Invocation_Object(
 
78
            'Foo', 'baz', $arguments, $this, TRUE
 
79
          )
 
80
        );
 
81
 
 
82
        return $result;
 
83
    }
 
84
 
 
85
    public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
 
86
    {
 
87
        return $this->__phpunit_getInvocationMocker()->expects($matcher);
 
88
    }
 
89
 
 
90
    public function method()
 
91
    {
 
92
        $any = new PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount;
 
93
        $expects = $this->expects($any);
 
94
        return call_user_func_array(array($expects, 'method'), func_get_args());
 
95
    }
 
96
 
 
97
    public function __phpunit_setOriginalObject($originalObject)
 
98
    {
 
99
        $this->__phpunit_originalObject = $originalObject;
 
100
    }
 
101
 
 
102
    public function __phpunit_getInvocationMocker()
 
103
    {
 
104
        if ($this->__phpunit_invocationMocker === NULL) {
 
105
            $this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
 
106
        }
 
107
 
 
108
        return $this->__phpunit_invocationMocker;
 
109
    }
 
110
 
 
111
    public function __phpunit_hasMatchers()
 
112
    {
 
113
        return $this->__phpunit_getInvocationMocker()->hasMatchers();
 
114
    }
 
115
 
 
116
    public function __phpunit_verify()
 
117
    {
 
118
        $this->__phpunit_getInvocationMocker()->verify();
 
119
        $this->__phpunit_invocationMocker = NULL;
 
120
    }
 
121
}