comparison vendor/phpunit/phpunit-mock-objects/tests/MockObject/232.phpt @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 --TEST--
2 PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE, TRUE)
3 --SKIPIF--
4 <?php
5 if (version_compare(PHP_VERSION, '5.4.0', '<')) print 'skip: PHP >= 5.4.0 required';
6 ?>
7 --FILE--
8 <?php
9 trait BaseTrait
10 {
11 protected function hello()
12 {
13 return 'hello';
14 }
15 }
16
17 trait ChildTrait
18 {
19 use BaseTrait
20 {
21 hello as private hi;
22 }
23
24 protected function hello()
25 {
26 return 'hi';
27 }
28
29 protected function world()
30 {
31 return $this->hi();
32 }
33 }
34
35 class Foo
36 {
37 use ChildTrait;
38
39 public function speak()
40 {
41 return $this->world();
42 }
43 }
44
45 require __DIR__ . '/../../vendor/autoload.php';
46
47 $generator = new PHPUnit_Framework_MockObject_Generator;
48
49 $mock = $generator->generate(
50 'Foo',
51 array(),
52 'MockFoo',
53 TRUE,
54 TRUE
55 );
56
57 print $mock['code'];
58 ?>
59 --EXPECTF--
60 class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
61 {
62 private $__phpunit_invocationMocker;
63 private $__phpunit_originalObject;
64
65 public function __clone()
66 {
67 $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
68 }
69
70 public function speak()
71 {
72 $arguments = array();
73 $count = func_num_args();
74
75 if ($count > 0) {
76 $_arguments = func_get_args();
77
78 for ($i = 0; $i < $count; $i++) {
79 $arguments[] = $_arguments[$i];
80 }
81 }
82
83 $result = $this->__phpunit_getInvocationMocker()->invoke(
84 new PHPUnit_Framework_MockObject_Invocation_Object(
85 'Foo', 'speak', $arguments, $this, TRUE
86 )
87 );
88
89 return $result;
90 }
91
92 public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
93 {
94 return $this->__phpunit_getInvocationMocker()->expects($matcher);
95 }
96
97 public function method()
98 {
99 $any = new PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount;
100 $expects = $this->expects($any);
101 return call_user_func_array(array($expects, 'method'), func_get_args());
102 }
103
104 public function __phpunit_setOriginalObject($originalObject)
105 {
106 $this->__phpunit_originalObject = $originalObject;
107 }
108
109 public function __phpunit_getInvocationMocker()
110 {
111 if ($this->__phpunit_invocationMocker === NULL) {
112 $this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
113 }
114
115 return $this->__phpunit_invocationMocker;
116 }
117
118 public function __phpunit_hasMatchers()
119 {
120 return $this->__phpunit_getInvocationMocker()->hasMatchers();
121 }
122
123 public function __phpunit_verify()
124 {
125 $this->__phpunit_getInvocationMocker()->verify();
126 $this->__phpunit_invocationMocker = NULL;
127 }
128 }
129