Skip to content

Commit 240788c

Browse files
committed
Removed backtracking for friend classes since it's not supported in PHP 7.0
1 parent e649702 commit 240788c

File tree

5 files changed

+8
-61
lines changed

5 files changed

+8
-61
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: php
22

33
php:
4+
- 7.0
45
- 5.6
56
- 5.5
67
- 5.4

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
## Installation
1919

20+
> PHP Version >= 5.4 is required!
21+
2022
The following instructions outline installation using Composer. If you don't
2123
have Composer, you can download it from [http://getcomposer.org/](http://getcomposer.org/)
2224

src/ShortifyPunit.php

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,8 @@ class ShortifyPunit
5656
*/
5757
private static $returnValues = [];
5858

59-
60-
/**
61-
* @var array of allowed friend classes, that could access private methods of this class
62-
*/
63-
private static $friendClasses = [
64-
'ShortifyPunit\ShortifyPunit',
65-
'ShortifyPunit\Stub\WhenCase',
66-
'ShortifyPunit\Mock\MockClassOnTheFly',
67-
'ShortifyPunit\Stub\WhenChainCase'];
68-
6959
/**
7060
* Call static function is used to detect calls to protected & private methods
71-
* only friend classes are allowed to call private methods (C++ Style)
72-
*
73-
* + Friend Classes are those who Implement the mocking interface (ShortifyPunitMockInterface)
74-
* or is set in $friendClasses variable
7561
*
7662
* @param $name
7763
* @param $arguments
@@ -88,22 +74,6 @@ public static function __callStatic($name, $arguments)
8874
throw self::generateException("{$class} has no such method!");
8975
}
9076

91-
$namespace = self::$namespace;
92-
$backTrace = debug_backtrace();
93-
$callingClassName = $backTrace[2]['class'];
94-
95-
$reflection = new \ReflectionClass($callingClassName);
96-
97-
if ($reflection->implementsInterface("{$namespace}\\Mock\\MockInterface") &&
98-
is_array($arguments)
99-
) {
100-
$arguments[0] = $callingClassName;
101-
}
102-
103-
if ( ! self::isFriendClass($callingClassName, $namespace)){
104-
throw self::generateException("{$class} is not a friend class!");
105-
}
106-
10777
return forward_static_call_array('static::'.$name, $arguments);
10878
}
10979

@@ -267,7 +237,7 @@ protected static function _isMethodStubbed($className, $instanceId, $methodName)
267237
}
268238

269239
/**
270-
* Setting up a chained mock response, function is called from mocked classes using `friend classes` style
240+
* Setting up a chained mock response, function is called from mocked classes
271241
*
272242
* @param $mockClassInstanceId
273243
* @param $mockClassType
@@ -315,7 +285,7 @@ protected static function _createChainResponse(
315285

316286

317287
/**
318-
* Setting up a mock response, function is called from mocked classes using `friend classes` style
288+
* Setting up a mock response, function is called from mocked classes
319289
*
320290
* @param $className
321291
* @param $instanceId
@@ -341,7 +311,7 @@ protected static function _setWhenMockResponse(
341311
}
342312

343313
/**
344-
* Generating instance id, function is called from mocked classes using `friend classes` style
314+
* Generating instance id, function is called from mocked classes
345315
* @return int
346316
*/
347317
protected static function _generateInstanceId()
@@ -350,7 +320,7 @@ protected static function _generateInstanceId()
350320
}
351321

352322
/**
353-
* Create response is a private method which is called from the Mocked classes using `friend classes` style
323+
* Create response is a private method which is called from the Mocked classes
354324
* returns a value which was set before in the When() function otherwise returning NULL
355325
*
356326
* @param $className
@@ -417,23 +387,6 @@ private static function getMockReflection($mockedClass)
417387
return $reflection;
418388
}
419389

420-
/**
421-
* @param $callingClassName
422-
* @param string $namespace
423-
* @return bool
424-
*/
425-
private static function isFriendClass($callingClassName, $namespace)
426-
{
427-
$reflection = new \ReflectionClass($callingClassName);
428-
429-
if ( ! $reflection->implementsInterface("{$namespace}\\Mock\\MockInterface") &&
430-
! in_array($callingClassName, self::$friendClasses)) {
431-
return false;
432-
}
433-
434-
return true;
435-
}
436-
437390
/**
438391
* Returns the mock hierarchy response values
439392
*

tests/ShortifyPunitTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,6 @@ public function testStubbingNullIfNotSet()
9191
$this->assertNull($mock->second_method());
9292
}
9393

94-
/**
95-
* @checks Friend classes
96-
* @expectedException \PHPUnit_Framework_AssertionFailedError
97-
*/
98-
public function testFriendClasses()
99-
{
100-
ShortifyPunit::generateInstanceId();
101-
}
102-
10394
/**
10495
* @checks Private method exist
10596
* @expectedException \PHPUnit_Framework_AssertionFailedError

tests/Verify/VerifyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@ public function testWithHamcrestMatcher()
141141
$this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->calledTimes(2));
142142
$this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->lessThan(1));
143143
}
144-
}
144+
}

0 commit comments

Comments
 (0)