Exemplo n.º 1
0
 });
 describe('->__toString()', function () {
     it('should return a string with user information', function () {
         $faker = \Faker\Factory::create();
         $uuid = new StringLiteral($faker->uuid);
         $actual = new User($uuid);
         expect(is_string($actual->__toString()))->equal(true);
     });
 });
 describe('->getId()', function () {
     it('should return the User\'s id', function () {
         $userFactory = new UserFactory();
         $faker = \Faker\Factory::create();
         $uuid = new StringLiteral($faker->uuid);
         $actual = new User($uuid);
         $actual = $userFactory->create();
         expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User');
         expect($actual->getId())->to->be->instanceof('Notes\\Domain\\ValueObject\\Uuid');
     });
 });
 describe('->getUsername()', function () {
     it('should return the User\'s username', function () {
         $faker = \Faker\Factory::create();
         $uuid = new StringLiteral($faker->uuid);
         $username = new StringLiteral($faker->userName);
         $actual = new User($uuid);
         $actual->setUsername($username);
         expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User');
         expect($actual->getUsername())->equal($username);
     });
 });
<?php

/**
 * Created by PhpStorm.
 * User: andrewscheerenberger
 * Date: 11/17/15
 * Time: 6:10 PM
 */
use Notes\Domain\Entity\UserFactory;
describe('', function () {
    describe('->__construct()', function () {
        it('Should create a new UserFactory object', function () {
            $actual = new UserFactory();
            expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\UserFactory');
        });
    });
    describe('->create()', function () {
        it('Should create a new user object', function () {
            $factory = new UserFactory();
            $actual = $factory->create();
            expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User');
        });
    });
});
Exemplo n.º 3
0
$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']);
});
$app->post('/users', function (Application $app, Request $request) use($repo, $userFactory) {
    $user = $userFactory->create();
    $user->setUsername(new StringLiteral("userFromPOST"));
    $newUser = $repo->add($user);
    return $app->json($repo->getUsers(), 201);
});
$app->before(function (Request $request) {
    if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
        $data = json_decode($request->getContent(), true);
        $request->request->replace(is_array($data) ? $data : array());
    }
});
$app->run();