-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TestCase::getMockForModel generate phpunit deprecations notices #14747
Comments
Do you want to make a PR here? |
Sure, I just don't know how to include a test for this (a test for the TestCase class?) |
Fixed in #14748 |
This solution shifts the deprecation warning to the case when trying to mock protected methods. get_class_methods returns public methods only. Maybe ReflectorClass should be used instead? |
You are right @hakito That way we have all methods reflected, in my codebase, worked to: [, $baseClass] = pluginSplit($alias);
$options += ['alias' => $baseClass, 'connection' => $connection];
$options += $locator->getConfig($alias);
$reflection = new ReflectionClass($className);
$classMethods = array_map(function ($method) { return $method->name; }, $reflection->getMethods());
$existingMethods = array_intersect($classMethods, $methods);
$nonExistingMethods = array_diff($methods, $existingMethods); Have another idea? I found another problem: if mock only proxied methods (from behaviors), PHPUNIT still generate a notice. I think its a bug in it, not a CakePHP fault, but need to build a standalone testcase to prove. |
A correct fix to getMockForModel issue #14747
This is a (multiple allowed):
bug
enhancement
feature-discussion (RFC)
CakePHP Version: 4.1-RC2.
Platform and Target: phpunit 8.5.8, php 7.2
What you did
Have test cases with model linked with behaviors and tried mock some of behavior methods.
What happened
Get that message when tests are run:
Trying to set mock method "myBehaviorMethod" with onlyMethods, but it does not exist in class "App\Model\Table\ArticlesTable". Use addMethods() for methods that don't exist in the class.
What you expected to happen
Mocked methods and silent run
I found a PR on PHPUNIT about that deprecation: sebastianbergmann/phpunit#3687
So, inspecting
Cake\TestSuite\TestCase::getMockForModel
I can fix that message changing:to
The text was updated successfully, but these errors were encountered: