Skip to content

Commit 2e723de

Browse files
committed
Upgrade PHPUnit polyfills package, fix mock generation
1 parent 5586f15 commit 2e723de

33 files changed

Lines changed: 467 additions & 334 deletions

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"pear/html_common2": "^2.3.1"
3030
},
3131
"require-dev": {
32-
"yoast/phpunit-polyfills": "^1.0"
32+
"yoast/phpunit-polyfills": "^4.0"
3333
},
3434
"autoload": {
3535
"psr-0": {

‎tests/QuickForm2/Container/GroupTest.php‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
/** Sets up includes */
2323
require_once dirname(dirname(__DIR__)) . '/TestHelper.php';
24+
// pear-package-only require_once __DIR__ . '/../MockBuilderMethod.php';
2425

2526
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
2627

@@ -29,6 +30,8 @@
2930
*/
3031
class HTML_QuickForm2_Element_GroupTest extends TestCase
3132
{
33+
use HTML_QuickForm2_MockBuilderMethod;
34+
3235
public function testNoRenameOnEmptyGroupName()
3336
{
3437
$g1 = new HTML_QuickForm2_Container_Group();
@@ -308,17 +311,17 @@ public function testRequest17576Client()
308311
$element = $group->addElement('text', 'anElement');
309312

310313
$ruleGroup = $this->getMockBuilder('HTML_QuickForm2_Rule')
311-
->setMethods(['validateOwner', 'getJavascriptCallback'])
314+
->{self::$mockMethod}(['validateOwner', 'getJavascriptCallback'])
312315
->setConstructorArgs([$group])
313316
->getMock();
314317
$ruleGroup->expects($this->once())->method('getJavascriptCallback')
315-
->will($this->returnValue('groupCallback'));
318+
->willReturn('groupCallback');
316319
$ruleElement = $this->getMockBuilder('HTML_QuickForm2_Rule')
317-
->setMethods(['validateOwner', 'getJavascriptCallback'])
320+
->{self::$mockMethod}(['validateOwner', 'getJavascriptCallback'])
318321
->setConstructorArgs([$element])
319322
->getMock();
320323
$ruleElement->expects($this->once())->method('getJavascriptCallback')
321-
->will($this->returnValue('elementCallback'));
324+
->willReturn('elementCallback');
322325

323326
$group->addRule($ruleGroup, HTML_QuickForm2_Rule::CLIENT);
324327
$element->addRule($ruleElement, HTML_QuickForm2_Rule::CLIENT);
@@ -333,7 +336,7 @@ public function testFrozenGroupsHaveNoClientValidation()
333336
{
334337
$group = new HTML_QuickForm2_Container_Group('aGroup');
335338
$ruleGroup = $this->getMockBuilder('HTML_QuickForm2_Rule')
336-
->setMethods(['validateOwner', 'getJavascriptCallback'])
339+
->{self::$mockMethod}(['validateOwner', 'getJavascriptCallback'])
337340
->setConstructorArgs([$group])
338341
->getMock();
339342
$ruleGroup->expects($this->never())->method('getJavascriptCallback');

‎tests/QuickForm2/ContainerTest.php‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
/** Sets up includes */
2323
require_once dirname(__DIR__) . '/TestHelper.php';
2424

25+
// pear-package-only require_once __DIR__ . '/MockBuilderMethod.php';
2526
// pear-package-only require_once __DIR__ . '/../stubs/ElementImpl.php';
2627
// pear-package-only require_once __DIR__ . '/../stubs/ContainerImpl.php';
2728
// pear-package-only require_once __DIR__ . '/../stubs/RuleRequest17576.php';
@@ -33,6 +34,8 @@
3334
*/
3435
class HTML_QuickForm2_ContainerTest extends TestCase
3536
{
37+
use HTML_QuickForm2_MockBuilderMethod;
38+
3639
public function testCanSetName()
3740
{
3841
$obj = new ContainerImpl();
@@ -403,23 +406,23 @@ public function testValidate()
403406
$el2 = $cValidate->appendChild(new ElementImpl('bar'));
404407

405408
$ruleTrue1 = $this->getMockBuilder('HTML_QuickForm2_Rule')
406-
->setMethods(['validateOwner'])
409+
->{self::$mockMethod}(['validateOwner'])
407410
->setConstructorArgs([$cValidate, 'irrelevant message'])
408411
->getMock();
409412
$ruleTrue1->expects($this->once())->method('validateOwner')
410-
->will($this->returnValue(true));
413+
->willReturn(true);
411414
$ruleFalse = $this->getMockBuilder('HTML_QuickForm2_Rule')
412-
->setMethods(['validateOwner'])
415+
->{self::$mockMethod}(['validateOwner'])
413416
->setConstructorArgs([$el1, 'some error'])
414417
->getMock();
415418
$ruleFalse->expects($this->once())->method('validateOwner')
416-
->will($this->returnValue(false));
419+
->willReturn(false);
417420
$ruleTrue2 = $this->getMockBuilder('HTML_QuickForm2_Rule')
418-
->setMethods(['validateOwner'])
421+
->{self::$mockMethod}(['validateOwner'])
419422
->setConstructorArgs([$el2, 'irrelevant message'])
420423
->getMock();
421424
$ruleTrue2->expects($this->once())->method('validateOwner')
422-
->will($this->returnValue(true));
425+
->willReturn(true);
423426

424427
$cValidate->addRule($ruleTrue1);
425428
$el1->addRule($ruleFalse);
@@ -439,11 +442,11 @@ public function testRequest17576()
439442
$element = $container->appendChild(new ElementImpl('foo'));
440443

441444
$ruleChange = $this->getMockBuilder('HTML_QuickForm2_Rule')
442-
->setMethods(['validateOwner'])
445+
->{self::$mockMethod}(['validateOwner'])
443446
->setConstructorArgs([$element, 'a message'])
444447
->getMock();
445448
$ruleChange->expects($this->exactly(2))->method('validateOwner')
446-
->will($this->onConsecutiveCalls(true, false));
449+
->willReturn(true, false);
447450
$element->addRule($ruleChange);
448451

449452
$container->addRule(new RuleRequest17576(
@@ -466,17 +469,17 @@ public function testRequest17576Client()
466469
$element = $container->appendChild(new ElementImpl('anElement'));
467470

468471
$ruleContainer = $this->getMockBuilder('HTML_QuickForm2_Rule')
469-
->setMethods(['validateOwner', 'getJavascriptCallback'])
472+
->{self::$mockMethod}(['validateOwner', 'getJavascriptCallback'])
470473
->setConstructorArgs([$container])
471474
->getMock();
472475
$ruleContainer->expects($this->once())->method('getJavascriptCallback')
473-
->will($this->returnValue('containerCallback'));
476+
->willReturn('containerCallback');
474477
$ruleElement = $this->getMockBuilder('HTML_QuickForm2_Rule')
475-
->setMethods(['validateOwner', 'getJavascriptCallback'])
478+
->{self::$mockMethod}(['validateOwner', 'getJavascriptCallback'])
476479
->setConstructorArgs([$element])
477480
->getMock();
478481
$ruleElement->expects($this->once())->method('getJavascriptCallback')
479-
->will($this->returnValue('elementCallback'));
482+
->willReturn('elementCallback');
480483

481484
$container->addRule($ruleContainer, HTML_QuickForm2_Rule::CLIENT);
482485
$element->addRule($ruleElement, HTML_QuickForm2_Rule::CLIENT);
@@ -491,7 +494,7 @@ public function testFrozenContainersHaveNoClientValidation()
491494
{
492495
$container = new ContainerImpl('aContainer');
493496
$ruleContainer = $this->getMockBuilder('HTML_QuickForm2_Rule')
494-
->setMethods(['validateOwner', 'getJavascriptCallback'])
497+
->{self::$mockMethod}(['validateOwner', 'getJavascriptCallback'])
495498
->setConstructorArgs([$container])
496499
->getMock();
497500
$ruleContainer->expects($this->never())->method('getJavascriptCallback');

‎tests/QuickForm2/Controller/Action/BackTest.php‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
/** Sets up includes */
2323
require_once dirname(dirname(dirname(__DIR__))) . '/TestHelper.php';
24+
// pear-package-only require_once __DIR__ . '/../../MockBuilderMethod.php';
2425

2526
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
2627

@@ -29,25 +30,27 @@
2930
*/
3031
class HTML_QuickForm2_Controller_Action_BackTest extends TestCase
3132
{
33+
use HTML_QuickForm2_MockBuilderMethod;
34+
3235
public function testPerform()
3336
{
3437
$formOne = new HTML_QuickForm2('formOne');
3538
$formOne->addElement('text', 'foo')->setValue('foo value');
3639
$pageOne = $this->getMockBuilder('HTML_QuickForm2_Controller_Page')
37-
->setMethods(['populateForm'])
40+
->{self::$mockMethod}(['populateForm'])
3841
->setConstructorArgs([$formOne])
3942
->getMock();
4043
$formTwo = new HTML_QuickForm2('formTwo');
4144
$formTwo->addElement('text', 'bar')->setValue('bar value');
4245
$pageTwo = $this->getMockBuilder('HTML_QuickForm2_Controller_Page')
43-
->setMethods(['populateForm'])
46+
->{self::$mockMethod}(['populateForm'])
4447
->setConstructorArgs([$formTwo])
4548
->getMock();
4649
$mockJump = $this->getMockBuilder('HTML_QuickForm2_Controller_Action')
47-
->setMethods(['perform'])
50+
->{self::$mockMethod}(['perform'])
4851
->getMock();
4952
$mockJump->expects($this->exactly(2))->method('perform')
50-
->will($this->returnValue('jump to foo'));
53+
->willReturn('jump to foo');
5154
$pageOne->addHandler('jump', $mockJump);
5255
$controller = new HTML_QuickForm2_Controller('testBackAction');
5356
$controller->addPage($pageOne);
@@ -64,19 +67,19 @@ public function testPerform()
6467
public function testNoValidationForWizards()
6568
{
6669
$mockForm = $this->getMockBuilder('HTML_QuickForm2')
67-
->setMethods(['validate'])
70+
->{self::$mockMethod}(['validate'])
6871
->setConstructorArgs(['eternallyValid'])
6972
->getMock();
7073
$mockForm->expects($this->once())->method('validate')
71-
->will($this->returnValue(true));
74+
->willReturn(true);
7275
$mockPage = $this->getMockBuilder('HTML_QuickForm2_Controller_Page')
73-
->setMethods(['populateForm'])
76+
->{self::$mockMethod}(['populateForm'])
7477
->setConstructorArgs([$mockForm])
7578
->getMock();
7679
$mockPage->addHandler(
7780
'jump',
7881
$this->getMockBuilder('HTML_QuickForm2_Controller_Action')
79-
->setMethods(['perform'])
82+
->{self::$mockMethod}(['perform'])
8083
->getMock()
8184
);
8285

‎tests/QuickForm2/Controller/Action/DirectTest.php‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
/** Sets up includes */
2323
require_once dirname(dirname(dirname(__DIR__))) . '/TestHelper.php';
24+
// pear-package-only require_once __DIR__ . '/../../MockBuilderMethod.php';
2425

2526
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
2627

@@ -29,30 +30,32 @@
2930
*/
3031
class HTML_QuickForm2_Controller_Action_DirectTest extends TestCase
3132
{
33+
use HTML_QuickForm2_MockBuilderMethod;
34+
3235
public function testPerform()
3336
{
3437
$source = $this->getMockBuilder('HTML_QuickForm2')
35-
->setMethods(['validate', 'getValue'])
38+
->{self::$mockMethod}(['validate', 'getValue'])
3639
->setConstructorArgs(['source'])
3740
->getMock();
3841
$source->expects($this->once())->method('validate')
39-
->will($this->returnValue(true));
42+
->willReturn(true);
4043
$source->expects($this->once())->method('getValue')
41-
->will($this->returnValue(['foo' => 'bar']));
44+
->willReturn(['foo' => 'bar']);
4245
$sourcePage = $this->getMockBuilder('HTML_QuickForm2_Controller_Page')
43-
->setMethods(['populateForm'])
46+
->{self::$mockMethod}(['populateForm'])
4447
->setConstructorArgs([$source])
4548
->getMock();
4649
$sourcePage->addHandler('destination', new HTML_QuickForm2_Controller_Action_Direct());
4750
$destPage = $this->getMockBuilder('HTML_QuickForm2_Controller_Page')
48-
->setMethods(['populateForm'])
51+
->{self::$mockMethod}(['populateForm'])
4952
->setConstructorArgs([new HTML_QuickForm2('destination')])
5053
->getMock();
5154
$mockJump = $this->getMockBuilder('HTML_QuickForm2_Controller_Action')
52-
->setMethods(['perform'])
55+
->{self::$mockMethod}(['perform'])
5356
->getMock();
5457
$mockJump->expects($this->once())->method('perform')
55-
->will($this->returnValue('jump to destination'));
58+
->willReturn('jump to destination');
5659
$destPage->addHandler('jump', $mockJump);
5760

5861
$controller = new HTML_QuickForm2_Controller('testDirectAction');

‎tests/QuickForm2/Controller/Action/DisplayTest.php‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
/** Sets up includes */
2323
require_once dirname(dirname(dirname(__DIR__))) . '/TestHelper.php';
24+
// pear-package-only require_once __DIR__ . '/../../MockBuilderMethod.php';
2425

2526
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
2627

@@ -29,6 +30,8 @@
2930
*/
3031
class HTML_QuickForm2_Controller_Action_DisplayTest extends TestCase
3132
{
33+
use HTML_QuickForm2_MockBuilderMethod;
34+
3235
/**
3336
* Do not allow displaying a wizard page if preceding page(s) are not valid
3437
*
@@ -37,22 +40,22 @@ class HTML_QuickForm2_Controller_Action_DisplayTest extends TestCase
3740
public function testBug2323()
3841
{
3942
$pageFirst = $this->getMockBuilder('HTML_QuickForm2_Controller_Page')
40-
->setMethods(['populateForm'])
43+
->{self::$mockMethod}(['populateForm'])
4144
->setConstructorArgs([new HTML_QuickForm2('first')])
4245
->getMock();
4346
$mockJump = $this->getMockBuilder('HTML_QuickForm2_Controller_Action')
44-
->setMethods(['perform'])
47+
->{self::$mockMethod}(['perform'])
4548
->getMock();
4649
$mockJump->expects($this->once())->method('perform')
47-
->will($this->returnValue('jump to first'));
50+
->willReturn('jump to first');
4851
$pageFirst->addHandler('jump', $mockJump);
4952

5053
$pageSecond = $this->getMockBuilder('HTML_QuickForm2_Controller_Page')
51-
->setMethods(['populateForm'])
54+
->{self::$mockMethod}(['populateForm'])
5255
->setConstructorArgs([new HTML_QuickForm2('second')])
5356
->getMock();
5457
$mockDisplay = $this->getMockBuilder('HTML_QuickForm2_Controller_Action_Display')
55-
->setMethods(['renderForm'])
58+
->{self::$mockMethod}(['renderForm'])
5659
->getMock();
5760
$mockDisplay->expects($this->never())->method('renderForm');
5861
$pageSecond->addHandler('display', $mockDisplay);
@@ -67,22 +70,22 @@ public function testBug2323()
6770
public function testLoadFromSessionContainerOnDisplay()
6871
{
6972
$mockForm = $this->getMockBuilder('HTML_QuickForm2')
70-
->setMethods(['validate'])
73+
->{self::$mockMethod}(['validate'])
7174
->setConstructorArgs(['load'])
7275
->getMock();
7376
$foo = $mockForm->addElement('text', 'foo');
7477
$mockForm->expects($this->once())->method('validate')
75-
->will($this->returnValue(false));
78+
->willReturn(false);
7679
$mockPage = $this->getMockBuilder('HTML_QuickForm2_Controller_Page')
77-
->setMethods(['populateForm'])
80+
->{self::$mockMethod}(['populateForm'])
7881
->setConstructorArgs([$mockForm])
7982
->getMock();
8083
$mockPage->expects($this->once())->method('populateForm');
8184
$mockDisplay = $this->getMockBuilder('HTML_QuickForm2_Controller_Action_Display')
82-
->setMethods(['renderForm'])
85+
->{self::$mockMethod}(['renderForm'])
8386
->getMock();
8487
$mockDisplay->expects($this->once())->method('renderForm')
85-
->will($this->returnValue('a form'));
88+
->willReturn('a form');
8689
$mockPage->addHandler('display', $mockDisplay);
8790

8891
$controller = new HTML_QuickForm2_Controller('loadValues');
@@ -99,20 +102,20 @@ public function testLoadFromSessionContainerOnDisplay()
99102
public function testNoLoadFromSessionContainerOnOtherActions()
100103
{
101104
$mockForm = $this->getMockBuilder('HTML_QuickForm2')
102-
->setMethods(['validate'])
105+
->{self::$mockMethod}(['validate'])
103106
->setConstructorArgs(['noload'])
104107
->getMock();
105108
$foo = $mockForm->addElement('text', 'foo');
106109
$mockForm->expects($this->never())->method('validate');
107110
$mockPage = $this->getMockBuilder('HTML_QuickForm2_Controller_Page')
108-
->setMethods(['populateForm'])
111+
->{self::$mockMethod}(['populateForm'])
109112
->setConstructorArgs([$mockForm])
110113
->getMock();
111114
$mockDisplay = $this->getMockBuilder('HTML_QuickForm2_Controller_Action_Display')
112-
->setMethods(['renderForm'])
115+
->{self::$mockMethod}(['renderForm'])
113116
->getMock();
114117
$mockDisplay->expects($this->once())->method('renderForm')
115-
->will($this->returnValue('a form'));
118+
->willReturn('a form');
116119
$mockPage->addHandler('display', $mockDisplay);
117120

118121
$_REQUEST = [

0 commit comments

Comments
 (0)