PHP Unit with square bracket ( [ ) for text field

2019-07-11 07:13发布

问题:

I am testing a web project using Laracasts\Integrated library (with PHPUNIT).

I have a following HTML form:

<input type="text" name = "company[0][name]" id="comp_0" />

I have the following test case:

/** @test **/
public function add_new()
{
   $this->type('New Company' , 'company[0][name]');
}

I get the following error:

Symfony\Component\CssSelector\Exception\SyntaxErrorException: Expected identifier or "*", but <number at 20> found.

I am searching and trying alot ... but i am not able to get the solution for it.

回答1:

Solution was simple:

/** @test **/
public function add_this()
{
  $this->storeInput('company[0][name]' , 'New Company Here On Nepal' ,true);
}


  public function storeInput($element, $text, $force = false)
    {
        if ($force) {
            $this->inputs[$element] = $text;
            return $this;
        }
        else {
            return parent::storeInput($element, $text);
        }
    }


标签: laravel-5