expect($actual)->to->be->instanceof('Notes\\Domain\\Entity\\User');
        });
    });
    describe('->setEmail()', function () {
        it('should change the email property of this UserBuilder object.', function () {
            $builder = new UserBuilder();
            $faker = \Faker\Factory::create();
            $email = $faker->email;
            $builder->setEmail($email);
            expect($builder->getEmail())->equal($email);
        });
    });
    describe('->setFirstname()', function () {
        it('should change the firstname property of this UserBuilder object.', function () {
            $builder = new UserBuilder();
            $faker = \Faker\Factory::create();
            $firstname = $faker->firstName;
            $builder->setFirstname($firstname);
            expect($builder->getFirstname())->equal($firstname);
        });
    });
    describe('->setLastname()', function () {
        it('should change the lastname property of this UserBuilder object.', function () {
            $builder = new UserBuilder();
            $faker = \Faker\Factory::create();
            $lastname = $faker->userName;
            $builder->setLastname($lastname);
            expect($builder->getLastname())->equal($lastname);
        });
    });
});
Пример #2
0
 * Date: 12/8/2015
 * Time: 10:00 AM
 */
require_once __DIR__ . '/../vendor/autoload.php';
use Silex\Application;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Notes\Domain\Entity\UserBuilder;
use Notes\Persistence\Entity\MysqlUserRepository;
$app = new Application();
$app->post('/users', function (Request $request) {
    $data = json_decode($request->getContent(), true);
    $request->request->replace(is_array($data) ? $data : array());
    $data = array('email' => $request->request->get('email'), 'firstName' => $request->request->get('firstName'), 'lastName' => $request->request->get('lastName'));
    $repo = new MysqlUserRepository();
    $userBuilder = new UserBuilder();
    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 () {