$this->user1Key = new Uuid(); $user1 = new User($this->user1Key, $username, $password, $email, $firstName, $lastName); $count = $actual->count(); expect($actual->count())->to->equal($count); $actual->add($user1); $count++; expect($actual->count())->to->equal($count); //expect($actual->getUser($user1Key))->equal($user1); }); }); describe('->getUsers()', function () { it('should return an array of users', function () { $actual = new MysqlUserRepository(); $count = $actual->count(); $users = []; $users = $actual->getUsers(); expect(count($users))->to->equal($count); expect(array_pop($users))->to->be->instanceof('Notes\\Domain\\Entity\\User'); }); }); describe('->removeUserID(Uuid $id)', function () { it('should remove a user by a userID', function () { $actual = new MysqlUserRepository(); $count = $actual->count(); $count -= 1; $actual->removeById($this->user1Key); expect($actual->count())->to->equal($count); }); }); describe('->getUser($userID)', function () { it('should return a single user that has the userid given', function () {
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']); }); $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); });