如何在 POSTMAN Rest API 中测试 OOP Php 函数
How To Test OOP Php Functions In POSTMAN Rest API
我正在练习以 OOP
格式制作 php
脚本。我即将在我的 php
脚本中测试我的 methods
。问题是,我如何专门测试我制作的那些 methods
?
http://localhost/tryhard/OOP/dbConnectClass.php
- 我应该把他们的 method
名字放在哪里?
Postman 用于构建、测试和记录 API。如果你想测试你的方法你必须创建一个PHP文件,导入class文件,创建对象并调用方法。
您不能直接调用 Postman 中的方法。
像这样创建文件:
文件名:testapi.php
<?php
import('dbConnectClass.php');
$dbConnect=new DBConnect(); // Assuming class name is DBConnect()
$returnvalue=$dbConnect->methodName();
echo $returnvalue;
// You can return output as JSON here.
?>
试试这个。
<?php
class parent{
function __construct() {
$self::mymethod();
}
public function mymethod(){
//do your thing
}
}
$class_object = new parent();
?>
当您调用 dbConnectClass.php
时,php 脚本将执行,它将创建 class 对象,构造函数将自动调用并调用您的方法。
我在当前项目中使用的是这样的东西。
我正在练习以 OOP
格式制作 php
脚本。我即将在我的 php
脚本中测试我的 methods
。问题是,我如何专门测试我制作的那些 methods
?
http://localhost/tryhard/OOP/dbConnectClass.php
- 我应该把他们的 method
名字放在哪里?
Postman 用于构建、测试和记录 API。如果你想测试你的方法你必须创建一个PHP文件,导入class文件,创建对象并调用方法。
您不能直接调用 Postman 中的方法。
像这样创建文件:
文件名:testapi.php
<?php
import('dbConnectClass.php');
$dbConnect=new DBConnect(); // Assuming class name is DBConnect()
$returnvalue=$dbConnect->methodName();
echo $returnvalue;
// You can return output as JSON here.
?>
试试这个。
<?php
class parent{
function __construct() {
$self::mymethod();
}
public function mymethod(){
//do your thing
}
}
$class_object = new parent();
?>
当您调用 dbConnectClass.php
时,php 脚本将执行,它将创建 class 对象,构造函数将自动调用并调用您的方法。
我在当前项目中使用的是这样的东西。