Skip to content

Commit

Permalink
Merge pull request #3309 from mhsdesign/task/deprecateGetAccessibleMock
Browse files Browse the repository at this point in the history
TASK: Deprecate BaseTestCase functionalities
  • Loading branch information
kitsunet authored Mar 28, 2024
2 parents 9034039 + 98a5829 commit b2f093b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
30 changes: 30 additions & 0 deletions Neos.Flow/Tests/AccessibleProxyInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Neos\Flow\Tests;

use Neos\Utility\ObjectAccess;

/**
* This interface defines the methods provided by {@see BaseTestCase::getAccessibleMock()}
* Do not implement this interface in own classes.
*
* It allows for calling even protected methods and access of protected properties.
*
* Note that this interface is not actually implemented by the accessible proxy, but only provides IDE support.
*
* @deprecated you should not use this for testing. As it will couple the tests to highly to the internal implementation
* and makes refactorings without rewriting major tests impossible.
*/
interface AccessibleProxyInterface
{
/** @deprecated */
public function _call(string $methodName, mixed ...$arguments): mixed;
/** @deprecated */
public function _callRef(string $methodName, mixed ...$argumentsPassedByReference): mixed;
/** @deprecated please specify properties via constructor call the injector manually or use - if you must - {@see ObjectAccess::setProperty()} instead. */
public function _set(string $propertyName, mixed $value): void;
/** @deprecated */
public function _setRef(string $propertyName, mixed &$value): void;
/** @deprecated please use - if you must - {@see ObjectAccess::setProperty()} instead. */
public function _get(string $propertyName): mixed;
}
30 changes: 14 additions & 16 deletions Neos.Flow/Tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@
* Don't sub class this test case but rather choose a more specialized base test case,
* such as UnitTestCase or FunctionalTestCase
*
* @api
* @deprecated its utilities are deprecated.
*/
abstract class BaseTestCase extends \PHPUnit\Framework\TestCase
{
/**
* @var array
*/
protected $backupGlobalsBlacklist = ['GLOBALS', 'bootstrap', '__PHPUNIT_BOOTSTRAP'];
protected $backupGlobalsExcludeList = ['GLOBALS', 'bootstrap', '__PHPUNIT_BOOTSTRAP'];

/**
* Enable or disable the backup and restoration of static attributes.
*
* @var boolean
*/
protected $backupStaticAttributes = false;
Expand All @@ -37,7 +35,8 @@ abstract class BaseTestCase extends \PHPUnit\Framework\TestCase
* Returns a mock object which allows for calling protected methods and access
* of protected properties.
*
* @param string $originalClassName Full qualified name of the original class
* @template T of object
* @param class-string<T> $originalClassName Full qualified name of the original class
* @param array $methods
* @param array $arguments
* @param string $mockClassName
Expand All @@ -47,8 +46,8 @@ abstract class BaseTestCase extends \PHPUnit\Framework\TestCase
* @param boolean $cloneArguments
* @param boolean $callOriginalMethods
* @param object $proxyTarget
* @return \PHPUnit\Framework\MockObject\MockObject
* @api
* @return T&\PHPUnit\Framework\MockObject\MockObject&AccessibleProxyInterface
* @deprecated please don't use this {@see AccessibleProxyInterface}
*/
protected function getAccessibleMock($originalClassName, $methods = [], array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false, $callOriginalMethods = false, $proxyTarget = null)
{
Expand Down Expand Up @@ -87,16 +86,17 @@ protected function getAccessibleMock($originalClassName, $methods = [], array $a
* Returns a mock object which allows for calling protected methods and access
* of protected properties.
*
* @param string $originalClassName Full qualified name of the original class
* @template T of object
* @param class-string<T> $originalClassName Full qualified name of the original class
* @param array $arguments
* @param string $mockClassName
* @param boolean $callOriginalConstructor
* @param boolean $callOriginalClone
* @param boolean $callAutoload
* @param array $mockedMethods
* @param boolean $cloneArguments
* @return \PHPUnit\Framework\MockObject\MockObject
* @api
* @return T&\PHPUnit\Framework\MockObject\MockObject&AccessibleProxyInterface
* @deprecated please don't use this {@see AccessibleProxyInterface}
*/
protected function getAccessibleMockForAbstractClass($originalClassName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = false)
{
Expand All @@ -109,7 +109,7 @@ protected function getAccessibleMockForAbstractClass($originalClassName, array $
*
* @param string $className Full qualified name of the original class
* @return string Full qualified name of the built class
* @api
* @deprecated please don't use this {@see AccessibleProxyInterface}
*/
protected function buildAccessibleProxy($className)
{
Expand Down Expand Up @@ -162,13 +162,11 @@ public function _get($propertyName) {
* @return void
* @throws \RuntimeException
* @throws \InvalidArgumentException
* @deprecated please specify properties via constructor, call the injector manually or use - if you must - ObjectAccess::setProperty instead.
*/
protected function inject($target, $name, $dependency)
protected function inject(object $target, string $name, mixed $dependency)
{
if (!is_object($target)) {
throw new \InvalidArgumentException('Wrong type for argument $target, must be object.');
}

// we don't use ObjectAccess::setProperty as it doesn't support `inject*`
$objectReflection = new \ReflectionObject($target);
$methodNamePart = strtoupper($name[0]) . substr($name, 1);
if ($objectReflection->hasMethod('set' . $methodNamePart)) {
Expand Down

0 comments on commit b2f093b

Please sign in to comment.