Skip to content

Commit

Permalink
ensure compatibility with older PHPUnit mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Jan 24, 2019
1 parent 0c32302 commit 51dfa67
Show file tree
Hide file tree
Showing 18 changed files with 262 additions and 306 deletions.
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormConfigInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\JsonResponse;
Expand Down Expand Up @@ -487,8 +488,7 @@ public function testCreateNotFoundException()

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

$formFactory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock();
$formFactory->expects($this->once())->method('create')->willReturn($form);
Expand Down
Expand Up @@ -13,6 +13,7 @@

use Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager;
use Symfony\Bundle\WebProfilerBundle\Tests\TestCase;
use Symfony\Component\HttpKernel\Profiler\Profile;
use Twig\Environment;

/**
Expand Down Expand Up @@ -57,8 +58,7 @@ protected function setUp()
*/
public function testGetNameOfInvalidTemplate()
{
$profile = $this->mockProfile();
$this->templateManager->getName($profile, 'notexistingpanel');
$this->templateManager->getName(new Profile('token'), 'notexistingpanel');
}

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

$profile = $this->mockProfile();
$profile->expects($this->any())
->method('hasCollector')
->will($this->returnCallback([$this, 'profileHasCollectorCallback']));

$this->assertEquals('FooBundle:Collector:foo.html.twig', $this->templateManager->getName($profile, 'foo'));
$this->assertEquals('FooBundle:Collector:foo.html.twig', $this->templateManager->getName(new ProfileDummy(), 'foo'));
}

/**
Expand All @@ -85,17 +80,12 @@ public function testGetNameValidTemplate()
*/
public function testGetTemplates()
{
$profile = $this->mockProfile();
$profile->expects($this->any())
->method('hasCollector')
->will($this->returnCallback([$this, 'profilerHasCallback']));

$this->profiler->expects($this->any())
->method('has')
->withAnyParameters()
->will($this->returnCallback([$this, 'profileHasCollectorCallback']));

$result = $this->templateManager->getTemplates($profile);
$result = $this->templateManager->getTemplates(new ProfileDummy());
$this->assertArrayHasKey('foo', $result);
$this->assertArrayNotHasKey('bar', $result);
$this->assertArrayNotHasKey('baz', $result);
Expand Down Expand Up @@ -155,3 +145,22 @@ protected function mockProfiler()
return $this->profiler;
}
}

class ProfileDummy extends Profile
{
public function __construct()
{
parent::__construct('token');
}

public function hasCollector($name)
{
switch ($name) {
case 'foo':
case 'bar':
return true;
default:
return false;
}
}
}
2 changes: 2 additions & 0 deletions src/Symfony/Component/Form/Form.php
Expand Up @@ -532,6 +532,8 @@ public function submit($submittedData, $clearMissing = true)
$submittedData = null;
} elseif (is_scalar($submittedData)) {
$submittedData = (string) $submittedData;
} elseif ($this->config->getOption('allow_file_upload')) {
// no-op
} elseif (!$this->config->getOption('allow_file_upload') && $this->config->getRequestHandler()->isFileUpload($submittedData)) {
$submittedData = null;
$this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, file upload given.');
Expand Down
20 changes: 0 additions & 20 deletions src/Symfony/Component/Form/Tests/AbstractFormTest.php
Expand Up @@ -65,26 +65,6 @@ protected function getBuilder($name = 'name', EventDispatcherInterface $dispatch
return new FormBuilder($name, $dataClass, $dispatcher ?: $this->dispatcher, $this->factory, $options);
}

/**
* @param string $name
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function getMockForm($name = 'name')
{
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
$config = $this->getMockBuilder('Symfony\Component\Form\FormConfigInterface')->getMock();

$form->expects($this->any())
->method('getName')
->will($this->returnValue($name));
$form->expects($this->any())
->method('getConfig')
->will($this->returnValue($config));

return $form;
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
Expand Down

0 comments on commit 51dfa67

Please sign in to comment.