public function create($candidate) { try { $userRepository = new UserRepository(); $candidate->user->accounttype = 0; $userRepository->create($candidate->user); $null = null; $req = $this->db->prepare('INSERT INTO candidates VALUES(:id, :userId, :cvId, :firstname, :lastname, :birthdate, :address, :phone, :email)'); $req->bindParam(':id', $candidate->id); $req->bindParam(':userId', !is_null($candidate->user) ? $candidate->user->id : $null); $req->bindParam(':cvId', !is_null($candidate->cv) ? $candidate->cv->id : $null); $req->bindParam(':firstname', $candidate->firstname); $req->bindParam(':lastname', $candidate->lastname); $req->bindParam(':birthdate', $candidate->birthdate); $req->bindParam(':address', $candidate->address); $req->bindParam(':phone', $candidate->phone); $req->bindParam(':email', $candidate->email); $req->execute(); } catch (PDOException $e) { } }
public function create($company) { try { $userRepository = new UserRepository(); $company->user->accounttype = 1; $userRepository->create($company->user); $null = null; $req = $this->db->prepare('INSERT INTO companies VALUES(:id, :userId, :name, :description, :address, :phone, :email, :logo, :cities)'); $req->bindParam(':id', $company->id); $req->bindParam(':userId', !is_null($company->user) ? $company->user->id : $null); $req->bindParam(':description', $company->description); $req->bindParam(':name', $company->name); $req->bindParam(':address', $company->address); $req->bindParam(':phone', $company->phone); $req->bindParam(':email', $company->email); $req->bindParam(':logo', $company->logo); $req->bindParam(':cities', $company->cities); $req->execute(); } catch (PDOException $e) { } }
/** @test **/ function it_persists_the_data_into_the_database() { $repository = new UserRepository($this->newContainerMock(new User())); $repository->create(['name' => 'Finn the Human', 'email' => '*****@*****.**']); $user = User::first(); $this->assertEquals('Finn the Human', $user->name); $this->assertEquals('*****@*****.**', $user->email); }