@@ -17,18 +17,18 @@ |
||
17 | 17 | */ |
18 | 18 | interface TestSuiteLoader |
19 | 19 | { |
20 | - /** |
|
21 | - * @param string $suiteClassName |
|
22 | - * @param string $suiteClassFile |
|
23 | - * |
|
24 | - * @return ReflectionClass |
|
25 | - */ |
|
26 | - public function load($suiteClassName, $suiteClassFile = ''); |
|
20 | + /** |
|
21 | + * @param string $suiteClassName |
|
22 | + * @param string $suiteClassFile |
|
23 | + * |
|
24 | + * @return ReflectionClass |
|
25 | + */ |
|
26 | + public function load($suiteClassName, $suiteClassFile = ''); |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param ReflectionClass $aClass |
|
30 | - * |
|
31 | - * @return ReflectionClass |
|
32 | - */ |
|
33 | - public function reload(ReflectionClass $aClass); |
|
28 | + /** |
|
29 | + * @param ReflectionClass $aClass |
|
30 | + * |
|
31 | + * @return ReflectionClass |
|
32 | + */ |
|
33 | + public function reload(ReflectionClass $aClass); |
|
34 | 34 | } |
@@ -19,102 +19,102 @@ |
||
19 | 19 | */ |
20 | 20 | class StandardTestSuiteLoader implements TestSuiteLoader |
21 | 21 | { |
22 | - /** |
|
23 | - * @param string $suiteClassName |
|
24 | - * @param string $suiteClassFile |
|
25 | - * |
|
26 | - * @return ReflectionClass |
|
27 | - * |
|
28 | - * @throws Exception |
|
29 | - */ |
|
30 | - public function load($suiteClassName, $suiteClassFile = '') |
|
31 | - { |
|
32 | - $suiteClassName = \str_replace('.php', '', $suiteClassName); |
|
33 | - |
|
34 | - if (empty($suiteClassFile)) { |
|
35 | - $suiteClassFile = Filesystem::classNameToFilename( |
|
36 | - $suiteClassName |
|
37 | - ); |
|
38 | - } |
|
39 | - |
|
40 | - if (!\class_exists($suiteClassName, false)) { |
|
41 | - $loadedClasses = \get_declared_classes(); |
|
42 | - |
|
43 | - $filename = Fileloader::checkAndLoad($suiteClassFile); |
|
44 | - |
|
45 | - $loadedClasses = \array_values( |
|
46 | - \array_diff(\get_declared_classes(), $loadedClasses) |
|
47 | - ); |
|
48 | - } |
|
49 | - |
|
50 | - if (!\class_exists($suiteClassName, false) && !empty($loadedClasses)) { |
|
51 | - $offset = 0 - \strlen($suiteClassName); |
|
52 | - |
|
53 | - foreach ($loadedClasses as $loadedClass) { |
|
54 | - $class = new ReflectionClass($loadedClass); |
|
55 | - if (\substr($loadedClass, $offset) === $suiteClassName && |
|
56 | - $class->getFileName() == $filename) { |
|
57 | - $suiteClassName = $loadedClass; |
|
58 | - |
|
59 | - break; |
|
60 | - } |
|
61 | - } |
|
62 | - } |
|
63 | - |
|
64 | - if (!\class_exists($suiteClassName, false) && !empty($loadedClasses)) { |
|
65 | - $testCaseClass = TestCase::class; |
|
66 | - |
|
67 | - foreach ($loadedClasses as $loadedClass) { |
|
68 | - $class = new ReflectionClass($loadedClass); |
|
69 | - $classFile = $class->getFileName(); |
|
70 | - |
|
71 | - if ($class->isSubclassOf($testCaseClass) && !$class->isAbstract()) { |
|
72 | - $suiteClassName = $loadedClass; |
|
73 | - $testCaseClass = $loadedClass; |
|
74 | - |
|
75 | - if ($classFile == \realpath($suiteClassFile)) { |
|
76 | - break; |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - if ($class->hasMethod('suite')) { |
|
81 | - $method = $class->getMethod('suite'); |
|
82 | - |
|
83 | - if (!$method->isAbstract() && $method->isPublic() && $method->isStatic()) { |
|
84 | - $suiteClassName = $loadedClass; |
|
85 | - |
|
86 | - if ($classFile == \realpath($suiteClassFile)) { |
|
87 | - break; |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - if (\class_exists($suiteClassName, false)) { |
|
95 | - $class = new ReflectionClass($suiteClassName); |
|
96 | - |
|
97 | - if ($class->getFileName() == \realpath($suiteClassFile)) { |
|
98 | - return $class; |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - throw new Exception( |
|
103 | - \sprintf( |
|
104 | - "Class '%s' could not be found in '%s'.", |
|
105 | - $suiteClassName, |
|
106 | - $suiteClassFile |
|
107 | - ) |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @param ReflectionClass $aClass |
|
113 | - * |
|
114 | - * @return ReflectionClass |
|
115 | - */ |
|
116 | - public function reload(ReflectionClass $aClass) |
|
117 | - { |
|
118 | - return $aClass; |
|
119 | - } |
|
22 | + /** |
|
23 | + * @param string $suiteClassName |
|
24 | + * @param string $suiteClassFile |
|
25 | + * |
|
26 | + * @return ReflectionClass |
|
27 | + * |
|
28 | + * @throws Exception |
|
29 | + */ |
|
30 | + public function load($suiteClassName, $suiteClassFile = '') |
|
31 | + { |
|
32 | + $suiteClassName = \str_replace('.php', '', $suiteClassName); |
|
33 | + |
|
34 | + if (empty($suiteClassFile)) { |
|
35 | + $suiteClassFile = Filesystem::classNameToFilename( |
|
36 | + $suiteClassName |
|
37 | + ); |
|
38 | + } |
|
39 | + |
|
40 | + if (!\class_exists($suiteClassName, false)) { |
|
41 | + $loadedClasses = \get_declared_classes(); |
|
42 | + |
|
43 | + $filename = Fileloader::checkAndLoad($suiteClassFile); |
|
44 | + |
|
45 | + $loadedClasses = \array_values( |
|
46 | + \array_diff(\get_declared_classes(), $loadedClasses) |
|
47 | + ); |
|
48 | + } |
|
49 | + |
|
50 | + if (!\class_exists($suiteClassName, false) && !empty($loadedClasses)) { |
|
51 | + $offset = 0 - \strlen($suiteClassName); |
|
52 | + |
|
53 | + foreach ($loadedClasses as $loadedClass) { |
|
54 | + $class = new ReflectionClass($loadedClass); |
|
55 | + if (\substr($loadedClass, $offset) === $suiteClassName && |
|
56 | + $class->getFileName() == $filename) { |
|
57 | + $suiteClassName = $loadedClass; |
|
58 | + |
|
59 | + break; |
|
60 | + } |
|
61 | + } |
|
62 | + } |
|
63 | + |
|
64 | + if (!\class_exists($suiteClassName, false) && !empty($loadedClasses)) { |
|
65 | + $testCaseClass = TestCase::class; |
|
66 | + |
|
67 | + foreach ($loadedClasses as $loadedClass) { |
|
68 | + $class = new ReflectionClass($loadedClass); |
|
69 | + $classFile = $class->getFileName(); |
|
70 | + |
|
71 | + if ($class->isSubclassOf($testCaseClass) && !$class->isAbstract()) { |
|
72 | + $suiteClassName = $loadedClass; |
|
73 | + $testCaseClass = $loadedClass; |
|
74 | + |
|
75 | + if ($classFile == \realpath($suiteClassFile)) { |
|
76 | + break; |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + if ($class->hasMethod('suite')) { |
|
81 | + $method = $class->getMethod('suite'); |
|
82 | + |
|
83 | + if (!$method->isAbstract() && $method->isPublic() && $method->isStatic()) { |
|
84 | + $suiteClassName = $loadedClass; |
|
85 | + |
|
86 | + if ($classFile == \realpath($suiteClassFile)) { |
|
87 | + break; |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + if (\class_exists($suiteClassName, false)) { |
|
95 | + $class = new ReflectionClass($suiteClassName); |
|
96 | + |
|
97 | + if ($class->getFileName() == \realpath($suiteClassFile)) { |
|
98 | + return $class; |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + throw new Exception( |
|
103 | + \sprintf( |
|
104 | + "Class '%s' could not be found in '%s'.", |
|
105 | + $suiteClassName, |
|
106 | + $suiteClassFile |
|
107 | + ) |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @param ReflectionClass $aClass |
|
113 | + * |
|
114 | + * @return ReflectionClass |
|
115 | + */ |
|
116 | + public function reload(ReflectionClass $aClass) |
|
117 | + { |
|
118 | + return $aClass; |
|
119 | + } |
|
120 | 120 | } |
@@ -12,87 +12,87 @@ |
||
12 | 12 | |
13 | 13 | class PHP_TimerTest extends TestCase |
14 | 14 | { |
15 | - /** |
|
16 | - * @covers PHP_Timer::start |
|
17 | - * @covers PHP_Timer::stop |
|
18 | - */ |
|
19 | - public function testStartStop() |
|
20 | - { |
|
21 | - $this->assertInternalType('float', PHP_Timer::stop()); |
|
22 | - } |
|
15 | + /** |
|
16 | + * @covers PHP_Timer::start |
|
17 | + * @covers PHP_Timer::stop |
|
18 | + */ |
|
19 | + public function testStartStop() |
|
20 | + { |
|
21 | + $this->assertInternalType('float', PHP_Timer::stop()); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * @covers PHP_Timer::secondsToTimeString |
|
26 | - * @dataProvider secondsProvider |
|
27 | - */ |
|
28 | - public function testSecondsToTimeString($string, $seconds) |
|
29 | - { |
|
30 | - $this->assertEquals( |
|
31 | - $string, |
|
32 | - PHP_Timer::secondsToTimeString($seconds) |
|
33 | - ); |
|
34 | - } |
|
24 | + /** |
|
25 | + * @covers PHP_Timer::secondsToTimeString |
|
26 | + * @dataProvider secondsProvider |
|
27 | + */ |
|
28 | + public function testSecondsToTimeString($string, $seconds) |
|
29 | + { |
|
30 | + $this->assertEquals( |
|
31 | + $string, |
|
32 | + PHP_Timer::secondsToTimeString($seconds) |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @covers PHP_Timer::timeSinceStartOfRequest |
|
38 | - */ |
|
39 | - public function testTimeSinceStartOfRequest() |
|
40 | - { |
|
41 | - $this->assertStringMatchesFormat( |
|
42 | - '%f %s', |
|
43 | - PHP_Timer::timeSinceStartOfRequest() |
|
44 | - ); |
|
45 | - } |
|
36 | + /** |
|
37 | + * @covers PHP_Timer::timeSinceStartOfRequest |
|
38 | + */ |
|
39 | + public function testTimeSinceStartOfRequest() |
|
40 | + { |
|
41 | + $this->assertStringMatchesFormat( |
|
42 | + '%f %s', |
|
43 | + PHP_Timer::timeSinceStartOfRequest() |
|
44 | + ); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * @covers PHP_Timer::resourceUsage |
|
50 | - */ |
|
51 | - public function testResourceUsage() |
|
52 | - { |
|
53 | - $this->assertStringMatchesFormat( |
|
54 | - 'Time: %s, Memory: %fMB', |
|
55 | - PHP_Timer::resourceUsage() |
|
56 | - ); |
|
57 | - } |
|
48 | + /** |
|
49 | + * @covers PHP_Timer::resourceUsage |
|
50 | + */ |
|
51 | + public function testResourceUsage() |
|
52 | + { |
|
53 | + $this->assertStringMatchesFormat( |
|
54 | + 'Time: %s, Memory: %fMB', |
|
55 | + PHP_Timer::resourceUsage() |
|
56 | + ); |
|
57 | + } |
|
58 | 58 | |
59 | - public function secondsProvider() |
|
60 | - { |
|
61 | - return array( |
|
62 | - array('0 ms', 0), |
|
63 | - array('1 ms', .001), |
|
64 | - array('10 ms', .01), |
|
65 | - array('100 ms', .1), |
|
66 | - array('999 ms', .999), |
|
67 | - array('1 second', .9999), |
|
68 | - array('1 second', 1), |
|
69 | - array('2 seconds', 2), |
|
70 | - array('59.9 seconds', 59.9), |
|
71 | - array('59.99 seconds', 59.99), |
|
72 | - array('59.99 seconds', 59.999), |
|
73 | - array('1 minute', 59.9999), |
|
74 | - array('59 seconds', 59.001), |
|
75 | - array('59.01 seconds', 59.01), |
|
76 | - array('1 minute', 60), |
|
77 | - array('1.01 minutes', 61), |
|
78 | - array('2 minutes', 120), |
|
79 | - array('2.01 minutes', 121), |
|
80 | - array('59.99 minutes', 3599.9), |
|
81 | - array('59.99 minutes', 3599.99), |
|
82 | - array('59.99 minutes', 3599.999), |
|
83 | - array('1 hour', 3599.9999), |
|
84 | - array('59.98 minutes', 3599.001), |
|
85 | - array('59.98 minutes', 3599.01), |
|
86 | - array('1 hour', 3600), |
|
87 | - array('1 hour', 3601), |
|
88 | - array('1 hour', 3601.9), |
|
89 | - array('1 hour', 3601.99), |
|
90 | - array('1 hour', 3601.999), |
|
91 | - array('1 hour', 3601.9999), |
|
92 | - array('1.01 hours', 3659.9999), |
|
93 | - array('1.01 hours', 3659.001), |
|
94 | - array('1.01 hours', 3659.01), |
|
95 | - array('2 hours', 7199.9999), |
|
96 | - ); |
|
97 | - } |
|
59 | + public function secondsProvider() |
|
60 | + { |
|
61 | + return array( |
|
62 | + array('0 ms', 0), |
|
63 | + array('1 ms', .001), |
|
64 | + array('10 ms', .01), |
|
65 | + array('100 ms', .1), |
|
66 | + array('999 ms', .999), |
|
67 | + array('1 second', .9999), |
|
68 | + array('1 second', 1), |
|
69 | + array('2 seconds', 2), |
|
70 | + array('59.9 seconds', 59.9), |
|
71 | + array('59.99 seconds', 59.99), |
|
72 | + array('59.99 seconds', 59.999), |
|
73 | + array('1 minute', 59.9999), |
|
74 | + array('59 seconds', 59.001), |
|
75 | + array('59.01 seconds', 59.01), |
|
76 | + array('1 minute', 60), |
|
77 | + array('1.01 minutes', 61), |
|
78 | + array('2 minutes', 120), |
|
79 | + array('2.01 minutes', 121), |
|
80 | + array('59.99 minutes', 3599.9), |
|
81 | + array('59.99 minutes', 3599.99), |
|
82 | + array('59.99 minutes', 3599.999), |
|
83 | + array('1 hour', 3599.9999), |
|
84 | + array('59.98 minutes', 3599.001), |
|
85 | + array('59.98 minutes', 3599.01), |
|
86 | + array('1 hour', 3600), |
|
87 | + array('1 hour', 3601), |
|
88 | + array('1 hour', 3601.9), |
|
89 | + array('1 hour', 3601.99), |
|
90 | + array('1 hour', 3601.999), |
|
91 | + array('1 hour', 3601.9999), |
|
92 | + array('1.01 hours', 3659.9999), |
|
93 | + array('1.01 hours', 3659.001), |
|
94 | + array('1.01 hours', 3659.01), |
|
95 | + array('2 hours', 7199.9999), |
|
96 | + ); |
|
97 | + } |
|
98 | 98 | } |
@@ -13,93 +13,93 @@ |
||
13 | 13 | */ |
14 | 14 | class PHP_Timer |
15 | 15 | { |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - private static $times = array( |
|
20 | - 'hour' => 3600000, |
|
21 | - 'minute' => 60000, |
|
22 | - 'second' => 1000 |
|
23 | - ); |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + private static $times = array( |
|
20 | + 'hour' => 3600000, |
|
21 | + 'minute' => 60000, |
|
22 | + 'second' => 1000 |
|
23 | + ); |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - private static $startTimes = array(); |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + private static $startTimes = array(); |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var float |
|
32 | - */ |
|
33 | - public static $requestTime; |
|
30 | + /** |
|
31 | + * @var float |
|
32 | + */ |
|
33 | + public static $requestTime; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Starts the timer. |
|
37 | - */ |
|
38 | - public static function start() |
|
39 | - { |
|
40 | - array_push(self::$startTimes, microtime(true)); |
|
41 | - } |
|
35 | + /** |
|
36 | + * Starts the timer. |
|
37 | + */ |
|
38 | + public static function start() |
|
39 | + { |
|
40 | + array_push(self::$startTimes, microtime(true)); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Stops the timer and returns the elapsed time. |
|
45 | - * |
|
46 | - * @return float |
|
47 | - */ |
|
48 | - public static function stop() |
|
49 | - { |
|
50 | - return microtime(true) - array_pop(self::$startTimes); |
|
51 | - } |
|
43 | + /** |
|
44 | + * Stops the timer and returns the elapsed time. |
|
45 | + * |
|
46 | + * @return float |
|
47 | + */ |
|
48 | + public static function stop() |
|
49 | + { |
|
50 | + return microtime(true) - array_pop(self::$startTimes); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Formats the elapsed time as a string. |
|
55 | - * |
|
56 | - * @param float $time |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public static function secondsToTimeString($time) |
|
60 | - { |
|
61 | - $ms = round($time * 1000); |
|
53 | + /** |
|
54 | + * Formats the elapsed time as a string. |
|
55 | + * |
|
56 | + * @param float $time |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public static function secondsToTimeString($time) |
|
60 | + { |
|
61 | + $ms = round($time * 1000); |
|
62 | 62 | |
63 | - foreach (self::$times as $unit => $value) { |
|
64 | - if ($ms >= $value) { |
|
65 | - $time = floor($ms / $value * 100.0) / 100.0; |
|
63 | + foreach (self::$times as $unit => $value) { |
|
64 | + if ($ms >= $value) { |
|
65 | + $time = floor($ms / $value * 100.0) / 100.0; |
|
66 | 66 | |
67 | - return $time . ' ' . ($time == 1 ? $unit : $unit . 's'); |
|
68 | - } |
|
69 | - } |
|
67 | + return $time . ' ' . ($time == 1 ? $unit : $unit . 's'); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - return $ms . ' ms'; |
|
72 | - } |
|
71 | + return $ms . ' ms'; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Formats the elapsed time since the start of the request as a string. |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public static function timeSinceStartOfRequest() |
|
80 | - { |
|
81 | - return self::secondsToTimeString(microtime(true) - self::$requestTime); |
|
82 | - } |
|
74 | + /** |
|
75 | + * Formats the elapsed time since the start of the request as a string. |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public static function timeSinceStartOfRequest() |
|
80 | + { |
|
81 | + return self::secondsToTimeString(microtime(true) - self::$requestTime); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Returns the resources (time, memory) of the request as a string. |
|
86 | - * |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public static function resourceUsage() |
|
90 | - { |
|
91 | - return sprintf( |
|
92 | - 'Time: %s, Memory: %4.2fMB', |
|
93 | - self::timeSinceStartOfRequest(), |
|
94 | - memory_get_peak_usage(true) / 1048576 |
|
95 | - ); |
|
96 | - } |
|
84 | + /** |
|
85 | + * Returns the resources (time, memory) of the request as a string. |
|
86 | + * |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public static function resourceUsage() |
|
90 | + { |
|
91 | + return sprintf( |
|
92 | + 'Time: %s, Memory: %4.2fMB', |
|
93 | + self::timeSinceStartOfRequest(), |
|
94 | + memory_get_peak_usage(true) / 1048576 |
|
95 | + ); |
|
96 | + } |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | if (isset($_SERVER['REQUEST_TIME_FLOAT'])) { |
100 | - PHP_Timer::$requestTime = $_SERVER['REQUEST_TIME_FLOAT']; |
|
100 | + PHP_Timer::$requestTime = $_SERVER['REQUEST_TIME_FLOAT']; |
|
101 | 101 | } elseif (isset($_SERVER['REQUEST_TIME'])) { |
102 | - PHP_Timer::$requestTime = $_SERVER['REQUEST_TIME']; |
|
102 | + PHP_Timer::$requestTime = $_SERVER['REQUEST_TIME']; |
|
103 | 103 | } else { |
104 | - PHP_Timer::$requestTime = microtime(true); |
|
104 | + PHP_Timer::$requestTime = microtime(true); |
|
105 | 105 | } |
@@ -64,11 +64,11 @@ |
||
64 | 64 | if ($ms >= $value) { |
65 | 65 | $time = floor($ms / $value * 100.0) / 100.0; |
66 | 66 | |
67 | - return $time . ' ' . ($time == 1 ? $unit : $unit . 's'); |
|
67 | + return $time.' '.($time == 1 ? $unit : $unit.'s'); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | - return $ms . ' ms'; |
|
71 | + return $ms.' ms'; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -12,30 +12,30 @@ |
||
12 | 12 | |
13 | 13 | class Framework_ProxyObjectTest extends TestCase |
14 | 14 | { |
15 | - public function testMockedMethodIsProxiedToOriginalMethod() |
|
16 | - { |
|
17 | - $proxy = $this->getMockBuilder(Bar::class) |
|
18 | - ->enableProxyingToOriginalMethods() |
|
19 | - ->getMock(); |
|
15 | + public function testMockedMethodIsProxiedToOriginalMethod() |
|
16 | + { |
|
17 | + $proxy = $this->getMockBuilder(Bar::class) |
|
18 | + ->enableProxyingToOriginalMethods() |
|
19 | + ->getMock(); |
|
20 | 20 | |
21 | - $proxy->expects($this->once()) |
|
22 | - ->method('doSomethingElse'); |
|
21 | + $proxy->expects($this->once()) |
|
22 | + ->method('doSomethingElse'); |
|
23 | 23 | |
24 | - $foo = new Foo; |
|
24 | + $foo = new Foo; |
|
25 | 25 | |
26 | - $this->assertEquals('result', $foo->doSomething($proxy)); |
|
27 | - } |
|
26 | + $this->assertEquals('result', $foo->doSomething($proxy)); |
|
27 | + } |
|
28 | 28 | |
29 | - public function testMockedMethodWithReferenceIsProxiedToOriginalMethod() |
|
30 | - { |
|
31 | - $proxy = $this->getMockBuilder(MethodCallbackByReference::class) |
|
32 | - ->enableProxyingToOriginalMethods() |
|
33 | - ->getMock(); |
|
29 | + public function testMockedMethodWithReferenceIsProxiedToOriginalMethod() |
|
30 | + { |
|
31 | + $proxy = $this->getMockBuilder(MethodCallbackByReference::class) |
|
32 | + ->enableProxyingToOriginalMethods() |
|
33 | + ->getMock(); |
|
34 | 34 | |
35 | - $a = $b = $c = 0; |
|
35 | + $a = $b = $c = 0; |
|
36 | 36 | |
37 | - $proxy->callback($a, $b, $c); |
|
37 | + $proxy->callback($a, $b, $c); |
|
38 | 38 | |
39 | - $this->assertEquals(1, $b); |
|
40 | - } |
|
39 | + $this->assertEquals(1, $b); |
|
40 | + } |
|
41 | 41 | } |
@@ -13,1025 +13,1025 @@ |
||
13 | 13 | |
14 | 14 | class Framework_MockObjectTest extends TestCase |
15 | 15 | { |
16 | - public function testMockedMethodIsNeverCalled() |
|
17 | - { |
|
18 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
19 | - ->getMock(); |
|
20 | - |
|
21 | - $mock->expects($this->never()) |
|
22 | - ->method('doSomething'); |
|
23 | - } |
|
24 | - |
|
25 | - public function testMockedMethodIsNeverCalledWithParameter() |
|
26 | - { |
|
27 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
28 | - ->getMock(); |
|
29 | - |
|
30 | - $mock->expects($this->never()) |
|
31 | - ->method('doSomething') |
|
32 | - ->with('someArg'); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @doesNotPerformAssertions |
|
37 | - */ |
|
38 | - public function testMockedMethodIsNotCalledWhenExpectsAnyWithParameter() |
|
39 | - { |
|
40 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
41 | - ->getMock(); |
|
42 | - |
|
43 | - $mock->expects($this->any()) |
|
44 | - ->method('doSomethingElse') |
|
45 | - ->with('someArg'); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * @doesNotPerformAssertions |
|
50 | - */ |
|
51 | - public function testMockedMethodIsNotCalledWhenMethodSpecifiedDirectlyWithParameter() |
|
52 | - { |
|
53 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
54 | - ->getMock(); |
|
55 | - |
|
56 | - $mock->method('doSomethingElse') |
|
57 | - ->with('someArg'); |
|
58 | - } |
|
59 | - |
|
60 | - public function testMockedMethodIsCalledAtLeastOnce() |
|
61 | - { |
|
62 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
63 | - ->getMock(); |
|
64 | - |
|
65 | - $mock->expects($this->atLeastOnce()) |
|
66 | - ->method('doSomething'); |
|
67 | - |
|
68 | - $mock->doSomething(); |
|
69 | - } |
|
70 | - |
|
71 | - public function testMockedMethodIsCalledAtLeastOnce2() |
|
72 | - { |
|
73 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
74 | - ->getMock(); |
|
75 | - |
|
76 | - $mock->expects($this->atLeastOnce()) |
|
77 | - ->method('doSomething'); |
|
78 | - |
|
79 | - $mock->doSomething(); |
|
80 | - $mock->doSomething(); |
|
81 | - } |
|
82 | - |
|
83 | - public function testMockedMethodIsCalledAtLeastTwice() |
|
84 | - { |
|
85 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
86 | - ->getMock(); |
|
87 | - |
|
88 | - $mock->expects($this->atLeast(2)) |
|
89 | - ->method('doSomething'); |
|
90 | - |
|
91 | - $mock->doSomething(); |
|
92 | - $mock->doSomething(); |
|
93 | - } |
|
94 | - |
|
95 | - public function testMockedMethodIsCalledAtLeastTwice2() |
|
96 | - { |
|
97 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
98 | - ->getMock(); |
|
99 | - |
|
100 | - $mock->expects($this->atLeast(2)) |
|
101 | - ->method('doSomething'); |
|
102 | - |
|
103 | - $mock->doSomething(); |
|
104 | - $mock->doSomething(); |
|
105 | - $mock->doSomething(); |
|
106 | - } |
|
107 | - |
|
108 | - public function testMockedMethodIsCalledAtMostTwice() |
|
109 | - { |
|
110 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
111 | - ->getMock(); |
|
112 | - |
|
113 | - $mock->expects($this->atMost(2)) |
|
114 | - ->method('doSomething'); |
|
115 | - |
|
116 | - $mock->doSomething(); |
|
117 | - $mock->doSomething(); |
|
118 | - } |
|
119 | - |
|
120 | - public function testMockedMethodIsCalledAtMosttTwice2() |
|
121 | - { |
|
122 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
123 | - ->getMock(); |
|
16 | + public function testMockedMethodIsNeverCalled() |
|
17 | + { |
|
18 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
19 | + ->getMock(); |
|
20 | + |
|
21 | + $mock->expects($this->never()) |
|
22 | + ->method('doSomething'); |
|
23 | + } |
|
24 | + |
|
25 | + public function testMockedMethodIsNeverCalledWithParameter() |
|
26 | + { |
|
27 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
28 | + ->getMock(); |
|
29 | + |
|
30 | + $mock->expects($this->never()) |
|
31 | + ->method('doSomething') |
|
32 | + ->with('someArg'); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @doesNotPerformAssertions |
|
37 | + */ |
|
38 | + public function testMockedMethodIsNotCalledWhenExpectsAnyWithParameter() |
|
39 | + { |
|
40 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
41 | + ->getMock(); |
|
42 | + |
|
43 | + $mock->expects($this->any()) |
|
44 | + ->method('doSomethingElse') |
|
45 | + ->with('someArg'); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * @doesNotPerformAssertions |
|
50 | + */ |
|
51 | + public function testMockedMethodIsNotCalledWhenMethodSpecifiedDirectlyWithParameter() |
|
52 | + { |
|
53 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
54 | + ->getMock(); |
|
55 | + |
|
56 | + $mock->method('doSomethingElse') |
|
57 | + ->with('someArg'); |
|
58 | + } |
|
59 | + |
|
60 | + public function testMockedMethodIsCalledAtLeastOnce() |
|
61 | + { |
|
62 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
63 | + ->getMock(); |
|
64 | + |
|
65 | + $mock->expects($this->atLeastOnce()) |
|
66 | + ->method('doSomething'); |
|
67 | + |
|
68 | + $mock->doSomething(); |
|
69 | + } |
|
70 | + |
|
71 | + public function testMockedMethodIsCalledAtLeastOnce2() |
|
72 | + { |
|
73 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
74 | + ->getMock(); |
|
75 | + |
|
76 | + $mock->expects($this->atLeastOnce()) |
|
77 | + ->method('doSomething'); |
|
78 | + |
|
79 | + $mock->doSomething(); |
|
80 | + $mock->doSomething(); |
|
81 | + } |
|
82 | + |
|
83 | + public function testMockedMethodIsCalledAtLeastTwice() |
|
84 | + { |
|
85 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
86 | + ->getMock(); |
|
87 | + |
|
88 | + $mock->expects($this->atLeast(2)) |
|
89 | + ->method('doSomething'); |
|
90 | + |
|
91 | + $mock->doSomething(); |
|
92 | + $mock->doSomething(); |
|
93 | + } |
|
94 | + |
|
95 | + public function testMockedMethodIsCalledAtLeastTwice2() |
|
96 | + { |
|
97 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
98 | + ->getMock(); |
|
99 | + |
|
100 | + $mock->expects($this->atLeast(2)) |
|
101 | + ->method('doSomething'); |
|
102 | + |
|
103 | + $mock->doSomething(); |
|
104 | + $mock->doSomething(); |
|
105 | + $mock->doSomething(); |
|
106 | + } |
|
107 | + |
|
108 | + public function testMockedMethodIsCalledAtMostTwice() |
|
109 | + { |
|
110 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
111 | + ->getMock(); |
|
112 | + |
|
113 | + $mock->expects($this->atMost(2)) |
|
114 | + ->method('doSomething'); |
|
115 | + |
|
116 | + $mock->doSomething(); |
|
117 | + $mock->doSomething(); |
|
118 | + } |
|
119 | + |
|
120 | + public function testMockedMethodIsCalledAtMosttTwice2() |
|
121 | + { |
|
122 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
123 | + ->getMock(); |
|
124 | 124 | |
125 | - $mock->expects($this->atMost(2)) |
|
126 | - ->method('doSomething'); |
|
127 | - |
|
128 | - $mock->doSomething(); |
|
129 | - } |
|
130 | - |
|
131 | - public function testMockedMethodIsCalledOnce() |
|
132 | - { |
|
133 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
134 | - ->getMock(); |
|
125 | + $mock->expects($this->atMost(2)) |
|
126 | + ->method('doSomething'); |
|
127 | + |
|
128 | + $mock->doSomething(); |
|
129 | + } |
|
130 | + |
|
131 | + public function testMockedMethodIsCalledOnce() |
|
132 | + { |
|
133 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
134 | + ->getMock(); |
|
135 | 135 | |
136 | - $mock->expects($this->once()) |
|
137 | - ->method('doSomething'); |
|
136 | + $mock->expects($this->once()) |
|
137 | + ->method('doSomething'); |
|
138 | 138 | |
139 | - $mock->doSomething(); |
|
140 | - } |
|
139 | + $mock->doSomething(); |
|
140 | + } |
|
141 | 141 | |
142 | - public function testMockedMethodIsCalledOnceWithParameter() |
|
143 | - { |
|
144 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
145 | - ->getMock(); |
|
142 | + public function testMockedMethodIsCalledOnceWithParameter() |
|
143 | + { |
|
144 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
145 | + ->getMock(); |
|
146 | 146 | |
147 | - $mock->expects($this->once()) |
|
148 | - ->method('doSomethingElse') |
|
149 | - ->with($this->equalTo('something')); |
|
147 | + $mock->expects($this->once()) |
|
148 | + ->method('doSomethingElse') |
|
149 | + ->with($this->equalTo('something')); |
|
150 | 150 | |
151 | - $mock->doSomethingElse('something'); |
|
152 | - } |
|
151 | + $mock->doSomethingElse('something'); |
|
152 | + } |
|
153 | 153 | |
154 | - public function testMockedMethodIsCalledExactly() |
|
155 | - { |
|
156 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
157 | - ->getMock(); |
|
154 | + public function testMockedMethodIsCalledExactly() |
|
155 | + { |
|
156 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
157 | + ->getMock(); |
|
158 | 158 | |
159 | - $mock->expects($this->exactly(2)) |
|
160 | - ->method('doSomething'); |
|
159 | + $mock->expects($this->exactly(2)) |
|
160 | + ->method('doSomething'); |
|
161 | 161 | |
162 | - $mock->doSomething(); |
|
163 | - $mock->doSomething(); |
|
164 | - } |
|
162 | + $mock->doSomething(); |
|
163 | + $mock->doSomething(); |
|
164 | + } |
|
165 | 165 | |
166 | - public function testStubbedException() |
|
167 | - { |
|
168 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
169 | - ->getMock(); |
|
166 | + public function testStubbedException() |
|
167 | + { |
|
168 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
169 | + ->getMock(); |
|
170 | 170 | |
171 | - $mock->expects($this->any()) |
|
172 | - ->method('doSomething') |
|
173 | - ->will($this->throwException(new Exception)); |
|
171 | + $mock->expects($this->any()) |
|
172 | + ->method('doSomething') |
|
173 | + ->will($this->throwException(new Exception)); |
|
174 | 174 | |
175 | - $this->expectException(Exception::class); |
|
175 | + $this->expectException(Exception::class); |
|
176 | 176 | |
177 | - $mock->doSomething(); |
|
178 | - } |
|
177 | + $mock->doSomething(); |
|
178 | + } |
|
179 | 179 | |
180 | - public function testStubbedWillThrowException() |
|
181 | - { |
|
182 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
183 | - ->getMock(); |
|
180 | + public function testStubbedWillThrowException() |
|
181 | + { |
|
182 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
183 | + ->getMock(); |
|
184 | 184 | |
185 | - $mock->expects($this->any()) |
|
186 | - ->method('doSomething') |
|
187 | - ->willThrowException(new Exception); |
|
185 | + $mock->expects($this->any()) |
|
186 | + ->method('doSomething') |
|
187 | + ->willThrowException(new Exception); |
|
188 | 188 | |
189 | - $this->expectException(Exception::class); |
|
189 | + $this->expectException(Exception::class); |
|
190 | 190 | |
191 | - $mock->doSomething(); |
|
192 | - } |
|
191 | + $mock->doSomething(); |
|
192 | + } |
|
193 | 193 | |
194 | - public function testStubbedReturnValue() |
|
195 | - { |
|
196 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
197 | - ->getMock(); |
|
194 | + public function testStubbedReturnValue() |
|
195 | + { |
|
196 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
197 | + ->getMock(); |
|
198 | 198 | |
199 | - $mock->expects($this->any()) |
|
200 | - ->method('doSomething') |
|
201 | - ->will($this->returnValue('something')); |
|
199 | + $mock->expects($this->any()) |
|
200 | + ->method('doSomething') |
|
201 | + ->will($this->returnValue('something')); |
|
202 | 202 | |
203 | - $this->assertEquals('something', $mock->doSomething()); |
|
203 | + $this->assertEquals('something', $mock->doSomething()); |
|
204 | 204 | |
205 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
206 | - ->getMock(); |
|
205 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
206 | + ->getMock(); |
|
207 | 207 | |
208 | - $mock->expects($this->any()) |
|
209 | - ->method('doSomething') |
|
210 | - ->willReturn('something'); |
|
208 | + $mock->expects($this->any()) |
|
209 | + ->method('doSomething') |
|
210 | + ->willReturn('something'); |
|
211 | 211 | |
212 | - $this->assertEquals('something', $mock->doSomething()); |
|
213 | - } |
|
212 | + $this->assertEquals('something', $mock->doSomething()); |
|
213 | + } |
|
214 | 214 | |
215 | - public function testStubbedReturnValueMap() |
|
216 | - { |
|
217 | - $map = [ |
|
218 | - ['a', 'b', 'c', 'd'], |
|
219 | - ['e', 'f', 'g', 'h'] |
|
220 | - ]; |
|
215 | + public function testStubbedReturnValueMap() |
|
216 | + { |
|
217 | + $map = [ |
|
218 | + ['a', 'b', 'c', 'd'], |
|
219 | + ['e', 'f', 'g', 'h'] |
|
220 | + ]; |
|
221 | 221 | |
222 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
223 | - ->getMock(); |
|
222 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
223 | + ->getMock(); |
|
224 | 224 | |
225 | - $mock->expects($this->any()) |
|
226 | - ->method('doSomething') |
|
227 | - ->will($this->returnValueMap($map)); |
|
225 | + $mock->expects($this->any()) |
|
226 | + ->method('doSomething') |
|
227 | + ->will($this->returnValueMap($map)); |
|
228 | 228 | |
229 | - $this->assertEquals('d', $mock->doSomething('a', 'b', 'c')); |
|
230 | - $this->assertEquals('h', $mock->doSomething('e', 'f', 'g')); |
|
231 | - $this->assertEquals(null, $mock->doSomething('foo', 'bar')); |
|
229 | + $this->assertEquals('d', $mock->doSomething('a', 'b', 'c')); |
|
230 | + $this->assertEquals('h', $mock->doSomething('e', 'f', 'g')); |
|
231 | + $this->assertEquals(null, $mock->doSomething('foo', 'bar')); |
|
232 | 232 | |
233 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
234 | - ->getMock(); |
|
233 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
234 | + ->getMock(); |
|
235 | 235 | |
236 | - $mock->expects($this->any()) |
|
237 | - ->method('doSomething') |
|
238 | - ->willReturnMap($map); |
|
236 | + $mock->expects($this->any()) |
|
237 | + ->method('doSomething') |
|
238 | + ->willReturnMap($map); |
|
239 | 239 | |
240 | - $this->assertEquals('d', $mock->doSomething('a', 'b', 'c')); |
|
241 | - $this->assertEquals('h', $mock->doSomething('e', 'f', 'g')); |
|
242 | - $this->assertEquals(null, $mock->doSomething('foo', 'bar')); |
|
243 | - } |
|
240 | + $this->assertEquals('d', $mock->doSomething('a', 'b', 'c')); |
|
241 | + $this->assertEquals('h', $mock->doSomething('e', 'f', 'g')); |
|
242 | + $this->assertEquals(null, $mock->doSomething('foo', 'bar')); |
|
243 | + } |
|
244 | 244 | |
245 | - public function testStubbedReturnArgument() |
|
246 | - { |
|
247 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
248 | - ->getMock(); |
|
245 | + public function testStubbedReturnArgument() |
|
246 | + { |
|
247 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
248 | + ->getMock(); |
|
249 | 249 | |
250 | - $mock->expects($this->any()) |
|
251 | - ->method('doSomething') |
|
252 | - ->will($this->returnArgument(1)); |
|
250 | + $mock->expects($this->any()) |
|
251 | + ->method('doSomething') |
|
252 | + ->will($this->returnArgument(1)); |
|
253 | 253 | |
254 | - $this->assertEquals('b', $mock->doSomething('a', 'b')); |
|
254 | + $this->assertEquals('b', $mock->doSomething('a', 'b')); |
|
255 | 255 | |
256 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
257 | - ->getMock(); |
|
256 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
257 | + ->getMock(); |
|
258 | 258 | |
259 | - $mock->expects($this->any()) |
|
260 | - ->method('doSomething') |
|
261 | - ->willReturnArgument(1); |
|
259 | + $mock->expects($this->any()) |
|
260 | + ->method('doSomething') |
|
261 | + ->willReturnArgument(1); |
|
262 | 262 | |
263 | - $this->assertEquals('b', $mock->doSomething('a', 'b')); |
|
264 | - } |
|
263 | + $this->assertEquals('b', $mock->doSomething('a', 'b')); |
|
264 | + } |
|
265 | 265 | |
266 | - public function testFunctionCallback() |
|
267 | - { |
|
268 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
269 | - ->setMethods(['doSomething']) |
|
270 | - ->getMock(); |
|
266 | + public function testFunctionCallback() |
|
267 | + { |
|
268 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
269 | + ->setMethods(['doSomething']) |
|
270 | + ->getMock(); |
|
271 | 271 | |
272 | - $mock->expects($this->once()) |
|
273 | - ->method('doSomething') |
|
274 | - ->will($this->returnCallback('functionCallback')); |
|
272 | + $mock->expects($this->once()) |
|
273 | + ->method('doSomething') |
|
274 | + ->will($this->returnCallback('functionCallback')); |
|
275 | 275 | |
276 | - $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); |
|
276 | + $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); |
|
277 | 277 | |
278 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
279 | - ->setMethods(['doSomething']) |
|
280 | - ->getMock(); |
|
278 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
279 | + ->setMethods(['doSomething']) |
|
280 | + ->getMock(); |
|
281 | 281 | |
282 | - $mock->expects($this->once()) |
|
283 | - ->method('doSomething') |
|
284 | - ->willReturnCallback('functionCallback'); |
|
282 | + $mock->expects($this->once()) |
|
283 | + ->method('doSomething') |
|
284 | + ->willReturnCallback('functionCallback'); |
|
285 | 285 | |
286 | - $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); |
|
287 | - } |
|
286 | + $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); |
|
287 | + } |
|
288 | 288 | |
289 | - public function testStubbedReturnSelf() |
|
290 | - { |
|
291 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
292 | - ->getMock(); |
|
289 | + public function testStubbedReturnSelf() |
|
290 | + { |
|
291 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
292 | + ->getMock(); |
|
293 | 293 | |
294 | - $mock->expects($this->any()) |
|
295 | - ->method('doSomething') |
|
296 | - ->will($this->returnSelf()); |
|
294 | + $mock->expects($this->any()) |
|
295 | + ->method('doSomething') |
|
296 | + ->will($this->returnSelf()); |
|
297 | 297 | |
298 | - $this->assertEquals($mock, $mock->doSomething()); |
|
298 | + $this->assertEquals($mock, $mock->doSomething()); |
|
299 | 299 | |
300 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
301 | - ->getMock(); |
|
300 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
301 | + ->getMock(); |
|
302 | 302 | |
303 | - $mock->expects($this->any()) |
|
304 | - ->method('doSomething') |
|
305 | - ->willReturnSelf(); |
|
306 | - |
|
307 | - $this->assertEquals($mock, $mock->doSomething()); |
|
308 | - } |
|
309 | - |
|
310 | - public function testStubbedReturnOnConsecutiveCalls() |
|
311 | - { |
|
312 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
313 | - ->getMock(); |
|
303 | + $mock->expects($this->any()) |
|
304 | + ->method('doSomething') |
|
305 | + ->willReturnSelf(); |
|
306 | + |
|
307 | + $this->assertEquals($mock, $mock->doSomething()); |
|
308 | + } |
|
309 | + |
|
310 | + public function testStubbedReturnOnConsecutiveCalls() |
|
311 | + { |
|
312 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
313 | + ->getMock(); |
|
314 | 314 | |
315 | - $mock->expects($this->any()) |
|
316 | - ->method('doSomething') |
|
317 | - ->will($this->onConsecutiveCalls('a', 'b', 'c')); |
|
318 | - |
|
319 | - $this->assertEquals('a', $mock->doSomething()); |
|
320 | - $this->assertEquals('b', $mock->doSomething()); |
|
321 | - $this->assertEquals('c', $mock->doSomething()); |
|
322 | - |
|
323 | - $mock = $this->getMockBuilder(AnInterface::class) |
|
324 | - ->getMock(); |
|
325 | - |
|
326 | - $mock->expects($this->any()) |
|
327 | - ->method('doSomething') |
|
328 | - ->willReturnOnConsecutiveCalls('a', 'b', 'c'); |
|
329 | - |
|
330 | - $this->assertEquals('a', $mock->doSomething()); |
|
331 | - $this->assertEquals('b', $mock->doSomething()); |
|
332 | - $this->assertEquals('c', $mock->doSomething()); |
|
333 | - } |
|
334 | - |
|
335 | - public function testStaticMethodCallback() |
|
336 | - { |
|
337 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
338 | - ->setMethods(['doSomething']) |
|
339 | - ->getMock(); |
|
340 | - |
|
341 | - $mock->expects($this->once()) |
|
342 | - ->method('doSomething') |
|
343 | - ->will($this->returnCallback(['MethodCallback', 'staticCallback'])); |
|
344 | - |
|
345 | - $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); |
|
346 | - } |
|
347 | - |
|
348 | - public function testPublicMethodCallback() |
|
349 | - { |
|
350 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
351 | - ->setMethods(['doSomething']) |
|
352 | - ->getMock(); |
|
353 | - |
|
354 | - $mock->expects($this->once()) |
|
355 | - ->method('doSomething') |
|
356 | - ->will($this->returnCallback([new MethodCallback, 'nonStaticCallback'])); |
|
357 | - |
|
358 | - $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); |
|
359 | - } |
|
360 | - |
|
361 | - public function testMockClassOnlyGeneratedOnce() |
|
362 | - { |
|
363 | - $mock1 = $this->getMockBuilder(AnInterface::class) |
|
364 | - ->getMock(); |
|
365 | - |
|
366 | - $mock2 = $this->getMockBuilder(AnInterface::class) |
|
367 | - ->getMock(); |
|
368 | - |
|
369 | - $this->assertEquals(get_class($mock1), get_class($mock2)); |
|
370 | - } |
|
371 | - |
|
372 | - public function testMockClassDifferentForPartialMocks() |
|
373 | - { |
|
374 | - $mock1 = $this->getMockBuilder(PartialMockTestClass::class) |
|
375 | - ->getMock(); |
|
376 | - |
|
377 | - $mock2 = $this->getMockBuilder(PartialMockTestClass::class) |
|
378 | - ->setMethods(['doSomething']) |
|
379 | - ->getMock(); |
|
380 | - |
|
381 | - $mock3 = $this->getMockBuilder(PartialMockTestClass::class) |
|
382 | - ->setMethods(['doSomething']) |
|
383 | - ->getMock(); |
|
384 | - |
|
385 | - $mock4 = $this->getMockBuilder(PartialMockTestClass::class) |
|
386 | - ->setMethods(['doAnotherThing']) |
|
387 | - ->getMock(); |
|
388 | - |
|
389 | - $mock5 = $this->getMockBuilder(PartialMockTestClass::class) |
|
390 | - ->setMethods(['doAnotherThing']) |
|
391 | - ->getMock(); |
|
392 | - |
|
393 | - $this->assertNotEquals(get_class($mock1), get_class($mock2)); |
|
394 | - $this->assertNotEquals(get_class($mock1), get_class($mock3)); |
|
395 | - $this->assertNotEquals(get_class($mock1), get_class($mock4)); |
|
396 | - $this->assertNotEquals(get_class($mock1), get_class($mock5)); |
|
397 | - $this->assertEquals(get_class($mock2), get_class($mock3)); |
|
398 | - $this->assertNotEquals(get_class($mock2), get_class($mock4)); |
|
399 | - $this->assertNotEquals(get_class($mock2), get_class($mock5)); |
|
400 | - $this->assertEquals(get_class($mock4), get_class($mock5)); |
|
401 | - } |
|
402 | - |
|
403 | - public function testMockClassStoreOverrulable() |
|
404 | - { |
|
405 | - $mock1 = $this->getMockBuilder(PartialMockTestClass::class) |
|
406 | - ->getMock(); |
|
407 | - |
|
408 | - $mock2 = $this->getMockBuilder(PartialMockTestClass::class) |
|
409 | - ->setMockClassName('MyMockClassNameForPartialMockTestClass1') |
|
410 | - ->getMock(); |
|
411 | - |
|
412 | - $mock3 = $this->getMockBuilder(PartialMockTestClass::class) |
|
413 | - ->getMock(); |
|
414 | - |
|
415 | - $mock4 = $this->getMockBuilder(PartialMockTestClass::class) |
|
416 | - ->setMethods(['doSomething']) |
|
417 | - ->setMockClassName('AnotherMockClassNameForPartialMockTestClass') |
|
418 | - ->getMock(); |
|
419 | - |
|
420 | - $mock5 = $this->getMockBuilder(PartialMockTestClass::class) |
|
421 | - ->setMockClassName('MyMockClassNameForPartialMockTestClass2') |
|
422 | - ->getMock(); |
|
423 | - |
|
424 | - $this->assertNotEquals(get_class($mock1), get_class($mock2)); |
|
425 | - $this->assertEquals(get_class($mock1), get_class($mock3)); |
|
426 | - $this->assertNotEquals(get_class($mock1), get_class($mock4)); |
|
427 | - $this->assertNotEquals(get_class($mock2), get_class($mock3)); |
|
428 | - $this->assertNotEquals(get_class($mock2), get_class($mock4)); |
|
429 | - $this->assertNotEquals(get_class($mock2), get_class($mock5)); |
|
430 | - $this->assertNotEquals(get_class($mock3), get_class($mock4)); |
|
431 | - $this->assertNotEquals(get_class($mock3), get_class($mock5)); |
|
432 | - $this->assertNotEquals(get_class($mock4), get_class($mock5)); |
|
433 | - } |
|
434 | - |
|
435 | - public function testGetMockWithFixedClassNameCanProduceTheSameMockTwice() |
|
436 | - { |
|
437 | - $mock = $this->getMockBuilder(stdClass::class)->setMockClassName('FixedName')->getMock(); |
|
438 | - $mock = $this->getMockBuilder(stdClass::class)->setMockClassName('FixedName')->getMock(); |
|
439 | - $this->assertInstanceOf(stdClass::class, $mock); |
|
440 | - } |
|
441 | - |
|
442 | - public function testOriginalConstructorSettingConsidered() |
|
443 | - { |
|
444 | - $mock1 = $this->getMockBuilder(PartialMockTestClass::class) |
|
445 | - ->getMock(); |
|
446 | - |
|
447 | - $mock2 = $this->getMockBuilder(PartialMockTestClass::class) |
|
448 | - ->disableOriginalConstructor() |
|
449 | - ->getMock(); |
|
450 | - |
|
451 | - $this->assertTrue($mock1->constructorCalled); |
|
452 | - $this->assertFalse($mock2->constructorCalled); |
|
453 | - } |
|
454 | - |
|
455 | - public function testOriginalCloneSettingConsidered() |
|
456 | - { |
|
457 | - $mock1 = $this->getMockBuilder(PartialMockTestClass::class) |
|
458 | - ->getMock(); |
|
459 | - |
|
460 | - $mock2 = $this->getMockBuilder(PartialMockTestClass::class) |
|
461 | - ->disableOriginalClone() |
|
462 | - ->getMock(); |
|
463 | - |
|
464 | - $this->assertNotEquals(get_class($mock1), get_class($mock2)); |
|
465 | - } |
|
466 | - |
|
467 | - public function testGetMockForAbstractClass() |
|
468 | - { |
|
469 | - $mock = $this->getMockBuilder(AbstractMockTestClass::class) |
|
470 | - ->getMock(); |
|
471 | - |
|
472 | - $mock->expects($this->never()) |
|
473 | - ->method('doSomething'); |
|
474 | - } |
|
475 | - |
|
476 | - /** |
|
477 | - * @dataProvider traversableProvider |
|
478 | - */ |
|
479 | - public function testGetMockForTraversable($type) |
|
480 | - { |
|
481 | - $mock = $this->getMockBuilder($type) |
|
482 | - ->getMock(); |
|
483 | - |
|
484 | - $this->assertInstanceOf(Traversable::class, $mock); |
|
485 | - } |
|
486 | - |
|
487 | - public function testMultipleInterfacesCanBeMockedInSingleObject() |
|
488 | - { |
|
489 | - $mock = $this->getMockBuilder([AnInterface::class, AnotherInterface::class]) |
|
490 | - ->getMock(); |
|
491 | - |
|
492 | - $this->assertInstanceOf(AnInterface::class, $mock); |
|
493 | - $this->assertInstanceOf(AnotherInterface::class, $mock); |
|
494 | - } |
|
495 | - |
|
496 | - public function testGetMockForTrait() |
|
497 | - { |
|
498 | - $mock = $this->getMockForTrait(AbstractTrait::class); |
|
499 | - |
|
500 | - $mock->expects($this->never()) |
|
501 | - ->method('doSomething'); |
|
502 | - |
|
503 | - $parent = get_parent_class($mock); |
|
504 | - $traits = class_uses($parent, false); |
|
505 | - |
|
506 | - $this->assertContains(AbstractTrait::class, $traits); |
|
507 | - } |
|
508 | - |
|
509 | - public function testClonedMockObjectShouldStillEqualTheOriginal() |
|
510 | - { |
|
511 | - $a = $this->getMockBuilder(stdClass::class) |
|
512 | - ->getMock(); |
|
513 | - |
|
514 | - $b = clone $a; |
|
515 | - |
|
516 | - $this->assertEquals($a, $b); |
|
517 | - } |
|
518 | - |
|
519 | - public function testMockObjectsConstructedIndepentantlyShouldBeEqual() |
|
520 | - { |
|
521 | - $a = $this->getMockBuilder(stdClass::class) |
|
522 | - ->getMock(); |
|
523 | - |
|
524 | - $b = $this->getMockBuilder(stdClass::class) |
|
525 | - ->getMock(); |
|
526 | - |
|
527 | - $this->assertEquals($a, $b); |
|
528 | - } |
|
529 | - |
|
530 | - public function testMockObjectsConstructedIndepentantlyShouldNotBeTheSame() |
|
531 | - { |
|
532 | - $a = $this->getMockBuilder(stdClass::class) |
|
533 | - ->getMock(); |
|
534 | - |
|
535 | - $b = $this->getMockBuilder(stdClass::class) |
|
536 | - ->getMock(); |
|
537 | - |
|
538 | - $this->assertNotSame($a, $b); |
|
539 | - } |
|
540 | - |
|
541 | - public function testClonedMockObjectCanBeUsedInPlaceOfOriginalOne() |
|
542 | - { |
|
543 | - $x = $this->getMockBuilder(stdClass::class) |
|
544 | - ->getMock(); |
|
545 | - |
|
546 | - $y = clone $x; |
|
547 | - |
|
548 | - $mock = $this->getMockBuilder(stdClass::class) |
|
549 | - ->setMethods(['foo']) |
|
550 | - ->getMock(); |
|
551 | - |
|
552 | - $mock->expects($this->once()) |
|
553 | - ->method('foo') |
|
554 | - ->with($this->equalTo($x)); |
|
555 | - |
|
556 | - $mock->foo($y); |
|
557 | - } |
|
315 | + $mock->expects($this->any()) |
|
316 | + ->method('doSomething') |
|
317 | + ->will($this->onConsecutiveCalls('a', 'b', 'c')); |
|
318 | + |
|
319 | + $this->assertEquals('a', $mock->doSomething()); |
|
320 | + $this->assertEquals('b', $mock->doSomething()); |
|
321 | + $this->assertEquals('c', $mock->doSomething()); |
|
322 | + |
|
323 | + $mock = $this->getMockBuilder(AnInterface::class) |
|
324 | + ->getMock(); |
|
325 | + |
|
326 | + $mock->expects($this->any()) |
|
327 | + ->method('doSomething') |
|
328 | + ->willReturnOnConsecutiveCalls('a', 'b', 'c'); |
|
329 | + |
|
330 | + $this->assertEquals('a', $mock->doSomething()); |
|
331 | + $this->assertEquals('b', $mock->doSomething()); |
|
332 | + $this->assertEquals('c', $mock->doSomething()); |
|
333 | + } |
|
334 | + |
|
335 | + public function testStaticMethodCallback() |
|
336 | + { |
|
337 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
338 | + ->setMethods(['doSomething']) |
|
339 | + ->getMock(); |
|
340 | + |
|
341 | + $mock->expects($this->once()) |
|
342 | + ->method('doSomething') |
|
343 | + ->will($this->returnCallback(['MethodCallback', 'staticCallback'])); |
|
344 | + |
|
345 | + $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); |
|
346 | + } |
|
347 | + |
|
348 | + public function testPublicMethodCallback() |
|
349 | + { |
|
350 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
351 | + ->setMethods(['doSomething']) |
|
352 | + ->getMock(); |
|
353 | + |
|
354 | + $mock->expects($this->once()) |
|
355 | + ->method('doSomething') |
|
356 | + ->will($this->returnCallback([new MethodCallback, 'nonStaticCallback'])); |
|
357 | + |
|
358 | + $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); |
|
359 | + } |
|
360 | + |
|
361 | + public function testMockClassOnlyGeneratedOnce() |
|
362 | + { |
|
363 | + $mock1 = $this->getMockBuilder(AnInterface::class) |
|
364 | + ->getMock(); |
|
365 | + |
|
366 | + $mock2 = $this->getMockBuilder(AnInterface::class) |
|
367 | + ->getMock(); |
|
368 | + |
|
369 | + $this->assertEquals(get_class($mock1), get_class($mock2)); |
|
370 | + } |
|
371 | + |
|
372 | + public function testMockClassDifferentForPartialMocks() |
|
373 | + { |
|
374 | + $mock1 = $this->getMockBuilder(PartialMockTestClass::class) |
|
375 | + ->getMock(); |
|
376 | + |
|
377 | + $mock2 = $this->getMockBuilder(PartialMockTestClass::class) |
|
378 | + ->setMethods(['doSomething']) |
|
379 | + ->getMock(); |
|
380 | + |
|
381 | + $mock3 = $this->getMockBuilder(PartialMockTestClass::class) |
|
382 | + ->setMethods(['doSomething']) |
|
383 | + ->getMock(); |
|
384 | + |
|
385 | + $mock4 = $this->getMockBuilder(PartialMockTestClass::class) |
|
386 | + ->setMethods(['doAnotherThing']) |
|
387 | + ->getMock(); |
|
388 | + |
|
389 | + $mock5 = $this->getMockBuilder(PartialMockTestClass::class) |
|
390 | + ->setMethods(['doAnotherThing']) |
|
391 | + ->getMock(); |
|
392 | + |
|
393 | + $this->assertNotEquals(get_class($mock1), get_class($mock2)); |
|
394 | + $this->assertNotEquals(get_class($mock1), get_class($mock3)); |
|
395 | + $this->assertNotEquals(get_class($mock1), get_class($mock4)); |
|
396 | + $this->assertNotEquals(get_class($mock1), get_class($mock5)); |
|
397 | + $this->assertEquals(get_class($mock2), get_class($mock3)); |
|
398 | + $this->assertNotEquals(get_class($mock2), get_class($mock4)); |
|
399 | + $this->assertNotEquals(get_class($mock2), get_class($mock5)); |
|
400 | + $this->assertEquals(get_class($mock4), get_class($mock5)); |
|
401 | + } |
|
402 | + |
|
403 | + public function testMockClassStoreOverrulable() |
|
404 | + { |
|
405 | + $mock1 = $this->getMockBuilder(PartialMockTestClass::class) |
|
406 | + ->getMock(); |
|
407 | + |
|
408 | + $mock2 = $this->getMockBuilder(PartialMockTestClass::class) |
|
409 | + ->setMockClassName('MyMockClassNameForPartialMockTestClass1') |
|
410 | + ->getMock(); |
|
411 | + |
|
412 | + $mock3 = $this->getMockBuilder(PartialMockTestClass::class) |
|
413 | + ->getMock(); |
|
414 | + |
|
415 | + $mock4 = $this->getMockBuilder(PartialMockTestClass::class) |
|
416 | + ->setMethods(['doSomething']) |
|
417 | + ->setMockClassName('AnotherMockClassNameForPartialMockTestClass') |
|
418 | + ->getMock(); |
|
419 | + |
|
420 | + $mock5 = $this->getMockBuilder(PartialMockTestClass::class) |
|
421 | + ->setMockClassName('MyMockClassNameForPartialMockTestClass2') |
|
422 | + ->getMock(); |
|
423 | + |
|
424 | + $this->assertNotEquals(get_class($mock1), get_class($mock2)); |
|
425 | + $this->assertEquals(get_class($mock1), get_class($mock3)); |
|
426 | + $this->assertNotEquals(get_class($mock1), get_class($mock4)); |
|
427 | + $this->assertNotEquals(get_class($mock2), get_class($mock3)); |
|
428 | + $this->assertNotEquals(get_class($mock2), get_class($mock4)); |
|
429 | + $this->assertNotEquals(get_class($mock2), get_class($mock5)); |
|
430 | + $this->assertNotEquals(get_class($mock3), get_class($mock4)); |
|
431 | + $this->assertNotEquals(get_class($mock3), get_class($mock5)); |
|
432 | + $this->assertNotEquals(get_class($mock4), get_class($mock5)); |
|
433 | + } |
|
434 | + |
|
435 | + public function testGetMockWithFixedClassNameCanProduceTheSameMockTwice() |
|
436 | + { |
|
437 | + $mock = $this->getMockBuilder(stdClass::class)->setMockClassName('FixedName')->getMock(); |
|
438 | + $mock = $this->getMockBuilder(stdClass::class)->setMockClassName('FixedName')->getMock(); |
|
439 | + $this->assertInstanceOf(stdClass::class, $mock); |
|
440 | + } |
|
441 | + |
|
442 | + public function testOriginalConstructorSettingConsidered() |
|
443 | + { |
|
444 | + $mock1 = $this->getMockBuilder(PartialMockTestClass::class) |
|
445 | + ->getMock(); |
|
446 | + |
|
447 | + $mock2 = $this->getMockBuilder(PartialMockTestClass::class) |
|
448 | + ->disableOriginalConstructor() |
|
449 | + ->getMock(); |
|
450 | + |
|
451 | + $this->assertTrue($mock1->constructorCalled); |
|
452 | + $this->assertFalse($mock2->constructorCalled); |
|
453 | + } |
|
454 | + |
|
455 | + public function testOriginalCloneSettingConsidered() |
|
456 | + { |
|
457 | + $mock1 = $this->getMockBuilder(PartialMockTestClass::class) |
|
458 | + ->getMock(); |
|
459 | + |
|
460 | + $mock2 = $this->getMockBuilder(PartialMockTestClass::class) |
|
461 | + ->disableOriginalClone() |
|
462 | + ->getMock(); |
|
463 | + |
|
464 | + $this->assertNotEquals(get_class($mock1), get_class($mock2)); |
|
465 | + } |
|
466 | + |
|
467 | + public function testGetMockForAbstractClass() |
|
468 | + { |
|
469 | + $mock = $this->getMockBuilder(AbstractMockTestClass::class) |
|
470 | + ->getMock(); |
|
471 | + |
|
472 | + $mock->expects($this->never()) |
|
473 | + ->method('doSomething'); |
|
474 | + } |
|
475 | + |
|
476 | + /** |
|
477 | + * @dataProvider traversableProvider |
|
478 | + */ |
|
479 | + public function testGetMockForTraversable($type) |
|
480 | + { |
|
481 | + $mock = $this->getMockBuilder($type) |
|
482 | + ->getMock(); |
|
483 | + |
|
484 | + $this->assertInstanceOf(Traversable::class, $mock); |
|
485 | + } |
|
486 | + |
|
487 | + public function testMultipleInterfacesCanBeMockedInSingleObject() |
|
488 | + { |
|
489 | + $mock = $this->getMockBuilder([AnInterface::class, AnotherInterface::class]) |
|
490 | + ->getMock(); |
|
491 | + |
|
492 | + $this->assertInstanceOf(AnInterface::class, $mock); |
|
493 | + $this->assertInstanceOf(AnotherInterface::class, $mock); |
|
494 | + } |
|
495 | + |
|
496 | + public function testGetMockForTrait() |
|
497 | + { |
|
498 | + $mock = $this->getMockForTrait(AbstractTrait::class); |
|
499 | + |
|
500 | + $mock->expects($this->never()) |
|
501 | + ->method('doSomething'); |
|
502 | + |
|
503 | + $parent = get_parent_class($mock); |
|
504 | + $traits = class_uses($parent, false); |
|
505 | + |
|
506 | + $this->assertContains(AbstractTrait::class, $traits); |
|
507 | + } |
|
508 | + |
|
509 | + public function testClonedMockObjectShouldStillEqualTheOriginal() |
|
510 | + { |
|
511 | + $a = $this->getMockBuilder(stdClass::class) |
|
512 | + ->getMock(); |
|
513 | + |
|
514 | + $b = clone $a; |
|
515 | + |
|
516 | + $this->assertEquals($a, $b); |
|
517 | + } |
|
518 | + |
|
519 | + public function testMockObjectsConstructedIndepentantlyShouldBeEqual() |
|
520 | + { |
|
521 | + $a = $this->getMockBuilder(stdClass::class) |
|
522 | + ->getMock(); |
|
523 | + |
|
524 | + $b = $this->getMockBuilder(stdClass::class) |
|
525 | + ->getMock(); |
|
526 | + |
|
527 | + $this->assertEquals($a, $b); |
|
528 | + } |
|
529 | + |
|
530 | + public function testMockObjectsConstructedIndepentantlyShouldNotBeTheSame() |
|
531 | + { |
|
532 | + $a = $this->getMockBuilder(stdClass::class) |
|
533 | + ->getMock(); |
|
534 | + |
|
535 | + $b = $this->getMockBuilder(stdClass::class) |
|
536 | + ->getMock(); |
|
537 | + |
|
538 | + $this->assertNotSame($a, $b); |
|
539 | + } |
|
540 | + |
|
541 | + public function testClonedMockObjectCanBeUsedInPlaceOfOriginalOne() |
|
542 | + { |
|
543 | + $x = $this->getMockBuilder(stdClass::class) |
|
544 | + ->getMock(); |
|
545 | + |
|
546 | + $y = clone $x; |
|
547 | + |
|
548 | + $mock = $this->getMockBuilder(stdClass::class) |
|
549 | + ->setMethods(['foo']) |
|
550 | + ->getMock(); |
|
551 | + |
|
552 | + $mock->expects($this->once()) |
|
553 | + ->method('foo') |
|
554 | + ->with($this->equalTo($x)); |
|
555 | + |
|
556 | + $mock->foo($y); |
|
557 | + } |
|
558 | 558 | |
559 | - public function testClonedMockObjectIsNotIdenticalToOriginalOne() |
|
560 | - { |
|
561 | - $x = $this->getMockBuilder(stdClass::class) |
|
562 | - ->getMock(); |
|
563 | - |
|
564 | - $y = clone $x; |
|
565 | - |
|
566 | - $mock = $this->getMockBuilder(stdClass::class) |
|
567 | - ->setMethods(['foo']) |
|
568 | - ->getMock(); |
|
569 | - |
|
570 | - $mock->expects($this->once()) |
|
571 | - ->method('foo') |
|
572 | - ->with($this->logicalNot($this->identicalTo($x))); |
|
573 | - |
|
574 | - $mock->foo($y); |
|
575 | - } |
|
576 | - |
|
577 | - public function testObjectMethodCallWithArgumentCloningEnabled() |
|
578 | - { |
|
579 | - $expectedObject = new stdClass; |
|
580 | - |
|
581 | - $mock = $this->getMockBuilder('SomeClass') |
|
582 | - ->setMethods(['doSomethingElse']) |
|
583 | - ->enableArgumentCloning() |
|
584 | - ->getMock(); |
|
585 | - |
|
586 | - $actualArguments = []; |
|
587 | - |
|
588 | - $mock->expects($this->any()) |
|
589 | - ->method('doSomethingElse') |
|
590 | - ->will( |
|
591 | - $this->returnCallback( |
|
592 | - function () use (&$actualArguments) { |
|
593 | - $actualArguments = func_get_args(); |
|
594 | - } |
|
595 | - ) |
|
596 | - ); |
|
597 | - |
|
598 | - $mock->doSomethingElse($expectedObject); |
|
599 | - |
|
600 | - $this->assertEquals(1, count($actualArguments)); |
|
601 | - $this->assertEquals($expectedObject, $actualArguments[0]); |
|
602 | - $this->assertNotSame($expectedObject, $actualArguments[0]); |
|
603 | - } |
|
604 | - |
|
605 | - public function testObjectMethodCallWithArgumentCloningDisabled() |
|
606 | - { |
|
607 | - $expectedObject = new stdClass; |
|
608 | - |
|
609 | - $mock = $this->getMockBuilder('SomeClass') |
|
610 | - ->setMethods(['doSomethingElse']) |
|
611 | - ->disableArgumentCloning() |
|
612 | - ->getMock(); |
|
613 | - |
|
614 | - $actualArguments = []; |
|
615 | - |
|
616 | - $mock->expects($this->any()) |
|
617 | - ->method('doSomethingElse') |
|
618 | - ->will( |
|
619 | - $this->returnCallback( |
|
620 | - function () use (&$actualArguments) { |
|
621 | - $actualArguments = func_get_args(); |
|
622 | - } |
|
623 | - ) |
|
624 | - ); |
|
625 | - |
|
626 | - $mock->doSomethingElse($expectedObject); |
|
627 | - |
|
628 | - $this->assertEquals(1, count($actualArguments)); |
|
629 | - $this->assertSame($expectedObject, $actualArguments[0]); |
|
630 | - } |
|
631 | - |
|
632 | - public function testArgumentCloningOptionGeneratesUniqueMock() |
|
633 | - { |
|
634 | - $mockWithCloning = $this->getMockBuilder('SomeClass') |
|
635 | - ->setMethods(['doSomethingElse']) |
|
636 | - ->enableArgumentCloning() |
|
637 | - ->getMock(); |
|
638 | - |
|
639 | - $mockWithoutCloning = $this->getMockBuilder('SomeClass') |
|
640 | - ->setMethods(['doSomethingElse']) |
|
641 | - ->disableArgumentCloning() |
|
642 | - ->getMock(); |
|
643 | - |
|
644 | - $this->assertNotEquals($mockWithCloning, $mockWithoutCloning); |
|
645 | - } |
|
646 | - |
|
647 | - public function testVerificationOfMethodNameFailsWithoutParameters() |
|
648 | - { |
|
649 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
650 | - ->setMethods(['right', 'wrong']) |
|
651 | - ->getMock(); |
|
652 | - |
|
653 | - $mock->expects($this->once()) |
|
654 | - ->method('right'); |
|
655 | - |
|
656 | - $mock->wrong(); |
|
657 | - |
|
658 | - try { |
|
659 | - $mock->__phpunit_verify(); |
|
660 | - $this->fail('Expected exception'); |
|
661 | - } catch (ExpectationFailedException $e) { |
|
662 | - $this->assertSame( |
|
663 | - "Expectation failed for method name is equal to <string:right> when invoked 1 time(s).\n" |
|
664 | - . "Method was expected to be called 1 times, actually called 0 times.\n", |
|
665 | - $e->getMessage() |
|
666 | - ); |
|
667 | - } |
|
668 | - |
|
669 | - $this->resetMockObjects(); |
|
670 | - } |
|
671 | - |
|
672 | - public function testVerificationOfMethodNameFailsWithParameters() |
|
673 | - { |
|
674 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
675 | - ->setMethods(['right', 'wrong']) |
|
676 | - ->getMock(); |
|
677 | - |
|
678 | - $mock->expects($this->once()) |
|
679 | - ->method('right'); |
|
680 | - |
|
681 | - $mock->wrong(); |
|
682 | - |
|
683 | - try { |
|
684 | - $mock->__phpunit_verify(); |
|
685 | - $this->fail('Expected exception'); |
|
686 | - } catch (ExpectationFailedException $e) { |
|
687 | - $this->assertSame( |
|
688 | - "Expectation failed for method name is equal to <string:right> when invoked 1 time(s).\n" |
|
689 | - . "Method was expected to be called 1 times, actually called 0 times.\n", |
|
690 | - $e->getMessage() |
|
691 | - ); |
|
692 | - } |
|
693 | - |
|
694 | - $this->resetMockObjects(); |
|
695 | - } |
|
696 | - |
|
697 | - public function testVerificationOfMethodNameFailsWithWrongParameters() |
|
698 | - { |
|
699 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
700 | - ->setMethods(['right', 'wrong']) |
|
701 | - ->getMock(); |
|
702 | - |
|
703 | - $mock->expects($this->once()) |
|
704 | - ->method('right') |
|
705 | - ->with(['first', 'second']); |
|
706 | - |
|
707 | - try { |
|
708 | - $mock->right(['second']); |
|
709 | - } catch (ExpectationFailedException $e) { |
|
710 | - $this->assertSame( |
|
711 | - "Expectation failed for method name is equal to <string:right> when invoked 1 time(s)\n" |
|
712 | - . "Parameter 0 for invocation SomeClass::right(Array (...)) does not match expected value.\n" |
|
713 | - . 'Failed asserting that two arrays are equal.', |
|
714 | - $e->getMessage() |
|
715 | - ); |
|
716 | - } |
|
717 | - |
|
718 | - try { |
|
719 | - $mock->__phpunit_verify(); |
|
720 | - $this->fail('Expected exception'); |
|
721 | - } catch (ExpectationFailedException $e) { |
|
722 | - $this->assertSame( |
|
723 | - "Expectation failed for method name is equal to <string:right> when invoked 1 time(s).\n" |
|
724 | - . "Parameter 0 for invocation SomeClass::right(Array (...)) does not match expected value.\n" |
|
725 | - . "Failed asserting that two arrays are equal.\n" |
|
726 | - . "--- Expected\n" |
|
727 | - . "+++ Actual\n" |
|
728 | - . "@@ @@\n" |
|
729 | - . " Array (\n" |
|
730 | - . "- 0 => 'first'\n" |
|
731 | - . "- 1 => 'second'\n" |
|
732 | - . "+ 0 => 'second'\n" |
|
733 | - . " )\n", |
|
734 | - $e->getMessage() |
|
735 | - ); |
|
736 | - } |
|
737 | - |
|
738 | - $this->resetMockObjects(); |
|
739 | - } |
|
740 | - |
|
741 | - public function testVerificationOfNeverFailsWithEmptyParameters() |
|
742 | - { |
|
743 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
744 | - ->setMethods(['right', 'wrong']) |
|
745 | - ->getMock(); |
|
746 | - |
|
747 | - $mock->expects($this->never()) |
|
748 | - ->method('right') |
|
749 | - ->with(); |
|
750 | - |
|
751 | - try { |
|
752 | - $mock->right(); |
|
753 | - $this->fail('Expected exception'); |
|
754 | - } catch (ExpectationFailedException $e) { |
|
755 | - $this->assertSame( |
|
756 | - 'SomeClass::right() was not expected to be called.', |
|
757 | - $e->getMessage() |
|
758 | - ); |
|
759 | - } |
|
760 | - |
|
761 | - $this->resetMockObjects(); |
|
762 | - } |
|
763 | - |
|
764 | - public function testVerificationOfNeverFailsWithAnyParameters() |
|
765 | - { |
|
766 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
767 | - ->setMethods(['right', 'wrong']) |
|
768 | - ->getMock(); |
|
769 | - |
|
770 | - $mock->expects($this->never()) |
|
771 | - ->method('right') |
|
772 | - ->withAnyParameters(); |
|
773 | - |
|
774 | - try { |
|
775 | - $mock->right(); |
|
776 | - $this->fail('Expected exception'); |
|
777 | - } catch (ExpectationFailedException $e) { |
|
778 | - $this->assertSame( |
|
779 | - 'SomeClass::right() was not expected to be called.', |
|
780 | - $e->getMessage() |
|
781 | - ); |
|
782 | - } |
|
783 | - |
|
784 | - $this->resetMockObjects(); |
|
785 | - } |
|
786 | - |
|
787 | - public function testWithAnythingInsteadOfWithAnyParameters() |
|
788 | - { |
|
789 | - $mock = $this->getMockBuilder(SomeClass::class) |
|
790 | - ->setMethods(['right', 'wrong']) |
|
791 | - ->getMock(); |
|
792 | - |
|
793 | - $mock->expects($this->once()) |
|
794 | - ->method('right') |
|
795 | - ->with($this->anything()); |
|
796 | - |
|
797 | - try { |
|
798 | - $mock->right(); |
|
799 | - $this->fail('Expected exception'); |
|
800 | - } catch (ExpectationFailedException $e) { |
|
801 | - $this->assertSame( |
|
802 | - "Expectation failed for method name is equal to <string:right> when invoked 1 time(s)\n" . |
|
803 | - "Parameter count for invocation SomeClass::right() is too low.\n" . |
|
804 | - 'To allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead.', |
|
805 | - $e->getMessage() |
|
806 | - ); |
|
807 | - } |
|
808 | - |
|
809 | - $this->resetMockObjects(); |
|
810 | - } |
|
811 | - |
|
812 | - /** |
|
813 | - * See https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 |
|
814 | - */ |
|
815 | - public function testMockArgumentsPassedByReference() |
|
816 | - { |
|
817 | - $foo = $this->getMockBuilder('MethodCallbackByReference') |
|
818 | - ->setMethods(['bar']) |
|
819 | - ->disableOriginalConstructor() |
|
820 | - ->disableArgumentCloning() |
|
821 | - ->getMock(); |
|
822 | - |
|
823 | - $foo->expects($this->any()) |
|
824 | - ->method('bar') |
|
825 | - ->will($this->returnCallback([$foo, 'callback'])); |
|
826 | - |
|
827 | - $a = $b = $c = 0; |
|
828 | - |
|
829 | - $foo->bar($a, $b, $c); |
|
830 | - |
|
831 | - $this->assertEquals(1, $b); |
|
832 | - } |
|
833 | - |
|
834 | - /** |
|
835 | - * See https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 |
|
836 | - */ |
|
837 | - public function testMockArgumentsPassedByReference2() |
|
838 | - { |
|
839 | - $foo = $this->getMockBuilder('MethodCallbackByReference') |
|
840 | - ->disableOriginalConstructor() |
|
841 | - ->disableArgumentCloning() |
|
842 | - ->getMock(); |
|
843 | - |
|
844 | - $foo->expects($this->any()) |
|
845 | - ->method('bar') |
|
846 | - ->will($this->returnCallback( |
|
847 | - function (&$a, &$b, $c) { |
|
848 | - $b = 1; |
|
849 | - } |
|
850 | - )); |
|
851 | - |
|
852 | - $a = $b = $c = 0; |
|
853 | - |
|
854 | - $foo->bar($a, $b, $c); |
|
855 | - |
|
856 | - $this->assertEquals(1, $b); |
|
857 | - } |
|
858 | - |
|
859 | - /** |
|
860 | - * @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/116 |
|
861 | - */ |
|
862 | - public function testMockArgumentsPassedByReference3() |
|
863 | - { |
|
864 | - $foo = $this->getMockBuilder('MethodCallbackByReference') |
|
865 | - ->setMethods(['bar']) |
|
866 | - ->disableOriginalConstructor() |
|
867 | - ->disableArgumentCloning() |
|
868 | - ->getMock(); |
|
869 | - |
|
870 | - $a = new stdClass; |
|
871 | - $b = $c = 0; |
|
872 | - |
|
873 | - $foo->expects($this->any()) |
|
874 | - ->method('bar') |
|
875 | - ->with($a, $b, $c) |
|
876 | - ->will($this->returnCallback([$foo, 'callback'])); |
|
877 | - |
|
878 | - $this->assertNull($foo->bar($a, $b, $c)); |
|
879 | - } |
|
880 | - |
|
881 | - /** |
|
882 | - * @see https://github.com/sebastianbergmann/phpunit/issues/796 |
|
883 | - */ |
|
884 | - public function testMockArgumentsPassedByReference4() |
|
885 | - { |
|
886 | - $foo = $this->getMockBuilder('MethodCallbackByReference') |
|
887 | - ->setMethods(['bar']) |
|
888 | - ->disableOriginalConstructor() |
|
889 | - ->disableArgumentCloning() |
|
890 | - ->getMock(); |
|
891 | - |
|
892 | - $a = new stdClass; |
|
893 | - $b = $c = 0; |
|
894 | - |
|
895 | - $foo->expects($this->any()) |
|
896 | - ->method('bar') |
|
897 | - ->with($this->isInstanceOf(stdClass::class), $b, $c) |
|
898 | - ->will($this->returnCallback([$foo, 'callback'])); |
|
899 | - |
|
900 | - $this->assertNull($foo->bar($a, $b, $c)); |
|
901 | - } |
|
902 | - |
|
903 | - /** |
|
904 | - * @requires extension soap |
|
905 | - */ |
|
906 | - public function testCreateMockFromWsdl() |
|
907 | - { |
|
908 | - $mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl', 'WsdlMock'); |
|
909 | - |
|
910 | - $this->assertStringStartsWith( |
|
911 | - 'Mock_WsdlMock_', |
|
912 | - get_class($mock) |
|
913 | - ); |
|
914 | - } |
|
915 | - |
|
916 | - /** |
|
917 | - * @requires extension soap |
|
918 | - */ |
|
919 | - public function testCreateNamespacedMockFromWsdl() |
|
920 | - { |
|
921 | - $mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl', 'My\\Space\\WsdlMock'); |
|
922 | - |
|
923 | - $this->assertStringStartsWith( |
|
924 | - 'Mock_WsdlMock_', |
|
925 | - get_class($mock) |
|
926 | - ); |
|
927 | - } |
|
928 | - |
|
929 | - /** |
|
930 | - * @requires extension soap |
|
931 | - */ |
|
932 | - public function testCreateTwoMocksOfOneWsdlFile() |
|
933 | - { |
|
934 | - $a = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl'); |
|
935 | - $b = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl'); |
|
936 | - |
|
937 | - $this->assertStringStartsWith('Mock_GoogleSearch_', get_class($a)); |
|
938 | - $this->assertEquals(get_class($a), get_class($b)); |
|
939 | - } |
|
940 | - |
|
941 | - /** |
|
942 | - * @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/156 |
|
943 | - * @ticket 156 |
|
944 | - */ |
|
945 | - public function testInterfaceWithStaticMethodCanBeStubbed() |
|
946 | - { |
|
947 | - $this->assertInstanceOf( |
|
948 | - InterfaceWithStaticMethod::class, |
|
949 | - $this->getMockBuilder(InterfaceWithStaticMethod::class)->getMock() |
|
950 | - ); |
|
951 | - } |
|
952 | - |
|
953 | - /** |
|
954 | - * @expectedException PHPUnit_Framework_MockObject_BadMethodCallException |
|
955 | - */ |
|
956 | - public function testInvokingStubbedStaticMethodRaisesException() |
|
957 | - { |
|
958 | - $mock = $this->getMockBuilder(ClassWithStaticMethod::class)->getMock(); |
|
959 | - |
|
960 | - $mock->staticMethod(); |
|
961 | - } |
|
962 | - |
|
963 | - /** |
|
964 | - * @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/171 |
|
965 | - * @ticket 171 |
|
966 | - */ |
|
967 | - public function testStubForClassThatImplementsSerializableCanBeCreatedWithoutInvokingTheConstructor() |
|
968 | - { |
|
969 | - $this->assertInstanceOf( |
|
970 | - ClassThatImplementsSerializable::class, |
|
971 | - $this->getMockBuilder(ClassThatImplementsSerializable::class) |
|
972 | - ->disableOriginalConstructor() |
|
973 | - ->getMock() |
|
974 | - ); |
|
975 | - } |
|
976 | - |
|
977 | - public function testGetMockForClassWithSelfTypeHint() |
|
978 | - { |
|
979 | - $this->assertInstanceOf( |
|
980 | - ClassWithSelfTypeHint::class, |
|
981 | - $this->getMockBuilder(ClassWithSelfTypeHint::class)->getMock() |
|
982 | - ); |
|
983 | - } |
|
984 | - |
|
985 | - private function resetMockObjects() |
|
986 | - { |
|
987 | - $refl = new ReflectionObject($this); |
|
988 | - $refl = $refl->getParentClass(); |
|
989 | - $prop = $refl->getProperty('mockObjects'); |
|
990 | - $prop->setAccessible(true); |
|
991 | - $prop->setValue($this, []); |
|
992 | - } |
|
993 | - |
|
994 | - public function testStringableClassDoesNotThrow() |
|
995 | - { |
|
996 | - $mock = $this->getMockBuilder(StringableClass::class)->getMock(); |
|
997 | - |
|
998 | - $this->assertInternalType('string', (string) $mock); |
|
999 | - } |
|
1000 | - |
|
1001 | - public function testStringableClassCanBeMocked() |
|
1002 | - { |
|
1003 | - $mock = $this->getMockBuilder(StringableClass::class)->getMock(); |
|
1004 | - |
|
1005 | - $mock->method('__toString')->willReturn('foo'); |
|
1006 | - |
|
1007 | - $this->assertSame('foo', (string) $mock); |
|
1008 | - } |
|
1009 | - |
|
1010 | - public function traversableProvider() |
|
1011 | - { |
|
1012 | - return [ |
|
1013 | - ['Traversable'], |
|
1014 | - ['\Traversable'], |
|
1015 | - ['TraversableMockTestInterface'], |
|
1016 | - [['Traversable']], |
|
1017 | - [['Iterator','Traversable']], |
|
1018 | - [['\Iterator','\Traversable']] |
|
1019 | - ]; |
|
1020 | - } |
|
1021 | - |
|
1022 | - public function testParameterCallbackConstraintOnlyEvaluatedOnce() |
|
1023 | - { |
|
1024 | - $mock = $this->getMockBuilder(Foo::class)->setMethods(['bar'])->getMock(); |
|
1025 | - $expectedNumberOfCalls = 1; |
|
1026 | - $callCount = 0; |
|
1027 | - |
|
1028 | - $mock->expects($this->exactly($expectedNumberOfCalls))->method('bar') |
|
1029 | - ->with($this->callback(function ($argument) use (&$callCount) { |
|
1030 | - return $argument === 'call_' . $callCount++; |
|
1031 | - })); |
|
1032 | - |
|
1033 | - for ($i = 0; $i < $expectedNumberOfCalls; $i++) { |
|
1034 | - $mock->bar('call_' . $i); |
|
1035 | - } |
|
1036 | - } |
|
559 | + public function testClonedMockObjectIsNotIdenticalToOriginalOne() |
|
560 | + { |
|
561 | + $x = $this->getMockBuilder(stdClass::class) |
|
562 | + ->getMock(); |
|
563 | + |
|
564 | + $y = clone $x; |
|
565 | + |
|
566 | + $mock = $this->getMockBuilder(stdClass::class) |
|
567 | + ->setMethods(['foo']) |
|
568 | + ->getMock(); |
|
569 | + |
|
570 | + $mock->expects($this->once()) |
|
571 | + ->method('foo') |
|
572 | + ->with($this->logicalNot($this->identicalTo($x))); |
|
573 | + |
|
574 | + $mock->foo($y); |
|
575 | + } |
|
576 | + |
|
577 | + public function testObjectMethodCallWithArgumentCloningEnabled() |
|
578 | + { |
|
579 | + $expectedObject = new stdClass; |
|
580 | + |
|
581 | + $mock = $this->getMockBuilder('SomeClass') |
|
582 | + ->setMethods(['doSomethingElse']) |
|
583 | + ->enableArgumentCloning() |
|
584 | + ->getMock(); |
|
585 | + |
|
586 | + $actualArguments = []; |
|
587 | + |
|
588 | + $mock->expects($this->any()) |
|
589 | + ->method('doSomethingElse') |
|
590 | + ->will( |
|
591 | + $this->returnCallback( |
|
592 | + function () use (&$actualArguments) { |
|
593 | + $actualArguments = func_get_args(); |
|
594 | + } |
|
595 | + ) |
|
596 | + ); |
|
597 | + |
|
598 | + $mock->doSomethingElse($expectedObject); |
|
599 | + |
|
600 | + $this->assertEquals(1, count($actualArguments)); |
|
601 | + $this->assertEquals($expectedObject, $actualArguments[0]); |
|
602 | + $this->assertNotSame($expectedObject, $actualArguments[0]); |
|
603 | + } |
|
604 | + |
|
605 | + public function testObjectMethodCallWithArgumentCloningDisabled() |
|
606 | + { |
|
607 | + $expectedObject = new stdClass; |
|
608 | + |
|
609 | + $mock = $this->getMockBuilder('SomeClass') |
|
610 | + ->setMethods(['doSomethingElse']) |
|
611 | + ->disableArgumentCloning() |
|
612 | + ->getMock(); |
|
613 | + |
|
614 | + $actualArguments = []; |
|
615 | + |
|
616 | + $mock->expects($this->any()) |
|
617 | + ->method('doSomethingElse') |
|
618 | + ->will( |
|
619 | + $this->returnCallback( |
|
620 | + function () use (&$actualArguments) { |
|
621 | + $actualArguments = func_get_args(); |
|
622 | + } |
|
623 | + ) |
|
624 | + ); |
|
625 | + |
|
626 | + $mock->doSomethingElse($expectedObject); |
|
627 | + |
|
628 | + $this->assertEquals(1, count($actualArguments)); |
|
629 | + $this->assertSame($expectedObject, $actualArguments[0]); |
|
630 | + } |
|
631 | + |
|
632 | + public function testArgumentCloningOptionGeneratesUniqueMock() |
|
633 | + { |
|
634 | + $mockWithCloning = $this->getMockBuilder('SomeClass') |
|
635 | + ->setMethods(['doSomethingElse']) |
|
636 | + ->enableArgumentCloning() |
|
637 | + ->getMock(); |
|
638 | + |
|
639 | + $mockWithoutCloning = $this->getMockBuilder('SomeClass') |
|
640 | + ->setMethods(['doSomethingElse']) |
|
641 | + ->disableArgumentCloning() |
|
642 | + ->getMock(); |
|
643 | + |
|
644 | + $this->assertNotEquals($mockWithCloning, $mockWithoutCloning); |
|
645 | + } |
|
646 | + |
|
647 | + public function testVerificationOfMethodNameFailsWithoutParameters() |
|
648 | + { |
|
649 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
650 | + ->setMethods(['right', 'wrong']) |
|
651 | + ->getMock(); |
|
652 | + |
|
653 | + $mock->expects($this->once()) |
|
654 | + ->method('right'); |
|
655 | + |
|
656 | + $mock->wrong(); |
|
657 | + |
|
658 | + try { |
|
659 | + $mock->__phpunit_verify(); |
|
660 | + $this->fail('Expected exception'); |
|
661 | + } catch (ExpectationFailedException $e) { |
|
662 | + $this->assertSame( |
|
663 | + "Expectation failed for method name is equal to <string:right> when invoked 1 time(s).\n" |
|
664 | + . "Method was expected to be called 1 times, actually called 0 times.\n", |
|
665 | + $e->getMessage() |
|
666 | + ); |
|
667 | + } |
|
668 | + |
|
669 | + $this->resetMockObjects(); |
|
670 | + } |
|
671 | + |
|
672 | + public function testVerificationOfMethodNameFailsWithParameters() |
|
673 | + { |
|
674 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
675 | + ->setMethods(['right', 'wrong']) |
|
676 | + ->getMock(); |
|
677 | + |
|
678 | + $mock->expects($this->once()) |
|
679 | + ->method('right'); |
|
680 | + |
|
681 | + $mock->wrong(); |
|
682 | + |
|
683 | + try { |
|
684 | + $mock->__phpunit_verify(); |
|
685 | + $this->fail('Expected exception'); |
|
686 | + } catch (ExpectationFailedException $e) { |
|
687 | + $this->assertSame( |
|
688 | + "Expectation failed for method name is equal to <string:right> when invoked 1 time(s).\n" |
|
689 | + . "Method was expected to be called 1 times, actually called 0 times.\n", |
|
690 | + $e->getMessage() |
|
691 | + ); |
|
692 | + } |
|
693 | + |
|
694 | + $this->resetMockObjects(); |
|
695 | + } |
|
696 | + |
|
697 | + public function testVerificationOfMethodNameFailsWithWrongParameters() |
|
698 | + { |
|
699 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
700 | + ->setMethods(['right', 'wrong']) |
|
701 | + ->getMock(); |
|
702 | + |
|
703 | + $mock->expects($this->once()) |
|
704 | + ->method('right') |
|
705 | + ->with(['first', 'second']); |
|
706 | + |
|
707 | + try { |
|
708 | + $mock->right(['second']); |
|
709 | + } catch (ExpectationFailedException $e) { |
|
710 | + $this->assertSame( |
|
711 | + "Expectation failed for method name is equal to <string:right> when invoked 1 time(s)\n" |
|
712 | + . "Parameter 0 for invocation SomeClass::right(Array (...)) does not match expected value.\n" |
|
713 | + . 'Failed asserting that two arrays are equal.', |
|
714 | + $e->getMessage() |
|
715 | + ); |
|
716 | + } |
|
717 | + |
|
718 | + try { |
|
719 | + $mock->__phpunit_verify(); |
|
720 | + $this->fail('Expected exception'); |
|
721 | + } catch (ExpectationFailedException $e) { |
|
722 | + $this->assertSame( |
|
723 | + "Expectation failed for method name is equal to <string:right> when invoked 1 time(s).\n" |
|
724 | + . "Parameter 0 for invocation SomeClass::right(Array (...)) does not match expected value.\n" |
|
725 | + . "Failed asserting that two arrays are equal.\n" |
|
726 | + . "--- Expected\n" |
|
727 | + . "+++ Actual\n" |
|
728 | + . "@@ @@\n" |
|
729 | + . " Array (\n" |
|
730 | + . "- 0 => 'first'\n" |
|
731 | + . "- 1 => 'second'\n" |
|
732 | + . "+ 0 => 'second'\n" |
|
733 | + . " )\n", |
|
734 | + $e->getMessage() |
|
735 | + ); |
|
736 | + } |
|
737 | + |
|
738 | + $this->resetMockObjects(); |
|
739 | + } |
|
740 | + |
|
741 | + public function testVerificationOfNeverFailsWithEmptyParameters() |
|
742 | + { |
|
743 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
744 | + ->setMethods(['right', 'wrong']) |
|
745 | + ->getMock(); |
|
746 | + |
|
747 | + $mock->expects($this->never()) |
|
748 | + ->method('right') |
|
749 | + ->with(); |
|
750 | + |
|
751 | + try { |
|
752 | + $mock->right(); |
|
753 | + $this->fail('Expected exception'); |
|
754 | + } catch (ExpectationFailedException $e) { |
|
755 | + $this->assertSame( |
|
756 | + 'SomeClass::right() was not expected to be called.', |
|
757 | + $e->getMessage() |
|
758 | + ); |
|
759 | + } |
|
760 | + |
|
761 | + $this->resetMockObjects(); |
|
762 | + } |
|
763 | + |
|
764 | + public function testVerificationOfNeverFailsWithAnyParameters() |
|
765 | + { |
|
766 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
767 | + ->setMethods(['right', 'wrong']) |
|
768 | + ->getMock(); |
|
769 | + |
|
770 | + $mock->expects($this->never()) |
|
771 | + ->method('right') |
|
772 | + ->withAnyParameters(); |
|
773 | + |
|
774 | + try { |
|
775 | + $mock->right(); |
|
776 | + $this->fail('Expected exception'); |
|
777 | + } catch (ExpectationFailedException $e) { |
|
778 | + $this->assertSame( |
|
779 | + 'SomeClass::right() was not expected to be called.', |
|
780 | + $e->getMessage() |
|
781 | + ); |
|
782 | + } |
|
783 | + |
|
784 | + $this->resetMockObjects(); |
|
785 | + } |
|
786 | + |
|
787 | + public function testWithAnythingInsteadOfWithAnyParameters() |
|
788 | + { |
|
789 | + $mock = $this->getMockBuilder(SomeClass::class) |
|
790 | + ->setMethods(['right', 'wrong']) |
|
791 | + ->getMock(); |
|
792 | + |
|
793 | + $mock->expects($this->once()) |
|
794 | + ->method('right') |
|
795 | + ->with($this->anything()); |
|
796 | + |
|
797 | + try { |
|
798 | + $mock->right(); |
|
799 | + $this->fail('Expected exception'); |
|
800 | + } catch (ExpectationFailedException $e) { |
|
801 | + $this->assertSame( |
|
802 | + "Expectation failed for method name is equal to <string:right> when invoked 1 time(s)\n" . |
|
803 | + "Parameter count for invocation SomeClass::right() is too low.\n" . |
|
804 | + 'To allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead.', |
|
805 | + $e->getMessage() |
|
806 | + ); |
|
807 | + } |
|
808 | + |
|
809 | + $this->resetMockObjects(); |
|
810 | + } |
|
811 | + |
|
812 | + /** |
|
813 | + * See https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 |
|
814 | + */ |
|
815 | + public function testMockArgumentsPassedByReference() |
|
816 | + { |
|
817 | + $foo = $this->getMockBuilder('MethodCallbackByReference') |
|
818 | + ->setMethods(['bar']) |
|
819 | + ->disableOriginalConstructor() |
|
820 | + ->disableArgumentCloning() |
|
821 | + ->getMock(); |
|
822 | + |
|
823 | + $foo->expects($this->any()) |
|
824 | + ->method('bar') |
|
825 | + ->will($this->returnCallback([$foo, 'callback'])); |
|
826 | + |
|
827 | + $a = $b = $c = 0; |
|
828 | + |
|
829 | + $foo->bar($a, $b, $c); |
|
830 | + |
|
831 | + $this->assertEquals(1, $b); |
|
832 | + } |
|
833 | + |
|
834 | + /** |
|
835 | + * See https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 |
|
836 | + */ |
|
837 | + public function testMockArgumentsPassedByReference2() |
|
838 | + { |
|
839 | + $foo = $this->getMockBuilder('MethodCallbackByReference') |
|
840 | + ->disableOriginalConstructor() |
|
841 | + ->disableArgumentCloning() |
|
842 | + ->getMock(); |
|
843 | + |
|
844 | + $foo->expects($this->any()) |
|
845 | + ->method('bar') |
|
846 | + ->will($this->returnCallback( |
|
847 | + function (&$a, &$b, $c) { |
|
848 | + $b = 1; |
|
849 | + } |
|
850 | + )); |
|
851 | + |
|
852 | + $a = $b = $c = 0; |
|
853 | + |
|
854 | + $foo->bar($a, $b, $c); |
|
855 | + |
|
856 | + $this->assertEquals(1, $b); |
|
857 | + } |
|
858 | + |
|
859 | + /** |
|
860 | + * @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/116 |
|
861 | + */ |
|
862 | + public function testMockArgumentsPassedByReference3() |
|
863 | + { |
|
864 | + $foo = $this->getMockBuilder('MethodCallbackByReference') |
|
865 | + ->setMethods(['bar']) |
|
866 | + ->disableOriginalConstructor() |
|
867 | + ->disableArgumentCloning() |
|
868 | + ->getMock(); |
|
869 | + |
|
870 | + $a = new stdClass; |
|
871 | + $b = $c = 0; |
|
872 | + |
|
873 | + $foo->expects($this->any()) |
|
874 | + ->method('bar') |
|
875 | + ->with($a, $b, $c) |
|
876 | + ->will($this->returnCallback([$foo, 'callback'])); |
|
877 | + |
|
878 | + $this->assertNull($foo->bar($a, $b, $c)); |
|
879 | + } |
|
880 | + |
|
881 | + /** |
|
882 | + * @see https://github.com/sebastianbergmann/phpunit/issues/796 |
|
883 | + */ |
|
884 | + public function testMockArgumentsPassedByReference4() |
|
885 | + { |
|
886 | + $foo = $this->getMockBuilder('MethodCallbackByReference') |
|
887 | + ->setMethods(['bar']) |
|
888 | + ->disableOriginalConstructor() |
|
889 | + ->disableArgumentCloning() |
|
890 | + ->getMock(); |
|
891 | + |
|
892 | + $a = new stdClass; |
|
893 | + $b = $c = 0; |
|
894 | + |
|
895 | + $foo->expects($this->any()) |
|
896 | + ->method('bar') |
|
897 | + ->with($this->isInstanceOf(stdClass::class), $b, $c) |
|
898 | + ->will($this->returnCallback([$foo, 'callback'])); |
|
899 | + |
|
900 | + $this->assertNull($foo->bar($a, $b, $c)); |
|
901 | + } |
|
902 | + |
|
903 | + /** |
|
904 | + * @requires extension soap |
|
905 | + */ |
|
906 | + public function testCreateMockFromWsdl() |
|
907 | + { |
|
908 | + $mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl', 'WsdlMock'); |
|
909 | + |
|
910 | + $this->assertStringStartsWith( |
|
911 | + 'Mock_WsdlMock_', |
|
912 | + get_class($mock) |
|
913 | + ); |
|
914 | + } |
|
915 | + |
|
916 | + /** |
|
917 | + * @requires extension soap |
|
918 | + */ |
|
919 | + public function testCreateNamespacedMockFromWsdl() |
|
920 | + { |
|
921 | + $mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl', 'My\\Space\\WsdlMock'); |
|
922 | + |
|
923 | + $this->assertStringStartsWith( |
|
924 | + 'Mock_WsdlMock_', |
|
925 | + get_class($mock) |
|
926 | + ); |
|
927 | + } |
|
928 | + |
|
929 | + /** |
|
930 | + * @requires extension soap |
|
931 | + */ |
|
932 | + public function testCreateTwoMocksOfOneWsdlFile() |
|
933 | + { |
|
934 | + $a = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl'); |
|
935 | + $b = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl'); |
|
936 | + |
|
937 | + $this->assertStringStartsWith('Mock_GoogleSearch_', get_class($a)); |
|
938 | + $this->assertEquals(get_class($a), get_class($b)); |
|
939 | + } |
|
940 | + |
|
941 | + /** |
|
942 | + * @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/156 |
|
943 | + * @ticket 156 |
|
944 | + */ |
|
945 | + public function testInterfaceWithStaticMethodCanBeStubbed() |
|
946 | + { |
|
947 | + $this->assertInstanceOf( |
|
948 | + InterfaceWithStaticMethod::class, |
|
949 | + $this->getMockBuilder(InterfaceWithStaticMethod::class)->getMock() |
|
950 | + ); |
|
951 | + } |
|
952 | + |
|
953 | + /** |
|
954 | + * @expectedException PHPUnit_Framework_MockObject_BadMethodCallException |
|
955 | + */ |
|
956 | + public function testInvokingStubbedStaticMethodRaisesException() |
|
957 | + { |
|
958 | + $mock = $this->getMockBuilder(ClassWithStaticMethod::class)->getMock(); |
|
959 | + |
|
960 | + $mock->staticMethod(); |
|
961 | + } |
|
962 | + |
|
963 | + /** |
|
964 | + * @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/171 |
|
965 | + * @ticket 171 |
|
966 | + */ |
|
967 | + public function testStubForClassThatImplementsSerializableCanBeCreatedWithoutInvokingTheConstructor() |
|
968 | + { |
|
969 | + $this->assertInstanceOf( |
|
970 | + ClassThatImplementsSerializable::class, |
|
971 | + $this->getMockBuilder(ClassThatImplementsSerializable::class) |
|
972 | + ->disableOriginalConstructor() |
|
973 | + ->getMock() |
|
974 | + ); |
|
975 | + } |
|
976 | + |
|
977 | + public function testGetMockForClassWithSelfTypeHint() |
|
978 | + { |
|
979 | + $this->assertInstanceOf( |
|
980 | + ClassWithSelfTypeHint::class, |
|
981 | + $this->getMockBuilder(ClassWithSelfTypeHint::class)->getMock() |
|
982 | + ); |
|
983 | + } |
|
984 | + |
|
985 | + private function resetMockObjects() |
|
986 | + { |
|
987 | + $refl = new ReflectionObject($this); |
|
988 | + $refl = $refl->getParentClass(); |
|
989 | + $prop = $refl->getProperty('mockObjects'); |
|
990 | + $prop->setAccessible(true); |
|
991 | + $prop->setValue($this, []); |
|
992 | + } |
|
993 | + |
|
994 | + public function testStringableClassDoesNotThrow() |
|
995 | + { |
|
996 | + $mock = $this->getMockBuilder(StringableClass::class)->getMock(); |
|
997 | + |
|
998 | + $this->assertInternalType('string', (string) $mock); |
|
999 | + } |
|
1000 | + |
|
1001 | + public function testStringableClassCanBeMocked() |
|
1002 | + { |
|
1003 | + $mock = $this->getMockBuilder(StringableClass::class)->getMock(); |
|
1004 | + |
|
1005 | + $mock->method('__toString')->willReturn('foo'); |
|
1006 | + |
|
1007 | + $this->assertSame('foo', (string) $mock); |
|
1008 | + } |
|
1009 | + |
|
1010 | + public function traversableProvider() |
|
1011 | + { |
|
1012 | + return [ |
|
1013 | + ['Traversable'], |
|
1014 | + ['\Traversable'], |
|
1015 | + ['TraversableMockTestInterface'], |
|
1016 | + [['Traversable']], |
|
1017 | + [['Iterator','Traversable']], |
|
1018 | + [['\Iterator','\Traversable']] |
|
1019 | + ]; |
|
1020 | + } |
|
1021 | + |
|
1022 | + public function testParameterCallbackConstraintOnlyEvaluatedOnce() |
|
1023 | + { |
|
1024 | + $mock = $this->getMockBuilder(Foo::class)->setMethods(['bar'])->getMock(); |
|
1025 | + $expectedNumberOfCalls = 1; |
|
1026 | + $callCount = 0; |
|
1027 | + |
|
1028 | + $mock->expects($this->exactly($expectedNumberOfCalls))->method('bar') |
|
1029 | + ->with($this->callback(function ($argument) use (&$callCount) { |
|
1030 | + return $argument === 'call_' . $callCount++; |
|
1031 | + })); |
|
1032 | + |
|
1033 | + for ($i = 0; $i < $expectedNumberOfCalls; $i++) { |
|
1034 | + $mock->bar('call_' . $i); |
|
1035 | + } |
|
1036 | + } |
|
1037 | 1037 | } |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | ->method('doSomethingElse') |
590 | 590 | ->will( |
591 | 591 | $this->returnCallback( |
592 | - function () use (&$actualArguments) { |
|
592 | + function() use (&$actualArguments) { |
|
593 | 593 | $actualArguments = func_get_args(); |
594 | 594 | } |
595 | 595 | ) |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | ->method('doSomethingElse') |
618 | 618 | ->will( |
619 | 619 | $this->returnCallback( |
620 | - function () use (&$actualArguments) { |
|
620 | + function() use (&$actualArguments) { |
|
621 | 621 | $actualArguments = func_get_args(); |
622 | 622 | } |
623 | 623 | ) |
@@ -799,8 +799,8 @@ discard block |
||
799 | 799 | $this->fail('Expected exception'); |
800 | 800 | } catch (ExpectationFailedException $e) { |
801 | 801 | $this->assertSame( |
802 | - "Expectation failed for method name is equal to <string:right> when invoked 1 time(s)\n" . |
|
803 | - "Parameter count for invocation SomeClass::right() is too low.\n" . |
|
802 | + "Expectation failed for method name is equal to <string:right> when invoked 1 time(s)\n". |
|
803 | + "Parameter count for invocation SomeClass::right() is too low.\n". |
|
804 | 804 | 'To allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead.', |
805 | 805 | $e->getMessage() |
806 | 806 | ); |
@@ -844,7 +844,7 @@ discard block |
||
844 | 844 | $foo->expects($this->any()) |
845 | 845 | ->method('bar') |
846 | 846 | ->will($this->returnCallback( |
847 | - function (&$a, &$b, $c) { |
|
847 | + function(&$a, &$b, $c) { |
|
848 | 848 | $b = 1; |
849 | 849 | } |
850 | 850 | )); |
@@ -905,7 +905,7 @@ discard block |
||
905 | 905 | */ |
906 | 906 | public function testCreateMockFromWsdl() |
907 | 907 | { |
908 | - $mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl', 'WsdlMock'); |
|
908 | + $mock = $this->getMockFromWsdl(__DIR__.'/_fixture/GoogleSearch.wsdl', 'WsdlMock'); |
|
909 | 909 | |
910 | 910 | $this->assertStringStartsWith( |
911 | 911 | 'Mock_WsdlMock_', |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | */ |
919 | 919 | public function testCreateNamespacedMockFromWsdl() |
920 | 920 | { |
921 | - $mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl', 'My\\Space\\WsdlMock'); |
|
921 | + $mock = $this->getMockFromWsdl(__DIR__.'/_fixture/GoogleSearch.wsdl', 'My\\Space\\WsdlMock'); |
|
922 | 922 | |
923 | 923 | $this->assertStringStartsWith( |
924 | 924 | 'Mock_WsdlMock_', |
@@ -931,8 +931,8 @@ discard block |
||
931 | 931 | */ |
932 | 932 | public function testCreateTwoMocksOfOneWsdlFile() |
933 | 933 | { |
934 | - $a = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl'); |
|
935 | - $b = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl'); |
|
934 | + $a = $this->getMockFromWsdl(__DIR__.'/_fixture/GoogleSearch.wsdl'); |
|
935 | + $b = $this->getMockFromWsdl(__DIR__.'/_fixture/GoogleSearch.wsdl'); |
|
936 | 936 | |
937 | 937 | $this->assertStringStartsWith('Mock_GoogleSearch_', get_class($a)); |
938 | 938 | $this->assertEquals(get_class($a), get_class($b)); |
@@ -1014,8 +1014,8 @@ discard block |
||
1014 | 1014 | ['\Traversable'], |
1015 | 1015 | ['TraversableMockTestInterface'], |
1016 | 1016 | [['Traversable']], |
1017 | - [['Iterator','Traversable']], |
|
1018 | - [['\Iterator','\Traversable']] |
|
1017 | + [['Iterator', 'Traversable']], |
|
1018 | + [['\Iterator', '\Traversable']] |
|
1019 | 1019 | ]; |
1020 | 1020 | } |
1021 | 1021 | |
@@ -1026,12 +1026,12 @@ discard block |
||
1026 | 1026 | $callCount = 0; |
1027 | 1027 | |
1028 | 1028 | $mock->expects($this->exactly($expectedNumberOfCalls))->method('bar') |
1029 | - ->with($this->callback(function ($argument) use (&$callCount) { |
|
1030 | - return $argument === 'call_' . $callCount++; |
|
1029 | + ->with($this->callback(function($argument) use (&$callCount) { |
|
1030 | + return $argument === 'call_'.$callCount++; |
|
1031 | 1031 | })); |
1032 | 1032 | |
1033 | 1033 | for ($i = 0; $i < $expectedNumberOfCalls; $i++) { |
1034 | - $mock->bar('call_' . $i); |
|
1034 | + $mock->bar('call_'.$i); |
|
1035 | 1035 | } |
1036 | 1036 | } |
1037 | 1037 | } |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | class StaticMockTestClass |
3 | 3 | { |
4 | - public static function doSomething() |
|
5 | - { |
|
6 | - } |
|
4 | + public static function doSomething() |
|
5 | + { |
|
6 | + } |
|
7 | 7 | |
8 | - public static function doSomethingElse() |
|
9 | - { |
|
10 | - return static::doSomething(); |
|
11 | - } |
|
8 | + public static function doSomethingElse() |
|
9 | + { |
|
10 | + return static::doSomething(); |
|
11 | + } |
|
12 | 12 | } |
@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | 2 | class PartialMockTestClass |
3 | 3 | { |
4 | - public $constructorCalled = false; |
|
4 | + public $constructorCalled = false; |
|
5 | 5 | |
6 | - public function __construct() |
|
7 | - { |
|
8 | - $this->constructorCalled = true; |
|
9 | - } |
|
6 | + public function __construct() |
|
7 | + { |
|
8 | + $this->constructorCalled = true; |
|
9 | + } |
|
10 | 10 | |
11 | - public function doSomething() |
|
12 | - { |
|
13 | - } |
|
11 | + public function doSomething() |
|
12 | + { |
|
13 | + } |
|
14 | 14 | |
15 | - public function doAnotherThing() |
|
16 | - { |
|
17 | - } |
|
15 | + public function doAnotherThing() |
|
16 | + { |
|
17 | + } |
|
18 | 18 | } |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | 2 | interface AnotherInterface |
3 | 3 | { |
4 | - public function doSomethingElse(); |
|
4 | + public function doSomethingElse(); |
|
5 | 5 | } |