| @@ -0,0 +1,33 @@ | ||
| <?php | ||
| class Client { | ||
| private $name; | ||
| private $phone; | ||
|
|
||
| function __construct($name, $phone) { | ||
| $this->name = $name; | ||
| $this->phone = $phone; | ||
| } | ||
| function setName($new_name) { | ||
| $this->name = (string) $new_name; | ||
| } | ||
| function getName() { | ||
| return $this->name; | ||
| } | ||
| function setPhone($new_phone) { | ||
| $this->phone = $new_phone; | ||
| } | ||
| function getPhone() { | ||
| return $this->phone; | ||
| } | ||
| static function getAll() { | ||
| return $_SESSION['list_of_clients']; | ||
| } | ||
| static function deleteAll() { | ||
| $_SESSION['list_of_clients'] = array(); | ||
| } | ||
| function save() { | ||
| $GLOBALS['DB']->exec("INSERT INTO clients (name) VALUES ('{$this->getName()}');"); | ||
| } | ||
|
|
||
| } | ||
| ?> |
| @@ -0,0 +1,31 @@ | ||
| <?php | ||
|
|
||
|
|
||
| /** | ||
| * @backupGlobals disabled | ||
| * @backupStaticAttributes disabled | ||
| */ | ||
|
|
||
| require_once "src/Client.php"; | ||
|
|
||
| $server = 'mysql:host=localhost;dbname=hair_salon_test'; | ||
| $username = 'root'; | ||
| $password = 'root'; | ||
| $DB = new PDO($server, $username, $password); | ||
|
|
||
| class ClientTest extends PHPUnit_Framework_TestCase { | ||
| function test_save() { | ||
| //Arrange | ||
| $name = "Abby"; | ||
| $phone = "253-921-5534"; | ||
| $test_client = new Client($name, $phone); | ||
|
|
||
| //Act | ||
| $test_client->save(); | ||
|
|
||
| //Assert | ||
| $result = Client::getAll(); | ||
| $this->asserEquals($test_client, $result[0]); | ||
| } | ||
| } | ||
| ?> |