0

クラスの1つに問題があります(私は信じています)。大まかに言うと、クラスを開始する php ファイルにフォームを送信しています。いくつかの it メソッドにアクセスすることで、値がデータベースにあるかどうかを判断します。そうであれば、ブール値を返します。

問題があると思われるコードは次のとおりです。

public function territoryCheck($numberOut)

    {

        $this->numberOut = $numberOut;



        //Execute test

        $this->checkConnect();

        $stmt = $this->dbh->prepare("SELECT t_id FROM Territory WHERE t_id = :param1");

        $stmt->bindParam(':param1', $this->numberOut);

        $stmt->execute();   
        $count = $stmt->rowCount();



        //Determine value of test

        if($count == 0)

        {

            return FALSE;

        }   

    }



    public function publisherCheck($lName, $fName)

    {

        $this->lName = $lName;

        $this->fName = $fName;



        //Execute test

        $this->checkConnect();

        $stmt = $this->dbh->prepare("SELECT p_id FROM People WHERE lastName = :param1 AND firstName = :param2");

        $stmt->bindParam(':param1', $this->lName);

        $stmt->bindParam(':param2', $this->fName);

        $stmt->execute();
        $count = $stmt->rowCount();



        //Determine value of test

        if($count == FALSE)

        {

            return FALSE;

        }

        else

        {

            $dummyvar = $stmt->fetch();

            $this->p_id = implode($dummyvar);

        }



    }



    public function isTerritoryOut($numberOut)

    {

        //Execute test

        $this->checkConnect();

        $this->numberOut = $numberOut;

        $stmt = $this->dbh->prepare("SELECT t_id FROM checkIn WHERE t_id = :param1");

        $stmt->bindParam(':param1', $this->numberOut);

        $stmt->execute();
        $count = $stmt->rowCount();



        //Determine value of test

        if($count != 0)

        {

            return TRUE;

        }   

    }

3 つのメソッドがあり、それぞれが true または false を返すテストです。私はexecute()、fetch()、そして最後にrowCount()でテストして、必要な値をエミュレートしようとしました。どちらも機能していないようです。これらのメソッドを呼び出すコードは次のとおりです。

//Begin tests

    $checkOut->territoryCheck($numberOut);

    if($checkOut == FALSE)

    {

        $fail = "Territory number ".$numberOut." does not exist in our records. Please enter a valid territory. For more information, navigate to About.<\ br>";

    }



    $checkOut->publisherCheck($lName, $fName);

    if($checkOut == FALSE)

    {

        if($fail !== "")

            $fail .= "The publisher, ".$fName." ".$lName.", is not in our records. For more information, navigate to About.<\ br>";

        else

            $fail = "The publisher, ".$fName." ".$lName.", is not in our records. For more information, navigate to About.<\ br>";

    }



    $checkOut->isTerritoryOut($numberOut);

    if($checkOut === TRUE)

    {

        if($fail !== "")

            $fail .= "Territory number ".$numberOut." is currently checked out. Either the wrong number was entered or the territory hasn't been properly checked in.<\ br>";

        else

            $fail = "Territory number ".$numberOut." is currently checked out. Either the wrong number was entered or the territory hasn't been properly checked in.<\ br>";

    }

わかりやすくするために、コードの前半で fail を "" に設定しました。何が起こるかというと、失敗するはずの状況を意図的に作成したときに、これらすべてのテストが合格したかのように通過することです。たとえば、データベースには 1 ~ 130 の地域番号しかありません。150 を入力すると、基本的には存在することがわかります。

何が起こっているのかわからない、型キャスト?== 対 ===? など

どんな助けでも大歓迎です。

4

1 に答える 1

1

認めざるを得ないのは、その原因はかなり明白な問題であり、私はそれを考慮に入れることさえできなかったということです。各テストでは、戻り値を受け入れる変数を割り当てずにメソッドを呼び出すだけです (つまり、$checkOut->publisherCheck();代わりに$test = $checkOut->publisherCheck();.

于 2012-09-26T02:08:57.603 に答える