~ballot/wordpress/openstack-objectstorage-breaking-insight

« back to all changes in this revision

Viewing changes to vendor/phpunit/phpunit-mock-objects/tests/MockObject/invocation_object_clone_object.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, 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
  TRUE
 
27
);
 
28
 
 
29
print $mock['code'];
 
30
?>
 
31
--EXPECTF--
 
32
class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
 
33
{
 
34
    private $__phpunit_invocationMocker;
 
35
    private $__phpunit_originalObject;
 
36
 
 
37
    public function __clone()
 
38
    {
 
39
        $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
 
40
    }
 
41
 
 
42
    public function bar(Foo $foo)
 
43
    {
 
44
        $arguments = array($foo);
 
45
        $count     = func_num_args();
 
46
 
 
47
        if ($count > 1) {
 
48
            $_arguments = func_get_args();
 
49
 
 
50
            for ($i = 1; $i < $count; $i++) {
 
51
                $arguments[] = $_arguments[$i];
 
52
            }
 
53
        }
 
54
 
 
55
        $result = $this->__phpunit_getInvocationMocker()->invoke(
 
56
          new PHPUnit_Framework_MockObject_Invocation_Object(
 
57
            'Foo', 'bar', $arguments, $this, TRUE
 
58
          )
 
59
        );
 
60
 
 
61
        return $result;
 
62
    }
 
63
 
 
64
    public function baz(Foo $foo)
 
65
    {
 
66
        $arguments = array($foo);
 
67
        $count     = func_num_args();
 
68
 
 
69
        if ($count > 1) {
 
70
            $_arguments = func_get_args();
 
71
 
 
72
            for ($i = 1; $i < $count; $i++) {
 
73
                $arguments[] = $_arguments[$i];
 
74
            }
 
75
        }
 
76
 
 
77
        $result = $this->__phpunit_getInvocationMocker()->invoke(
 
78
          new PHPUnit_Framework_MockObject_Invocation_Object(
 
79
            'Foo', 'baz', $arguments, $this, TRUE
 
80
          )
 
81
        );
 
82
 
 
83
        return $result;
 
84
    }
 
85
 
 
86
    public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
 
87
    {
 
88
        return $this->__phpunit_getInvocationMocker()->expects($matcher);
 
89
    }
 
90
 
 
91
    public function method()
 
92
    {
 
93
        $any = new PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount;
 
94
        $expects = $this->expects($any);
 
95
        return call_user_func_array(array($expects, 'method'), func_get_args());
 
96
    }
 
97
 
 
98
    public function __phpunit_setOriginalObject($originalObject)
 
99
    {
 
100
        $this->__phpunit_originalObject = $originalObject;
 
101
    }
 
102
 
 
103
    public function __phpunit_getInvocationMocker()
 
104
    {
 
105
        if ($this->__phpunit_invocationMocker === NULL) {
 
106
            $this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
 
107
        }
 
108
 
 
109
        return $this->__phpunit_invocationMocker;
 
110
    }
 
111
 
 
112
    public function __phpunit_hasMatchers()
 
113
    {
 
114
        return $this->__phpunit_getInvocationMocker()->hasMatchers();
 
115
    }
 
116
 
 
117
    public function __phpunit_verify()
 
118
    {
 
119
        $this->__phpunit_getInvocationMocker()->verify();
 
120
        $this->__phpunit_invocationMocker = NULL;
 
121
    }
 
122
}