Ejemplo n.º 1
0
 public function testDelete()
 {
     $factory = new EntityFactory();
     $taskAggregate = new TaskAggregate();
     $taskAggregate->setFactory($factory);
     //simulate post
     $description = 'zzzzzz' . microtime();
     $dueDate = '01/01/2999';
     $_POST['description'] = $description;
     $_POST['dueDate'] = $dueDate;
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $request = new Request();
     $response = $taskAggregate->saveTask($request);
     $this->assertEquals(1, $response->getData()->success);
     $pdo = Database::connect();
     $statement = $pdo->prepare('SELECT * FROM task WHERE dueDate=:dueDate AND description =:description');
     $statement->execute(array(':dueDate' => "2999-01-01 12:00:00", ':description' => $description));
     $result = $statement->fetch();
     //----------------------------------------------------------------------
     //delete data
     $_POST['id'] = $result['id'];
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $newRequest = new Request();
     $response = $taskAggregate->deleteTask($newRequest);
     $this->assertEquals(1, $response->getData()->success);
     $statement = $pdo->prepare('SELECT * FROM task WHERE id=:id AND deleted=:deleted');
     $statement->execute(array(':id' => $result['id'], ':deleted' => 1));
     $newResult = $statement->fetch();
     $this->assertNotEmpty($newResult);
     $stmt = $pdo->prepare('DELETE FROM task WHERE id = :id');
     $stmt->execute(array(':id' => $result['id']));
 }
Ejemplo n.º 2
0
Archivo: app.php Proyecto: nirolph/todo
    return require_once root . '/public/index.html';
});
$controller->add('/task/create', function () {
    $factory = new TaskEntityFactory();
    $taskAggregate = new TaskAggregate();
    $taskAggregate->setFactory($factory);
    $request = new Request();
    $response = $taskAggregate->saveTask($request);
    echo $response->getJSON();
});
$controller->add('/task/delete', function () {
    $factory = new TaskEntityFactory();
    $taskAggregate = new TaskAggregate();
    $taskAggregate->setFactory($factory);
    $request = new Request();
    $response = $taskAggregate->deleteTask($request);
    echo $response->getJSON();
});
$controller->add('/task/update-status', function () {
    $factory = new TaskEntityFactory();
    $taskAggregate = new TaskAggregate();
    $taskAggregate->setFactory($factory);
    $request = new Request();
    $response = $taskAggregate->changeTaskStatus($request);
    echo $response->getJSON();
});
$controller->add('/report/tasks', function () {
    $factory = new ReportEntityFactory();
    $reportAggregate = new ReportAggregate();
    $reportAggregate->setFactory($factory);
    $request = new Request();