"You cannot define a mapping item when in a sequence" when running phpunit in symfony
Asked Answered
P

3

15

I'm getting the following errors when I try to run phpunit on my symfony project:

$ phpunit -c app

1) [...]\DefaultControllerTest::testIndex
Symfony\Component\Config\Exception\FileLoaderLoadException: Cannot import resource "/srv/http/typeform/app/config/config.yml" from "/srv/http/typeform/app/config/config_dev.yml".

/srv/http/typeform/vendor/symfony/src/Symfony/Component/Config/Loader/FileLoader.php:89
[...]
/srv/http/typeform/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php:39
/srv/http/typeform/src/QuickyForm/PublicBundle/Tests/Controller/DefaultControllerTest.php:11

Caused by
Symfony\Component\Yaml\Exception\ParseException: You cannot define a mapping item when in a sequence in "\/srv\/http\/typeform\/app\/config\/config.yml"

/usr/share/pear/Symfony/Component/Yaml/Parser.php:116
[...]
/srv/http/typeform/app/bootstrap.php.cache:520
/srv/http/typeform/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php:39
/srv/http/typeform/src/QuickyForm/PublicBundle/Tests/Controller/DefaultControllerTest.php:11

It seems that it crash when I call static::createClient();

Here's my config_test.yml

imports:
    - { resource: config_dev.yml }
Pocky answered 10/5, 2013 at 13:0 Comment(2)
You appear to be missing most of the default symfony content from config_test.yml - is there any particular reason for that?Emilie
because I was testing, when I use the default config_test.yml the problem is the sameExposition
E
30

The errors you are getting suggest that the app is failing to parse your 'config.yml' because "You cannot define a mapping item when in a sequence".

This means that in a yml file when defining array values you cannot provide both mapping entries in the form "key: value" and sequence entries in the form "- item" - all values must be either one or the other form.

So, this is ok:

group: 
  key: value
  key: value

This is also ok:

group: 
  - item 
  - item 

This is not ok:

group: 
  key: value
  - item 

The errors suggest that there is an occurrence of the last form in your config.yml, although if this is the case it ought to cause problems running your app in the browser and not just under phpunit.

Emilie answered 13/5, 2013 at 15:10 Comment(3)
thanks! Finally I notice that the error dissapear when I replace Yaml parser from 2.x to 1.xExposition
This is unfortunate, a format like this would be useful persons:\\ size: 2\\ - Alice\\ - Bob.Emanative
@Emanative Think of it like json - you can have an associative array, where the keys are strings (also used to represent an 'object'), or a numerically indexed array, where the numeric keys are implied by the order, but you can't combine the two. So in json your persons object would have to be something like {size:2,data[Alice,Bob]}.Emilie
N
0

Additionally, to redbirdo's answer, you should be aware that you might need to use - under the required tag's items. For example:

UserLogin:
  type: "object"
  required:
    - email
    - password
  security:
    basicAuth: [] .......
Nannienanning answered 12/9, 2022 at 7:23 Comment(0)
C
0

I had the case when I created values like this:

    fontColor:
      colors:
        - { label: 'Light', color: 'rgb(8,8,8)' }
        - { label: 'Dark', color: 'rgb(4,4,4)' }

After some confusion I remarked that instead of the minus signs '-' in the beginning of the lines with the values, I had an mdash —.
It seems I have copied it from some page where someone took care rather on nice presentation than on functionality. After replacing the mdashes by minus signs everything worked fine.

Capella answered 11/9, 2023 at 20:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.