$email = "*****@*****.**";
            $firstName = "Gary";
            $lastName = "Grice";
            $this->user1Key = new Uuid();
            $user1 = new User($this->user1Key, $username, $password, $email, $firstName, $lastName);
            $actual->add($user1);
            $returnedUser = $actual->getUser($this->user1Key);
            expect($returnedUser)->to->be->instanceof('Notes\\Domain\\Entity\\User');
            expect($returnedUser->getUserName())->to->equal($user1->getUserName());
        });
    });
    describe('->containsUser($userID)', function () {
        it('should return true if the user is in the database and false if they are not', function () {
            $actual = new MysqlUserRepository();
            expect($actual->containsUser($this->user1Key))->to->equal(true);
            $fakeId = new Uuid();
            expect($actual->containsUser($fakeId))->to->equal(false);
        });
    });
    describe('->modify($userID)', function () {
        it('should modify a user with the ID given with one or more input values', function () {
            $actual = new MysqlUserRepository();
            $passwordU = "OldDannyBrown12\$";
            $emailU = "*****@*****.**";
            $actual->modify($this->user1Key, '', '', $passwordU, $emailU, '');
            $returnedUser = $actual->getUser($this->user1Key);
            expect($returnedUser)->to->be->instanceof('Notes\\Domain\\Entity\\User');
            expect($returnedUser->getEmail())->to->equal($emailU);
        });
    });
});
Exemplo n.º 2
0
    if (!isset($data['email'])) {
        $this->abort(406, 'Invalid Input');
    }
    $user = $userBuilder->build($data['email'], $data['firstName'], $data['lastName']);
    $repo->add($user);
    $success_message = "Success";
    $response = new Response(json_encode($success_message, 200));
    $response->headers->set('Content-Type', 'application/json');
    $response->headers->set('Content-Length', strlen($success_message));
    return $response;
});
$app->get('/', function () {
    return new Response('<h1>Final Project</h1>', 200);
});
$app->get('/users', function () {
    $sort = isset($_REQUEST['sort']) ? strtoupper(['sort']) : null;
    $repo = new MysqlUserRepository();
    $decoded_json = json_decode($repo->getAll());
    if (isset($sort)) {
        if ($sort == 'ASC') {
            $decoded_json = asort($decoded_json);
        } else {
            $decoded_json = arsort($decoded_json);
        }
    }
    $response = new Response($decoded_json, 200);
    $response->headers->set('Content-Type', 'application/json');
    $response->headers->set('Content-Length', strlen($decoded_json));
    return $response;
});
$app->run();
Exemplo n.º 3
0
 <?php 
require_once __DIR__ . '/vendor/autoload.php';
//require_once __DIR__ . '';
use Silex\Application;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Notes\Persistence\Entity\MysqlUserRepository;
use Notes\Domain\Entity\UserFactory;
use Notes\Domain\ValueObject\StringLiteral;
$app = new Application();
$app['debug'] = true;
$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$username = '******';
$password = '******';
$repo = new MysqlUserRepository($dsn, $username, $password);
$userFactory = new UserFactory();
$app->get('/', function () {
    return new Response('Final Project API', 200);
});
$app->get('/users', function (Request $request) use($repo) {
    $sort = strtolower($request->get("sort-username"));
    $users = $repo->getUsers();
    /* ran out of time cuz my virtual machine crashed, so i didnt implement them!!
        if($sort == 'dsc') {
    
        }
        elseif($sort == "asc") {
    
        }*/
    return new Response(json_encode($users), 200, ['Content-Type' => 'application/json']);
});