Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form] fixed bug - name in ButtonBuilder #19306

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bugfix in Form ButtonBuilder + test
  • Loading branch information
cheprasov committed Jul 6, 2016
commit 0619e08a25efa19f98a4e5351ed5afc4c4f2708a
5 changes: 3 additions & 2 deletions 5 src/Symfony/Component/Form/ButtonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
*/
public function __construct($name, array $options = array())
{
if (empty($name) && 0 != $name) {
$name = (string) $name;
if ('' === $name) {
throw new InvalidArgumentException('Buttons cannot have empty names.');
}

$this->name = (string) $name;
$this->name = $name;
$this->options = $options;
}

Expand Down
71 changes: 71 additions & 0 deletions 71 src/Symfony/Component/Form/Tests/ButtonBuilderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Form\Tests;

use Symfony\Component\Form\ButtonBuilder;

/**
* @author Alexander Cheprasov <cheprasov.84@ya.ru>
*/
class ButtonBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* @return array
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for the docblocks in tests.

public function getValidNames()
{
return array(
array('reset'),
array('submit'),
array('foo'),
array('0'),
array(0),
array('button[]'),
);
}

/**
* @dataProvider getValidNames
*
* @param string $name
*/
public function testValidNames($name)
{
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder($name));
}

/**
* @return array
*/
public function getInvalidNames()
{
return array(
array(''),
array(false),
array(null),
);
}

/**
* @dataProvider getInvalidNames
*
* @param string $name
*/
public function testInvalidNames($name)
{
$this->setExpectedException(
'\Symfony\Component\Form\Exception\InvalidArgumentException',
'Buttons cannot have empty names.'
);
new ButtonBuilder($name);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.