8000 ensure compatibility with older PHPUnit mocks · symfony/symfony@51dfa67 · GitHub
[go: up one dir, main page]

Skip to content

Commit 51dfa67

Browse files
committed
ensure compatibility with older PHPUnit mocks
1 parent 0c32302 commit 51dfa67

18 files changed

+262
-306
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerTraitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1616
use Symfony\Component\DependencyInjection\Container;
1717
use Symfony\Component\Form\Form;
18+
use Symfony\Component\Form\FormConfigInterface;
1819
use Symfony\Component\HttpFoundation\BinaryFileResponse;
1920
use Symfony\Component\HttpFoundation\File\File;
2021
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -487,8 +488,7 @@ public function testCreateNotFoundException()
487488

488489
public function testCreateForm()
489490
{
490-
$config = $this->getMockBuilder('Symfony\Component\Form\FormConfigInterface')->getMock();
491-
$form = new Form($config);
491+
$form = new Form($this->getMockBuilder(FormConfigInterface::class)->getMock());
492492

493493
$formFactory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
494494
$formFactory->expects($this->once())->method('create')->willReturn($form);

src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager;
1515
use Symfony\Bundle\WebProfilerBundle\Tests\TestCase;
16+
use Symfony\Component\HttpKernel\Profiler\Profile;
1617
use Twig\Environment;
1718

1819
/**
@@ -57,8 +58,7 @@ protected function setUp()
5758
*/
5859
public function testGetNameOfInvalidTemplate()
5960
{
60-
$profile = $this->mockProfile();
61-
$this->templateManager->getName($profile, 'notexistingpanel');
61+
$this->templateManager->getName(new Profile('token'), 'notexistingpanel');
6262
}
6363

6464
/**
@@ -71,12 +71,7 @@ public function testGetNameValidTemplate()
7171
->withAnyParameters()
7272
->will($this->returnCallback([$this, 'profilerHasCallback']));
7373

74-
$profile = $this->mockProfile();
75-
$profile->expects($this->any())
76-
->method('hasCollector')
77-
->will($this->returnCallback([$this, 'profileHasCollectorCallback']));
78-
79-
$this->assertEquals('FooBundle:Collector:foo.html.twig', $this->templateManager->getName($profile, 'foo'));
74+
$this->assertEquals('FooBundle:Collector:foo.html.twig', $this->templateManager->getName(new ProfileDummy(), 'foo'));
8075
}
8176

8277
/**
@@ -85,17 +80,12 @@ public function testGetNameValidTemplate()
8580
*/
8681
public function testGetTemplates()
8782
{
88-
$profile = $this->mockProfile();
89-
$profile->expects($this->any())
90-
->method('hasCollector')
91-
->will($this->returnCallback([$this, 'profilerHasCallback']));
92-
9383
$this->profiler->expects($this->any())
9484
->method('has')
9585
->withAnyParameters()
9686
->will($this->returnCallback([$this, 'profileHasCollectorCallback']));
9787

98-
$result = $this->templateManager->getTemplates($profile);
88+
$result = $this->templateManager->getTemplates(new ProfileDummy());
9989
$this->assertArrayHasKey('foo', $result);
10090
$this->assertArrayNotHasKey('bar', $result);
10191
$this->assertArrayNotHasKey('baz', $result);
@@ -155,3 +145,22 @@ protected function mockProfiler()
155145
return $this->profiler;
156146
}
157147
}
148+
149+
class ProfileDummy extends Profile
150+
{
151+
public function __construct()
152+
{
153+
parent::__construct('token');
154+
}
155+
156+
public function hasCollector($name)
157+
{
158+
switch ($name) {
159+
case 'foo':
160+
case 'bar':
161+
return true;
162+
default:
163+
return false;
164+
}
165+
}
166+
}

src/Symfony/Component/Form/Form.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,8 @@ public function submit($submittedData, $clearMissing = true)
532532
$submittedData = null;
533533
} elseif (is_scalar($submittedData)) {
534534
$submittedData = (string) $submittedData;
535+
} elseif ($this->config->getOption('allow_file_upload')) {
536+
// no-op
535537
} elseif (!$this->config->getOption('allow_file_upload') && $this->config->getRequestHandler()->isFileUpload($submittedData)) {
536538
$submittedData = null;
537539
$this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, file upload given.');

src/Symfony/Component/Form/Tests/AbstractFormTest.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,6 @@ protected function getBuilder($name = 'name', EventDispatcherInterface $dispatch
6565
return new FormBuilder($name, $dataClass, $dispatcher ?: $this->dispatcher, $this->factory, $options);
6666
}
6767

68-
/**
69-
* @param string $name
70-
*
71-
* @return \PHPUnit_Framework_MockObject_MockObject
72-
*/
73-
protected function getMockForm($name = 'name')
74-
{
75-
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
76-
$config = $this->getMockBuilder('Symfony\Component\Form\FormConfigInterface')->getMock();
77-
78-
$form->expects($this->any())
79-
->method('getName')
80-
->will($this->returnValue($name));
81-
$form->expects($this->any())
82-
->method('getConfig')
83-
->will($this->returnValue($config));
84-
85-
return $form;
86-
}
87-
8868
/**
8969
* @return \PHPUnit_Framework_MockObject_MockObject
9070
*/

0 commit comments

Comments
 (0)
0