liuggio / symfony2-rest-api-the-best-2013-way

Code for the article at:
http://welcometothebundle.com/symfony2-rest-api-the-best-2013-way/
MIT License
150 stars 46 forks source link

TestsErrors #11

Open bizmate opened 10 years ago

bizmate commented 10 years ago

Tests show these errors


vagrant@precise64:/var/www/symfony$ bin/phpunit -c app
PHPUnit 3.7.37 by Sebastian Bergmann.

Configuration read from /var/www/symfony/app/phpunit.xml.dist

...F.FFF.......EE

Time: 52.64 seconds, Memory: 51.50Mb

There were 2 errors:

1) BoShurik\SurveyBundle\Tests\Controller\SurveyControllerTest::testCompleteScenario
InvalidArgumentException: The current node list is empty.

/var/www/symfony/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Crawler.php:697
/var/www/symfony/src/BoShurik/SurveyBundle/Tests/Controller/SurveyControllerTest.php:18

2) BoShurik\UserBundle\Tests\Controller\RegistrationControllerTest::testRegistration
InvalidArgumentException: The current node list is empty.

/var/www/symfony/vendor/symfony/symfony/src/Symfony/Component/DomCrawler/Crawler.php:737
/var/www/symfony/src/BoShurik/UserBundle/Tests/Controller/RegistrationControllerTest.php:30

--

There were 4 failures:

1) Acme\BlogBundle\Tests\Controller\PageControllerTest::testJsonPostPageAction
{"code":400,"message":"Validation Failed","errors":{"errors":["The CSRF token is invalid. Please try to resubmit the form."],"children":{"title":[],"body":[]}}}
Failed asserting that 400 matches expected 201.

/var/www/symfony/src/Acme/BlogBundle/Tests/Controller/PageControllerTest.php:194
/var/www/symfony/src/Acme/BlogBundle/Tests/Controller/PageControllerTest.php:81

2) Acme\BlogBundle\Tests\Controller\PageControllerTest::testJsonPutPageActionShouldModify
{"code":400,"message":"Validation Failed","errors":{"errors":["The CSRF token is invalid. Please try to resubmit the form."],"children":{"title":[],"body":[]}}}
Failed asserting that 400 matches expected 204.

/var/www/symfony/src/Acme/BlogBundle/Tests/Controller/PageControllerTest.php:194
/var/www/symfony/src/Acme/BlogBundle/Tests/Controller/PageControllerTest.php:125

3) Acme\BlogBundle\Tests\Controller\PageControllerTest::testJsonPutPageActionShouldCreate
{"code":400,"message":"Validation Failed","errors":{"errors":["The CSRF token is invalid. Please try to resubmit the form."],"children":{"title":[],"body":[]}}}
Failed asserting that 400 matches expected 201.

/var/www/symfony/src/Acme/BlogBundle/Tests/Controller/PageControllerTest.php:194
/var/www/symfony/src/Acme/BlogBundle/Tests/Controller/PageControllerTest.php:155

4) Acme\BlogBundle\Tests\Controller\PageControllerTest::testJsonPatchPageAction
{"code":400,"message":"Validation Failed","errors":{"errors":["The CSRF token is invalid. Please try to resubmit the form."],"children":{"title":[],"body":[]}}}
Failed asserting that 400 matches expected 204.

/var/www/symfony/src/Acme/BlogBundle/Tests/Controller/PageControllerTest.php:194
/var/www/symfony/src/Acme/BlogBundle/Tests/Controller/PageControllerTest.php:174

FAILURES!
Tests: 17, Assertions: 47, Failures: 4, Errors: 2.

//composer file

{
    "name": "symfony/framework-standard-edition",
    "license": "MIT",
    "type": "project",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "~2.4",
        "doctrine/orm": "~2.2,>=2.2.3",
        "doctrine/doctrine-bundle": "~1.2",
        "twig/extensions": "~1.0",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~2.3",
        "sensio/framework-extra-bundle": "~3.0",
        "sensio/generator-bundle": "~2.3",
        "incenteev/composer-parameter-handler": "~2.0",
        "friendsofsymfony/user-bundle": "~2.0@dev",
        "friendsofsymfony/rest-bundle": "@dev",
        "jms/serializer-bundle": "@dev",
        "nelmio/api-doc-bundle": "@dev"
    },
    "require-dev": {
        "doctrine/doctrine-fixtures-bundle": "dev-master",
        "phpunit/phpunit": "3.7.*",
        "liip/functional-test-bundle":"dev-master",
        "phpunit/php-invoker":"~1.1"
    },
    "scripts": {
        "post-install-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "2.4-dev"
        }
    }
}
liuggio commented 10 years ago

I added the formats

liuggio commented 10 years ago

ehm seems a CSRFproblem, did you add the ... : http://welcometothebundle.com/symfony2-rest-api-the-best-way-part-3/#disable_csrf_with_rest ?

bizmate commented 10 years ago

Very likely i had not set this right as i reached the line executing the test: in http://welcometothebundle.com/symfony2-rest-api-the-best-2013-way/ where i had kind of guessed how to set configuration. I will double check tonight and close the ticket if that is the cause of the problem. I guess i ll do some more basic reading about FOSRest as i still need to get used to how to make it work with some extra features including authentication etc. Thanks

bizmate commented 10 years ago

Just to confirm that csrf was already disabled for api role

fos_rest: param_fetcher_listener: true view: view_response_listener: 'force' formats: xml: true json: true templating_formats: html: true format_listener: rules:

Still i get the failures in the AcmeBlogBundle