MarcTroesken's avatar

Struggeling with a PHPUnit test in L5.1

Hi,

I´m writing some tests atm and have a test failing right now. I can´t find the error :(

I have a Form with

{!! Form::select('language_id', $languages->lists('name', 'id')->all(), null, ['class' => 'form-control']) !!}

and my test tries this:

$this->actingAs($user)->visit('categories/create')->select('language_id', 1)->press('Submit');

I get this Error

InvalidArgumentException: Nothing matched the filter [1] CSS query provided for [http://my-side.com/categories/create]
0 likes
3 replies
bobbybouwmann's avatar

Are you sure the select field is filled? Since you run a test the data is probably coming from another database and the languages select is not filled since their is no data for languages in the database. Try to fill the languages database before executing this command

MarcTroesken's avatar

Looks like this in the browser:

<select class="form-control" id="language_id" name="language_id">
    <option value="1">Deutschland</option>
</select>
1 like
Thatdoorsajar's avatar

You have probably been using Jeffreys Integration package before the move to L5.1 in which the attribute order for form testing methods was:

$this->method($elementName, $value)

However in Illuminate\Foundation\Testing\CrawlerTrait it has been reversed:

$this->method($value, $elementName)

Your code should therefore be:

$this->actingAs($user)->visit('categories/create')->select(1, 'language_id')->press('Submit');

Thanks, James

1 like

Please or to participate in this conversation.