Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchCourrier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
MaarchCourrier
Commits
f5da4a68
Verified
Commit
f5da4a68
authored
5 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
FIX unit tests
parent
7b3c327e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/note/controllers/NoteController.php
+1
-1
1 addition, 1 deletion
src/app/note/controllers/NoteController.php
test/unitTests/app/note/NoteControllerTest.php
+30
-26
30 additions, 26 deletions
test/unitTests/app/note/NoteControllerTest.php
with
31 additions
and
27 deletions
src/app/note/controllers/NoteController.php
+
1
−
1
View file @
f5da4a68
...
@@ -75,7 +75,7 @@ class NoteController
...
@@ -75,7 +75,7 @@ class NoteController
return
$response
->
withJson
(
$note
);
return
$response
->
withJson
(
$note
);
}
}
public
function
create
(
Request
$request
,
Response
$response
,
array
$aArgs
)
public
function
create
(
Request
$request
,
Response
$response
)
{
{
$body
=
$request
->
getParsedBody
();
$body
=
$request
->
getParsedBody
();
...
...
This diff is collapsed.
Click to expand it.
test/unitTests/app/note/NoteControllerTest.php
+
30
−
26
View file @
f5da4a68
...
@@ -37,13 +37,14 @@ class NoteControllerTest extends TestCase
...
@@ -37,13 +37,14 @@ class NoteControllerTest extends TestCase
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$aArgs
=
[
$aArgs
=
[
'value'
=>
"Test d'ajout d'une note par php unit"
,
'value'
=>
"Test d'ajout d'une note par php unit"
,
'entities'
=>
[
'COU'
,
'CAB'
]
'entities'
=>
[
'COU'
,
'CAB'
],
'resId'
=>
self
::
$resId
];
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$response
=
$noteController
->
create
(
$fullRequest
,
new
\Slim\Http\Response
()
,
[
'resId'
=>
self
::
$resId
]
);
$response
=
$noteController
->
create
(
$fullRequest
,
new
\Slim\Http\Response
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
self
::
$noteId
=
$responseBody
->
noteId
;
self
::
$noteId
=
$responseBody
->
noteId
;
...
@@ -55,12 +56,13 @@ class NoteControllerTest extends TestCase
...
@@ -55,12 +56,13 @@ class NoteControllerTest extends TestCase
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$aArgs
=
[
$aArgs
=
[
'value'
=>
"Test d'ajout d'une note par php unit"
'value'
=>
"Test d'ajout d'une note par php unit"
,
'resId'
=>
self
::
$resId
];
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$response
=
$noteController
->
create
(
$fullRequest
,
new
\Slim\Http\Response
()
,
[
'resId'
=>
self
::
$resId
]
);
$response
=
$noteController
->
create
(
$fullRequest
,
new
\Slim\Http\Response
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
self
::
$noteId2
=
$responseBody
->
noteId
;
self
::
$noteId2
=
$responseBody
->
noteId
;
...
@@ -71,16 +73,17 @@ class NoteControllerTest extends TestCase
...
@@ -71,16 +73,17 @@ class NoteControllerTest extends TestCase
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'POST'
]);
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'POST'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$aArgs
=
[
$body
=
[
'entities'
=>
[
"COU"
,
"CAB"
]
'entities'
=>
[
"COU"
,
"CAB"
],
'resId'
=>
self
::
$resId
];
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$
aArgs
,
$request
);
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$
body
,
$request
);
$response
=
$noteController
->
create
(
$fullRequest
,
new
\Slim\Http\Response
()
,
[
'resId'
=>
self
::
$resId
]
);
$response
=
$noteController
->
create
(
$fullRequest
,
new
\Slim\Http\Response
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertSame
(
'
Data
value is empty or not a string'
,
$responseBody
->
errors
);
$this
->
assertSame
(
'
Body
value is empty or not a string'
,
$responseBody
->
errors
);
}
}
public
function
testUpdate
()
public
function
testUpdate
()
...
@@ -93,11 +96,12 @@ class NoteControllerTest extends TestCase
...
@@ -93,11 +96,12 @@ class NoteControllerTest extends TestCase
$aArgs
=
[
$aArgs
=
[
'value'
=>
"Test modification d'une note par php unit"
,
'value'
=>
"Test modification d'une note par php unit"
,
'entities'
=>
[
'COU'
,
'DGS'
]
'entities'
=>
[
'COU'
,
'DGS'
],
'resId'
=>
self
::
$resId
];
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$response
=
$noteController
->
update
(
$fullRequest
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId
,
'resId'
=>
self
::
$resId
]);
$response
=
$noteController
->
update
(
$fullRequest
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId
]);
$this
->
assertSame
(
204
,
$response
->
getStatusCode
());
$this
->
assertSame
(
204
,
$response
->
getStatusCode
());
...
@@ -106,14 +110,14 @@ class NoteControllerTest extends TestCase
...
@@ -106,14 +110,14 @@ class NoteControllerTest extends TestCase
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$aArgs
=
[
$aArgs
=
[
'value'
=>
''
'value'
=>
''
,
'resId'
=>
self
::
$resId
];
];
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$fullRequest
=
\httpRequestCustom
::
addContentInBody
(
$aArgs
,
$request
);
$response
=
$noteController
->
update
(
$fullRequest
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId
,
'resId'
=>
self
::
$resId
]);
$response
=
$noteController
->
update
(
$fullRequest
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId
]);
$this
->
assertSame
(
400
,
$response
->
getStatusCode
());
$this
->
assertSame
(
400
,
$response
->
getStatusCode
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertInternalType
(
'string'
,
$responseBody
->
errors
);
$this
->
assertInternalType
(
'string'
,
$responseBody
->
errors
);
...
@@ -127,7 +131,7 @@ class NoteControllerTest extends TestCase
...
@@ -127,7 +131,7 @@ class NoteControllerTest extends TestCase
// READ
// READ
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
$noteController
->
getById
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId
,
'resId'
=>
self
::
$resId
]);
$response
=
$noteController
->
getById
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId
]);
$this
->
assertSame
(
200
,
$response
->
getStatusCode
());
$this
->
assertSame
(
200
,
$response
->
getStatusCode
());
...
@@ -137,7 +141,7 @@ class NoteControllerTest extends TestCase
...
@@ -137,7 +141,7 @@ class NoteControllerTest extends TestCase
$this
->
assertSame
(
"Test modification d'une note par php unit"
,
$responseBody
->
value
);
$this
->
assertSame
(
"Test modification d'une note par php unit"
,
$responseBody
->
value
);
$this
->
assertInternalType
(
'array'
,
$responseBody
->
entities
);
$this
->
assertInternalType
(
'array'
,
$responseBody
->
entities
);
$response
=
$noteController
->
getById
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
999999999
,
'resId'
=>
self
::
$resId
]);
$response
=
$noteController
->
getById
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
999999999
]);
$this
->
assertSame
(
403
,
$response
->
getStatusCode
());
$this
->
assertSame
(
403
,
$response
->
getStatusCode
());
...
@@ -146,23 +150,23 @@ class NoteControllerTest extends TestCase
...
@@ -146,23 +150,23 @@ class NoteControllerTest extends TestCase
$this
->
assertSame
(
'Note out of perimeter'
,
$responseBody
->
errors
);
$this
->
assertSame
(
'Note out of perimeter'
,
$responseBody
->
errors
);
}
}
public
function
testGet
()
public
function
testGet
ByResId
()
{
{
$noteController
=
new
\Note\controllers\NoteController
();
$noteController
=
new
\Note\controllers\NoteController
();
// READ
// READ
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
$noteController
->
get
(
$request
,
new
\Slim\Http\Response
(),
[
'resId'
=>
self
::
$resId
]);
$response
=
$noteController
->
get
ByResId
(
$request
,
new
\Slim\Http\Response
(),
[
'resId'
=>
self
::
$resId
]);
$this
->
assertSame
(
200
,
$response
->
getStatusCode
());
$this
->
assertSame
(
200
,
$response
->
getStatusCode
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertInternalType
(
'array'
,
$responseBody
);
$this
->
assertInternalType
(
'array'
,
$responseBody
->
notes
);
$this
->
assertNotEmpty
(
$responseBody
);
$this
->
assertNotEmpty
(
$responseBody
->
notes
);
foreach
(
$responseBody
as
$value
)
{
foreach
(
$responseBody
->
notes
as
$value
)
{
$this
->
assertInternalType
(
'int'
,
$value
->
id
);
$this
->
assertInternalType
(
'int'
,
$value
->
id
);
$this
->
assertInternalType
(
'int'
,
$value
->
identifier
);
$this
->
assertInternalType
(
'int'
,
$value
->
identifier
);
$this
->
assertInternalType
(
'string'
,
$value
->
value
);
$this
->
assertInternalType
(
'string'
,
$value
->
value
);
...
@@ -182,14 +186,14 @@ class NoteControllerTest extends TestCase
...
@@ -182,14 +186,14 @@ class NoteControllerTest extends TestCase
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$noteController
=
new
\Note\controllers\NoteController
();
$noteController
=
new
\Note\controllers\NoteController
();
$response
=
$noteController
->
delete
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId
,
'resId'
=>
self
::
$resId
]);
$response
=
$noteController
->
delete
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId
]);
$this
->
assertSame
(
204
,
$response
->
getStatusCode
());
$this
->
assertSame
(
204
,
$response
->
getStatusCode
());
// READ
// READ
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$environment
=
\Slim\Http\Environment
::
mock
([
'REQUEST_METHOD'
=>
'GET'
]);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$request
=
\Slim\Http\Request
::
createFromEnvironment
(
$environment
);
$response
=
$noteController
->
getById
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId
,
'resId'
=>
self
::
$resId
]);
$response
=
$noteController
->
getById
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId
]);
$this
->
assertSame
(
403
,
$response
->
getStatusCode
());
$this
->
assertSame
(
403
,
$response
->
getStatusCode
());
...
@@ -200,12 +204,12 @@ class NoteControllerTest extends TestCase
...
@@ -200,12 +204,12 @@ class NoteControllerTest extends TestCase
// FAIL DELETE
// FAIL DELETE
$noteController
=
new
\Note\controllers\NoteController
();
$noteController
=
new
\Note\controllers\NoteController
();
$response
=
$noteController
->
delete
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId
,
'resId'
=>
self
::
$resId
]);
$response
=
$noteController
->
delete
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId
]);
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$responseBody
=
json_decode
((
string
)
$response
->
getBody
());
$this
->
assertSame
(
'Note out of perimeter'
,
$responseBody
->
errors
);
$this
->
assertSame
(
'Note out of perimeter'
,
$responseBody
->
errors
);
$this
->
assertSame
(
403
,
$response
->
getStatusCode
());
$this
->
assertSame
(
403
,
$response
->
getStatusCode
());
$noteController
->
delete
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId2
,
'resId'
=>
self
::
$resId
]);
$noteController
->
delete
(
$request
,
new
\Slim\Http\Response
(),
[
'id'
=>
self
::
$noteId2
]);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment