Skip to content

Commit 6f96c8a

Browse files
committed
ioc controller issues fixed
1 parent c5bfca4 commit 6f96c8a

File tree

6 files changed

+76
-60
lines changed

6 files changed

+76
-60
lines changed

app/Http/Controllers/DeploymentController.php

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace App\Http\Controllers;
44

55
use App;
6-
use App\Deployment;
7-
use App\Project;
8-
use App\Server;
6+
use App\DeploymentInterface;
7+
use App\ProjectInterface;
8+
use App\ServerInterface;
99

1010
class DeploymentController extends Controller
1111
{
@@ -17,13 +17,13 @@ public function __construct()
1717
/**
1818
* Display a listing of the resource.
1919
*
20-
* @param Project $project
21-
* @param Server $server
20+
* @param ProjectInterface $project
21+
* @param ServerInterface $server
2222
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
2323
*/
24-
public function index(Project $project, Server $server)
24+
public function index(ProjectInterface $project, ServerInterface $server)
2525
{
26-
$deploymentsCollection =$server->deployments()
26+
$deploymentsCollection = $server->deployments()
2727
->orderBy('created_at', 'desc')
2828
->paginate(10);
2929
return view('deployments.index',compact('deploymentsCollection','project','server'));
@@ -33,11 +33,11 @@ public function index(Project $project, Server $server)
3333
/**
3434
* Show the form for creating a new resource.
3535
*
36-
* @param Project $project
37-
* @param Server $server
36+
* @param ProjectInterface $project
37+
* @param ServerInterface $server
3838
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
3939
*/
40-
public function create(Project $project, Server $server)
40+
public function create(ProjectInterface $project, ServerInterface $server)
4141
{
4242
$gitLog = [];
4343
$connection = App::make(
@@ -57,11 +57,11 @@ public function create(Project $project, Server $server)
5757

5858
/**
5959
* Store a newly created resource in storage.
60-
* @param Project $project
61-
* @param Server $server
62-
* @return \Illuminate\Http\RedirectResponse
60+
* @param ProjectInterface $project
61+
* @param ServerInterface $server
62+
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
6363
*/
64-
public function store(Project $project, Server $server)
64+
public function store(ProjectInterface $project, ServerInterface $server)
6565
{
6666
$deployment = $server->executeDeployment([
6767
'user_id' => auth()->id(),
@@ -75,10 +75,12 @@ public function store(Project $project, Server $server)
7575
/**
7676
* Display the specified resource.
7777
*
78-
* @param \App\Deployment $deployment
79-
* @return \Illuminate\Http\Response
78+
* @param ProjectInterface $project
79+
* @param ServerInterface $server
80+
* @param DeploymentInterface $deployment
81+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
8082
*/
81-
public function show(Project $project,Server $server,Deployment $deployment)
83+
public function show(ProjectInterface $project, ServerInterface $server, DeploymentInterface $deployment)
8284
{
8385
return view('deployments.show', compact('project','server', 'deployment'));
8486
}
@@ -120,11 +122,11 @@ public function show(Project $project,Server $server,Deployment $deployment)
120122
/**
121123
* Show git diff
122124
*
123-
* @param Project $project
124-
* @param Server $server
125+
* @param ProjectInterface $project
126+
* @param ServerInterface $server
125127
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
126128
*/
127-
public function gitDiff(Project $project,Server $server)
129+
public function gitDiff(ProjectInterface $project,ServerInterface $server)
128130
{
129131
$gitDiff = [];
130132
$commitRef = request('commit');

app/Http/Controllers/ProjectController.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace App\Http\Controllers;
44

5-
use App\Project;
5+
use App;
6+
use App\ProjectInterface;
67

78
class ProjectController extends Controller
89
{
@@ -18,7 +19,7 @@ public function __construct()
1819
*/
1920
public function index()
2021
{
21-
$projectsCollection = Project::latest()
22+
$projectsCollection = (App::make('App\ProjectInterface'))::latest()
2223
->orderBy('created_at', 'desc')
2324
->paginate(10);
2425
return view('projects.index',compact('projectsCollection'));
@@ -40,7 +41,7 @@ public function create()
4041
*/
4142
public function store()
4243
{
43-
Project::create([
44+
(App::make('App\ProjectInterface'))::create([
4445
'user_id' => auth()->id(),
4546
'slug' => request('name'),
4647
'name' => request('name'),
@@ -52,44 +53,44 @@ public function store()
5253

5354
/**
5455
* Display the specified resource.
55-
* @param Project $project
56+
* @param ProjectInterface $project
5657
*
5758
* @return \Illuminate\Http\Response
5859
*/
59-
public function show(Project $project)
60+
public function show(ProjectInterface $project)
6061
{
6162
return view('projects.show', compact('project'));
6263
}
6364

6465
/**
6566
* Show the form for editing the specified resource.
6667
*
67-
* @param Project $project
68+
* @param ProjectInterface $project
6869
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
6970
*/
70-
public function edit(Project $project)
71+
public function edit(ProjectInterface $project)
7172
{
7273
return view('projects.edit', compact('project'));
7374
}
7475

7576
/**
7677
* Show the form for deleting the specified resource.
7778
*
78-
* @param Project $project
79+
* @param ProjectInterface $project
7980
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
8081
*/
81-
public function delete(Project $project)
82+
public function delete(ProjectInterface $project)
8283
{
8384
return view('projects.delete', compact('project'));
8485
}
8586

8687
/**
8788
* Update the specified resource in storage.
8889
*
89-
* @param Project $project
90-
* @return Project
90+
* @param ProjectInterface $project
91+
* @return ProjectInterface
9192
*/
92-
public function update(Project $project)
93+
public function update(ProjectInterface $project)
9394
{
9495
$project->update(request([
9596
'name',
@@ -102,11 +103,11 @@ public function update(Project $project)
102103
/**
103104
* Remove the specified resource from storage.
104105
*
105-
* @param Project $project
106+
* @param ProjectInterface $project
106107
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
107108
* @throws \Exception
108109
*/
109-
public function destroy(Project $project)
110+
public function destroy(ProjectInterface $project)
110111
{
111112
if(!request('confirm')){
112113
$error = \Illuminate\Validation\ValidationException::withMessages([

app/Http/Controllers/ServerController.php

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace App\Http\Controllers;
44

55
use App;
6-
use App\Project;
7-
use App\Server;
6+
use App\ProjectInterface;
7+
use App\ServerInterface;
88

99
class ServerController extends Controller
1010
{
@@ -16,10 +16,10 @@ public function __construct()
1616
/**
1717
* Display a listing of the resource.
1818
*
19-
* @param Project $project
19+
* @param ProjectInterface $project
2020
* @return \Illuminate\Http\Response
2121
*/
22-
public function index(Project $project)
22+
public function index(ProjectInterface $project)
2323
{
2424
$serversCollection = $project->servers()
2525
->orderBy('created_at', 'desc')
@@ -30,10 +30,10 @@ public function index(Project $project)
3030
/**
3131
* Show the form for creating a new resource.
3232
*
33-
* @param Project $project
33+
* @param ProjectInterface $project
3434
* @return \Illuminate\Http\Response
3535
*/
36-
public function create(Project $project)
36+
public function create(ProjectInterface $project)
3737
{
3838
$gitBranches = (App::make('App\GitInteractions\GitLocalInterface'))
3939
->getGitBranches($project->repository);
@@ -42,10 +42,10 @@ public function create(Project $project)
4242

4343
/**
4444
* Store a newly created resource in storage.
45-
* @param Project $project
45+
* @param ProjectInterface $project
4646
* @return \Illuminate\Http\RedirectResponse
4747
*/
48-
public function store(Project $project)
48+
public function store(ProjectInterface $project)
4949
{
5050
$project->addServer([
5151
'project_id' => $project->id,
@@ -68,22 +68,23 @@ public function store(Project $project)
6868
/**
6969
* Display the specified resource.
7070
*
71-
* @param \App\Server $server
72-
* @return \Illuminate\Http\Response
71+
* @param ProjectInterface $project
72+
* @param ServerInterface $server
73+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
7374
*/
74-
public function show(Project $project, Server $server)
75+
public function show(ProjectInterface $project, ServerInterface $server)
7576
{
7677
return view('servers.show', compact('project', 'server'));
7778
}
7879

7980
/**
8081
* Show the form for editing the specified resource.
8182
*
82-
* @param Project $project
83-
* @param Server $server
83+
* @param ProjectInterface $project
84+
* @param ServerInterface $server
8485
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
8586
*/
86-
public function edit(Project $project, Server $server)
87+
public function edit(ProjectInterface $project, ServerInterface $server)
8788
{
8889
$gitBranches = (App::make('App\GitInteractions\GitLocalInterface'))
8990
->getGitBranches($project->repository);
@@ -93,23 +94,23 @@ public function edit(Project $project, Server $server)
9394
/**
9495
* Show the form for deleting the specified resource.
9596
*
96-
* @param Project $project
97-
* @param Server $server
97+
* @param ProjectInterface $project
98+
* @param ServerInterface $server
9899
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
99100
*/
100-
public function delete(Project $project, Server $server)
101+
public function delete(ProjectInterface $project, ServerInterface $server)
101102
{
102103
return view('servers.delete', compact('project', 'server'));
103104
}
104105

105106
/**
106107
* Update the specified resource in storage.
107108
*
108-
* @param Project $project
109-
* @param Server $server
110-
* @return Server
109+
* @param ProjectInterface $project
110+
* @param ServerInterface $server
111+
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
111112
*/
112-
public function update(Project $project, Server $server)
113+
public function update(ProjectInterface $project, ServerInterface $server)
113114
{
114115
$server->update(request([
115116
'name',
@@ -129,12 +130,12 @@ public function update(Project $project, Server $server)
129130
/**
130131
* Remove the specified resource from storage.
131132
*
132-
* @param Project $project
133-
* @param Server $server
133+
* @param ProjectInterface $project
134+
* @param ServerInterface $server
134135
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
135136
* @throws \Exception
136137
*/
137-
public function destroy(Project $project, Server $server)
138+
public function destroy(ProjectInterface $project, ServerInterface $server)
138139
{
139140
if(!request('confirm')){
140141
$error = \Illuminate\Validation\ValidationException::withMessages([

app/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Server extends Model implements ServerInterface
1717
*/
1818
public function path(): string
1919
{
20-
return $this->project()->first()->path().'/servers/'.$this->slug;
20+
return $this->project()->first()->path().'/servers/'.$this->{$this->getRouteKeyName()};
2121
}
2222

2323
/**

routes/web.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
| contains the "web" middleware group. Now create something great!
4545
|
4646
*/
47+
Route::model('project','App\ProjectInterface');
48+
Route::model('server','App\ServerInterface');
49+
Route::model('deployment','App\DeploymentInterface');
4750

4851
Route::get('/', function () {
4952
return view('welcome');

tests/codeception/acceptance/UserIndexPageCest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ public function see_users_list(AcceptanceTester $I)
2525
$I->loginAsTheTestUser();
2626
$I->amOnPage($this->page);
2727
$I->seeCurrentUrlEquals($this->page);
28-
$I->click('ul.pagination li.page-item:nth-last-child(2) a');
28+
try {
29+
$I->click('ul.pagination li.page-item:nth-last-child(2) a');
30+
} catch (Exception $e) {
31+
}
2932
$I->see($this->user->email);
3033
}
3134

@@ -44,7 +47,10 @@ public function see_show_edit_delete_user_links(AcceptanceTester $I)
4447
$I->loginAsTheTestUser();
4548
$I->amOnPage($this->page);
4649
$I->seeCurrentUrlEquals($this->page);
50+
try {
4751
$I->click('ul.pagination li.page-item:nth-last-child(2) a');
52+
} catch (Exception $e) {
53+
}
4854
$I->seeElement('a[href="'.route('users.show', [$this->user]).'"]');
4955
$I->seeElement('a[href="'.route('users.edit', [$this->user]).'"]');
5056
$I->seeElement('form[action="'.route('user.destroy', [$this->user]).'"] button[data-title="Delete User"]');
@@ -57,7 +63,10 @@ public function see_show_edit_delete_user_links(AcceptanceTester $I)
5763
// $I->loginAsTheTestUser();
5864
// $I->amOnPage($this->page);
5965
// $I->seeCurrentUrlEquals($this->page);
66+
// try {
6067
// $I->click('ul.pagination li.page-item:nth-last-child(2) a');
68+
// } catch (Exception $e) {
69+
// }
6170
// $I->seeRecord('users', ['id' => $this->user->id]);
6271
// $I->click('form[action="'.route('user.destroy', [$this->user]).'"] button[data-title="Delete User"]');
6372
// $I->waitForElementVisible('#confirmDelete', 15);

0 commit comments

Comments
 (0)