phpunit testing ???? how shall i compare to xml files before and after api function call(the function contains the stored procedure)

StackOverflow https://stackoverflow.com/questions/21401245

Question

after searching for a long time got this great article its really very nice but i am facing a bit problem here in my stuff as u have used direct mysql query in api i have used stored procedure in here and every time i have to compare two XML before and after even for a single short and sweet query so is there any alternative for this process but which is this secure please chk this out u will get i more clearly

database testing in php using phpunit,simpletest on api haveing stored procedure

or how shall i compare to xml files before and after api function call(the function contains the stored procedure) means i am able to get the before state with mysql-dump but the after but not getting the instant after xml state

sorry for the English but tried my best thanks for the help friend

have to write an unit test test for the api function

public function delete($userId)
    {
          // this function calls a stored procedure
               $sql = "CALL Delete_User_Details(:userId)";
                try {
                        $db = parent::getConnection();
                        $stmt = $db->prepare($sql);
                        $stmt->bindParam("userId", $userId);
                        $stmt->execute();
                        $id = $stmt->fetchObject();
                        if ($id == null) {
                        $delete_response->createJSONArray("DATABASE_ERROR",0);
                        } else {
                        $delete_response->createJSONArray("SUCCESS",1);
                        }
                } catch (PDOException $e) {
                    $delete_response->createJSONArray("DATABASE_ERROR",0);
                }
       return $delete_response->toJSON();
    }

i have writen this unit test for it now want to write an dbunit for it

 public function testDeleteUser()
 {
            $decodedResponse = $response->json();
            $this->assertEquals($response->getStatusCode(), 200);
            $this->assertEquals($decodedResponse['status']['StatusMSG'], 'SUCCESS');
            $this->assertEquals($decodedResponse['status']['Code'], '1');
 }

help guyss

Was it helpful?

Solution

u can just simply test it before by calling the query like

  $sql = "select * from user";

and compare it with BeforeDeleteUser.xml

And the Call Ur stored procedure

   $sql = "CALL Delete_User_Details(:userId)";

And for the after case just repeat the before one again

  $sql = "select * from user";

and compare it with AfterDeleteUser.xml

see the logic is very simple if u have 5 Users in BeforeDeleteUser.xml and it results true and after the call of CALL Delete_User_Details(:userId) stored procedure , the AfterDeleteUser.xml should contain only 4 user (or maybe idDelete field to 0 that depends on ur implementation)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top