Markdown

[Symfony] The annotation does not exist, or could not be auto-loaded.

The annotation does not exist, or could not be auto-loaded.

在外部用AJAX POST可以正常寫入,
但寫TEST的時候就會噴錯。`
[2017-06-17 20:26:51] request.INFO: Matched route “bankRegister”. {“route”:“bankRegister”,“route_parameters”:{"_controller":“AppBundle\Controller\BankController::registerAction”,"_route":“bankRegister”},“request_uri”:“http://localhost/bank/register",“method”:"POST”} []
[2017-06-17 20:26:51] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2017-06-17 20:26:51] request.CRITICAL: Uncaught PHP Exception Doctrine\Common\Annotations\AnnotationException:
"[Semantical Error]
The annotation "@Doctrine\ORM\Mapping\ID"
in property AppBundle\Entity\Bank::$id does not exist,
or could not be auto-loaded.“
at/home/eric_tu/BANK/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php line 54 {“exception”:”[object]
(Doctrine\Common\Annotations\AnnotationException(code: 0): [Semantical Error] The annotation “@Doctrine\ORM\Mapping\ID” in property AppBundle\Entity\Bank::$id does not exist, or could not be auto-loaded. at /home/eric_tu/BANK/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:54)"} []
ORM\ID -> ORM\Id 就可以了
| 22     /**~
| 23      * @ORM\Id~                                                                                                                  
| 24      * @ORM\Column(type="integer")~
| 25      * @ORM\GeneratedValue(strategy="AUTO")~
| 26      */~
| 27     private $id;~


附上AJAX與TEST
<DOCTYPE>
    <html>

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>TEST CATCH API</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script>
            var Submit = function() {
                var json = {
                    "username": "test",
                    "password": "test"
                }
                // FOR REGISTER
                $.ajax({
                    url: 'http://test123/bank/register',
                    //url: 'http://test123/bank/index',
                    // data: $('#sentToBack').serialize(),
                     data: JSON.stringify(json),
                    type: "POST",
                    dataType: 'text',

                    success: function(msg) {
                        // alert(msg);
                        console.log(msg)
                    },

                    error: function(xhr, ajaxOptions, thrownError) {
                        alert(xhr.status);
                        alert(thrownError);
                    }
                });

            }
        </script>
    </head>

    <body>
        <form id="sentToBack">
            <input type="text" name="Text" />
            <input type="button" value="送出" onClick="Submit()" />
        </form>
    </body>

    </html>
    /**
    * @group bb
    */
   public function testRegisterAction()
   {

       $postData = [
           'username' => 'C8763_' . mt_rand(0,9),
           'password' => '0000'
               ];
       $paramArray = [];
       $uploadFileArray = [];
       $contentTypeArray = ['CONTENT_TYPE' => 'application/json'];

       $client = static::createClient();
       $crawler = $client->request(
               'POST',
               'bank/register',
               $paramArray,
               $uploadFileArray,
               $contentTypeArray,
               json_encode($postData));
             //   $postData
             //  );
       // dump($postData);

       $this->assertEquals(200, $client->getResponse()->getStatusCode());
       $content = $client->getResponse()->getcontent();
       $responseCheck = json_decode($content, true);
//        dump($content);
//        $this->assertEquals($postData['username'], $responseCheck["username"]);
   }

留言