我的应用程序中有以下结构:
|
|----user folder
| |
| |-----Member.php
| |
| |---- tests Folder
| |
| |-----Member.php
这是我Member.php
的用户文件夹:
<?php
namespace user;
class Member
{
private $firstName;
private $lastName;
private $email;
private $password;
private $cell;
public function __construct()
{
}
public function getFirstName()
{
return $this->firstName;
}
public function setFirstName($firstName)
{
$this->firstName = $firstName;
return TRUE;
}
public function getLastName()
{
return $this->lastName;
}
public function setLastName($lastName)
{
$this->lastName = $lastName;
return TRUE;
}
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
$this->email = $email;
return TRUE;
}
public function getPassword()
{
return $this->password;
}
public function setPassword($password)
{
$this->password = $password;
return TRUE;
}
public function getCell()
{
return $this->cell;
}
public function setCell($cell)
{
$this->cell = $cell;
return TRUE;
}
}
这是我在测试文件夹中的 Member.php:
<?php
/*
* Member class getters and setters tests
*/
namespace user;
use user;
$member = new Member();
$member->setFirstName("Javad");
if($member->getFirstName() == "Javad")
echo "Test code 1 passed";
else
echo "Test code 1 failed";
$member = new Member();
$member->setLastName("Akbari");
if($member->getLastName() == "Akbari")
echo "Test code 2 passed";
else
echo "Test code 2 failed";
$member = new Member();
$member->setEmail("j2omrani@gmail.com");
if($member->getEmail() == "j2omrani@gmail.com")
echo "Test code 3 passed";
else
echo "Test code 3 failed";
$member = new Member();
$member->setPassword("123456");
if($member->getPassword() == "123456")
echo "Test code 4 passed";
else
echo "Test code 4 failed";
$member = new Member();
$member->setCell("09121234567");
if($member->getCell() == "09121234567")
echo "Test code 5 passed";
else
echo "Test code 5 failed";
当我想创建一个对象时,它会抛出异常并说:
Fatal error: Class 'user\Member' not found in C:\xampp\htdocs\auto24\user\tests\Member.php on line 8
我的问题是如何使用命名空间调用测试文件夹文件中的成员对象?