Skip to content

Commit 00c4fc6

Browse files
committed
MAGETWO-87512: Removed create_function() function usage #32
- Merge Pull Request magento-engcom/php-7.2-support#32 from joni-jones/magento2:G#8 - Merged commits: 1. 7c79007
2 parents 7bc49cd + 7c79007 commit 00c4fc6

File tree

2 files changed

+61
-39
lines changed

2 files changed

+61
-39
lines changed

dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,4 +2528,5 @@
25282528
['_isAttributeValueEmpty', 'Magento\Catalog\Model\ResourceModel\AbstractResource'],
25292529
['var_dump', ''],
25302530
['each', ''],
2531+
['create_function', ''],
25312532
];

lib/internal/Magento/Framework/Validator/Test/Unit/Constraint/Option/CallbackTest.php

Lines changed: 60 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\Framework\Validator\Test\Unit\Constraint\Option;
87

9-
/**
10-
* Test case for \Magento\Framework\Validator\Constraint\Option\Callback
11-
*/
8+
use Magento\Framework\Validator\Constraint\Option\Callback;
9+
use Magento\Framework\Validator\Test\Unit\Test\Callback as TestCallback;
10+
1211
class CallbackTest extends \PHPUnit\Framework\TestCase
1312
{
1413
/**
@@ -28,41 +27,46 @@ class CallbackTest extends \PHPUnit\Framework\TestCase
2827
*/
2928
public function testGetValue($callback, $expectedResult, $arguments = null, $createInstance = false)
3029
{
31-
$option = new \Magento\Framework\Validator\Constraint\Option\Callback($callback, $arguments, $createInstance);
32-
$this->assertEquals($expectedResult, $option->getValue());
30+
$option = new Callback($callback, $arguments, $createInstance);
31+
self::assertEquals($expectedResult, $option->getValue());
3332
}
3433

3534
/**
3635
* Data provider for testGetValue
3736
*/
3837
public function getConfigDataProvider()
3938
{
40-
$functionName = create_function('', 'return "Value from function";');
4139
$closure = function () {
4240
return 'Value from closure';
4341
};
4442

45-
$mock = $this->getMockBuilder('Foo')->setMethods(['getValue'])->getMock();
46-
$mock->expects(
47-
$this->once()
48-
)->method(
49-
'getValue'
50-
)->with(
51-
'arg1',
52-
'arg2'
53-
)->will(
54-
$this->returnValue('Value from mock')
55-
);
43+
$mock = $this->getMockBuilder('Foo')
44+
->setMethods(['getValue'])
45+
->getMock();
46+
$mock->method('getValue')
47+
->with('arg1', 'arg2')
48+
->willReturn('Value from mock');
5649

5750
return [
58-
[$functionName, 'Value from function'],
59-
[$closure, 'Value from closure'],
60-
[[$this, 'getTestValue'], self::TEST_VALUE],
61-
[[__CLASS__, 'getTestValueStatically'], self::TEST_VALUE],
62-
[[$mock, 'getValue'], 'Value from mock', ['arg1', 'arg2']],
6351
[
64-
[\Magento\Framework\Validator\Test\Unit\Test\Callback::class, 'getId'],
65-
\Magento\Framework\Validator\Test\Unit\Test\Callback::ID,
52+
$closure,
53+
'Value from closure'
54+
],
55+
[
56+
[$this, 'getTestValue'],
57+
self::TEST_VALUE
58+
],
59+
[
60+
[__CLASS__, 'getTestValueStatically'],
61+
self::TEST_VALUE
62+
],
63+
[
64+
[$mock, 'getValue'],
65+
'Value from mock', ['arg1', 'arg2']
66+
],
67+
[
68+
[TestCallback::class, 'getId'],
69+
TestCallback::ID,
6670
null,
6771
true
6872
]
@@ -90,25 +94,29 @@ public function getTestValue()
9094
*
9195
* @dataProvider setArgumentsDataProvider
9296
*
93-
* @param mixed $value
94-
* @param mixed $expectedValue
97+
* @param string|array $value
98+
* @param string|array $expectedValue
9599
*/
96100
public function testSetArguments($value, $expectedValue)
97101
{
98-
$option = new \Magento\Framework\Validator\Constraint\Option\Callback(
99-
function () {
100-
}
101-
);
102+
$option = new Callback(function () {
103+
});
102104
$option->setArguments($value);
103-
$this->assertAttributeEquals($expectedValue, '_arguments', $option);
105+
self::assertAttributeEquals($expectedValue, '_arguments', $option);
104106
}
105107

106108
/**
107109
* Data provider for testGetValue
108110
*/
109111
public function setArgumentsDataProvider()
110112
{
111-
return [['baz', ['baz']], [['foo', 'bar'], ['foo', 'bar']]];
113+
return [
114+
['baz', ['baz']],
115+
[
116+
['foo', 'bar'],
117+
['foo', 'bar']
118+
]
119+
];
112120
}
113121

114122
/**
@@ -119,11 +127,12 @@ public function setArgumentsDataProvider()
119127
* @param mixed $callback
120128
* @param string $expectedMessage
121129
* @param bool $createInstance
130+
* @expectedException \InvalidArgumentException
122131
*/
123132
public function testGetValueException($callback, $expectedMessage, $createInstance = false)
124133
{
125-
$option = new \Magento\Framework\Validator\Constraint\Option\Callback($callback, null, $createInstance);
126-
$this->expectException('InvalidArgumentException', $expectedMessage);
134+
$option = new Callback($callback, null, $createInstance);
135+
self::expectExceptionMessage($expectedMessage);
127136
$option->getValue();
128137
}
129138

@@ -139,10 +148,22 @@ public function getValueExceptionDataProvider()
139148
['Not_Existing_Callback_Class', 'someMethod'],
140149
'Class "Not_Existing_Callback_Class" was not found',
141150
],
142-
[[$this, 'notExistingMethod'], 'Callback does not callable'],
143-
[['object' => $this, 'method' => 'getTestValue'], 'Callback does not callable'],
144-
['unknown_function', 'Callback does not callable'],
145-
[new \stdClass(), 'Callback does not callable'],
151+
[
152+
[$this, 'notExistingMethod'],
153+
'Callback does not callable'
154+
],
155+
[
156+
['object' => $this, 'method' => 'getTestValue'],
157+
'Callback does not callable'
158+
],
159+
[
160+
'unknown_function',
161+
'Callback does not callable'
162+
],
163+
[
164+
new \stdClass(),
165+
'Callback does not callable'
166+
],
146167
[
147168
[$this, 'getTestValue'],
148169
'Callable expected to be an array with class name as first element',

0 commit comments

Comments
 (0)