Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iqdevTranningProj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Александр Плохих
iqdevTranningProj
Commits
73614b75
Commit
73614b75
authored
10 months ago
by
Александр Плохих
Browse files
Options
Downloads
Patches
Plain Diff
STA-962 | fixes
parent
0797bd35
No related branches found
Branches containing commit
No related tags found
1 merge request
!17
Sta 962
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/tests/NewsTests/Controller/NewsControllerTests.php
+116
-42
116 additions, 42 deletions
app/tests/NewsTests/Controller/NewsControllerTests.php
app/tests/RestaurantTests/Controller/RestaurantsControllerTests.php
+121
-7
121 additions, 7 deletions
...RestaurantTests/Controller/RestaurantsControllerTests.php
with
237 additions
and
49 deletions
app/tests/NewsTests/Controller/NewsControllerTests.php
+
116
−
42
View file @
73614b75
...
...
@@ -2,7 +2,18 @@
namespace
App\Tests\NewsTests\Controller
;
use
App\News\Collection\NewsCategoryCollection
;
use
App\News\Dto\NewsCategoryDto
;
use
App\News\Dto\NewsDetailElementDto
;
use
App\News\Dto\NewsFilterVariantsDto
;
use
App\News\Dto\NewsListDto
;
use
App\News\Dto\NewsListingElementDto
;
use
App\Shared\Collection\ListingCollection
;
use
App\Shared\Dto\FileDto
;
use
App\Shared\Dto\PaginationDto
;
use
DateTimeImmutable
;
use
Symfony\Bundle\FrameworkBundle\Test\WebTestCase
;
use
Symfony\Component\HttpFoundation\JsonResponse
;
class
NewsControllerTests
extends
WebTestCase
{
...
...
@@ -14,14 +25,30 @@ class NewsControllerTests extends WebTestCase
'GET'
,
'/api/v1/news/00000000-0000-0000-0000-000000000000'
);
$data
=
$client
->
getResponse
()
->
getContent
();
self
::
assertResponseIsSuccessful
();
/** Проверка получемых новостей */
self
::
assertStringContainsString
(
'"id":"00000000-0000-0000-0000-000000000000","name":"news1","description":"Preview text","createAt":"17.05.2024","text":"Detail text","image":{"id":"00000000-0000-0000-0000-000000000000","name":"file1","description":"fileDescription","size":1024,"type":"png","url":"\/somewhere\/"'
,
$data
,
self
::
assertSame
(
(
new
JsonResponse
(
new
NewsDetailElementDto
(
'00000000-0000-0000-0000-000000000000'
,
'news1'
,
'Preview text'
,
(
new
DateTimeImmutable
())
->
format
(
'd.m.Y'
),
'Detail text'
,
new
FileDto
(
'00000000-0000-0000-0000-000000000000'
,
'file1'
,
'fileDescription'
,
1024
,
'png'
,
'/somewhere/'
),
)
))
->
getContent
(),
$client
->
getResponse
()
->
getContent
(),
'Полученная детальная новость инккоректена'
);
}
...
...
@@ -33,7 +60,6 @@ class NewsControllerTests extends WebTestCase
'GET'
,
'/api/v1/news/00000000-0000-0000-0000-000000000005'
);
$data
=
$client
->
getResponse
()
->
getContent
();
self
::
assertResponseStatusCodeSame
(
404
);
}
...
...
@@ -52,33 +78,62 @@ class NewsControllerTests extends WebTestCase
{
$client
=
static
::
createClient
();
$client
->
request
(
'GET'
,
'/api/v1/news/'
);
$data
=
$client
->
getResponse
()
->
getContent
();
self
::
assertResponseIsSuccessful
();
/** Проверка пагинации */
self
::
assertStringContainsString
(
'"pagination":{"currentPage":1,"pages":1,"pageSize":12}'
,
$data
,
'Пагинация инкорректна при пустом реквесте'
$testResponse
=
new
JsonResponse
(
new
NewsListDto
(
new
PaginationDto
(
1
,
1
,
12
),
new
ListingCollection
(
[
new
NewsListingElementDto
(
'00000000-0000-0000-0000-000000000000'
,
'news1'
,
(
new
DateTimeImmutable
())
->
format
(
'd.m.Y'
),
'api/v1/news/00000000-0000-0000-0000-000000000000'
,
'Preview text'
,
new
FileDto
(
'00000000-0000-0000-0000-000000000000'
,
'file1'
,
'fileDescription'
,
1024
,
'png'
,
'/somewhere/'
),
),
new
NewsListingElementDto
(
'00000000-0000-0000-0000-000000000001'
,
'news2'
,
(
new
DateTimeImmutable
())
->
format
(
'd.m.Y'
),
'api/v1/news/00000000-0000-0000-0000-000000000001'
,
null
,
null
,
),
],
),
new
NewsFilterVariantsDto
(
new
NewsCategoryCollection
(
[
new
NewsCategoryDto
(
'00000000-0000-0000-0000-000000000000'
,
'newsCategory1'
,
'newsCategory_1'
,
),
new
NewsCategoryDto
(
'00000000-0000-0000-0000-000000000001'
,
'newsCategory2'
,
'newsCategory_2'
,
),
]
),
),
),
);
/** Проверка получемых новостей */
self
::
assertStringContainsString
(
'"list":[{"id":"00000000-0000-0000-0000-000000000000","name":"news1","detailLink":"api\/v1\/news\/00000000-0000-0000-0000-000000000000","createAt":"17.05.2024","description":"Preview text","image":{"id":"00000000-0000-0000-0000-000000000000","name":"file1","description":"fileDescription","size":1024,"type":"png","url":"\/somewhere\/"}},{"id":"00000000-0000-0000-0000-000000000001","name":"news2","detailLink":"api\/v1\/news\/00000000-0000-0000-0000-000000000001","createAt":"17.05.2024","description":null,"image":null}]'
,
$data
,
'Полученный список новостей инккоректен при пустом реквесте'
);
/** Проверка фильтров */
self
::
assertStringContainsString
(
'"filterVariants"'
.
':{"category":[{"id":"00000000-0000-0000-0000-000000000000",'
.
'"name":"newsCategory1","code":"newsCategory_1"},'
.
'{"id":"00000000-0000-0000-0000-000000000001",'
.
'"name":"newsCategory2","code":"newsCategory_2"}]}'
,
$data
,
'Пагинация инкорректна при пустом реквесте'
self
::
assertSame
(
$testResponse
->
getContent
(),
$client
->
getResponse
()
->
getContent
(),
'Полученное тело респонза неверно'
);
}
...
...
@@ -92,9 +147,9 @@ class NewsControllerTests extends WebTestCase
/** Проверка пагинации */
self
::
assertStringContainsString
(
'"pagination":{"currentPage":1,"pages":1,"pageSize":12}'
,
(
new
JsonResponse
(
new
PaginationDto
(
1
,
1
,
12
)))
->
getContent
()
,
$data
,
'Пагинация инкор
р
ектна
при негативных значениях
'
'Пагинация инкоректна'
);
}
...
...
@@ -108,9 +163,9 @@ class NewsControllerTests extends WebTestCase
/** Проверка пагинации */
self
::
assertStringContainsString
(
'"pagination":{"currentPage":1,"pages":1,"pageSize":12}'
,
(
new
JsonResponse
(
new
PaginationDto
(
1
,
1
,
12
)))
->
getContent
()
,
$data
,
'Пагинация инкор
р
ектна
при позитивных значениях
'
'Пагинация инкоректна'
);
}
...
...
@@ -125,19 +180,38 @@ class NewsControllerTests extends WebTestCase
self
::
assertResponseIsSuccessful
();
/** Проверка получемых новостей */
self
::
assertStringNotContainsString
(
'"list":[{"id":"00000000-0000-0000-0000-000000000000",'
.
'"name":"news1","createAt":"2024-05-15 09:55:45",'
.
'"detailLink":"api\/v1\/news\/00000000-0000-0000-0000-000000000000"'
.
',"description":"Preview text",'
.
'"image":{"id":"00000000-0000-0000-0000-000000000000",'
.
'"name":"file1","description":"fileDescription","size":1024,'
.
'"type":"png","url":"\/somewhere\/"}},'
.
'{"id":"00000000-0000-0000-0000-000000000001",'
.
'"name":"news2","createAt":"2024-05-15 09:55:45",'
.
'"detailLink":"api\/v1\/news\/00000000-0000-0000-0000-000000000001",'
.
'"description":null,"image":null}]'
,
(
new
JsonResponse
(
new
ListingCollection
(
[
new
NewsListingElementDto
(
'00000000-0000-0000-0000-000000000000'
,
'news1'
,
(
new
DateTimeImmutable
())
->
format
(
'd.m.Y'
),
'api/v1/news/00000000-0000-0000-0000-000000000000'
,
'Preview text'
,
new
FileDto
(
'00000000-0000-0000-0000-000000000000'
,
'file1'
,
'fileDescription'
,
1024
,
'png'
,
'/somewhere/'
,
),
),
new
NewsListingElementDto
(
'00000000-0000-0000-0000-000000000001'
,
'news2'
,
(
new
DateTimeImmutable
())
->
format
(
'd.m.Y'
),
'api/v1/news/00000000-0000-0000-0000-000000000001'
,
null
,
null
,
),
]
)
))
->
getContent
(),
$data
,
'Полученный список новостей инккоректен при правильном фильтре'
);
...
...
This diff is collapsed.
Click to expand it.
app/tests/RestaurantTests/Controller/RestaurantsControllerTests.php
+
121
−
7
View file @
73614b75
...
...
@@ -2,7 +2,22 @@
namespace
App\Tests\RestaurantTests\Controller
;
use
App\Restaurants\Collection\KitchenCollection
;
use
App\Restaurants\Collection\RestaurantTypeCollection
;
use
App\Restaurants\Collection\TagCollection
;
use
App\Restaurants\Dto\KitchenTypeDto
;
use
App\Restaurants\Dto\RestaurantDetailElementDto
;
use
App\Restaurants\Dto\RestaurantFilterVariantsDto
;
use
App\Restaurants\Dto\RestaurantListingElementDto
;
use
App\Restaurants\Dto\RestaurantTypeDto
;
use
App\Restaurants\Dto\TagDto
;
use
App\Shared\Collection\FileCollection
;
use
App\Shared\Collection\ListingCollection
;
use
App\Shared\Collection\StringCollection
;
use
App\Shared\Dto\FileDto
;
use
App\Shared\Dto\PaginationDto
;
use
Symfony\Bundle\FrameworkBundle\Test\WebTestCase
;
use
Symfony\Component\HttpFoundation\JsonResponse
;
class
RestaurantsControllerTests
extends
WebTestCase
{
...
...
@@ -18,8 +33,56 @@ class RestaurantsControllerTests extends WebTestCase
self
::
assertResponseIsSuccessful
();
self
::
assertStringContainsString
(
'"id":"00000000-0000-0000-0000-000000000000","name":"Restaurant1","code":"restaurant_1","coordinates":"0.0.0.0","type":{"id":"00000000-0000-0000-0000-000000000001","name":"Type2","code":"type_2"},"check":"check1","check_info":"check1Info","kitchen":[{"id":"00000000-0000-0000-0000-000000000000","name":"Kitchen1","code":"kitchen_1"}],"phone":{"phone1":"+7000000000"},"email":{"email":"base@gmail.com"},"address":{"address":"somewhere"},"tags":[{"name":"setTags1","list":["tag1","tag2","tag3"]},{"name":"setTags2","list":["tag1","tag2","tag3"]}],"site":"www.restaurant.ru","image":{"id":"00000000-0000-0000-0000-000000000001","name":"image1","description":"description","size":512,"type":"jpg","url":"\/here\/"},"gallery":[]}'
,
self
::
assertSame
(
(
new
JsonResponse
(
new
RestaurantDetailElementDto
(
'00000000-0000-0000-0000-000000000000'
,
'Restaurant1'
,
'restaurant_1'
,
'0.0.0.0'
,
new
RestaurantTypeDto
(
'00000000-0000-0000-0000-000000000001'
,
'Type2'
,
'type_2'
,
),
'check1'
,
'check1Info'
,
new
KitchenCollection
(
[
new
KitchenTypeDto
(
'00000000-0000-0000-0000-000000000000'
,
'Kitchen1'
,
'kitchen_1'
),
]
),
new
StringCollection
([
'phone1'
=>
'+7000000000'
]),
new
StringCollection
([
'email'
=>
'base@gmail.com'
]),
new
StringCollection
([
'address'
=>
'somewhere'
]),
new
TagCollection
(
[
new
TagDto
(
'setTags1'
,
new
StringCollection
([
'tag1'
,
'tag2'
,
'tag3'
])
),
new
TagDto
(
'setTags2'
,
new
StringCollection
([
'tag1'
,
'tag2'
,
'tag3'
])
),
]
),
'www.restaurant.ru'
,
new
FileDto
(
'00000000-0000-0000-0000-000000000001'
,
'image1'
,
'description'
,
512
,
'jpg'
,
'/here/'
),
new
FileCollection
([])
)
))
->
getContent
(),
$data
,
'Полученная детальная новость инккоректена'
);
...
...
@@ -55,21 +118,72 @@ class RestaurantsControllerTests extends WebTestCase
/** Проверка пагинации */
self
::
assertStringContainsString
(
'"pagination":{"currentPage":1,"pages":1,"pageSize":12}'
,
(
new
JsonResponse
(
new
PaginationDto
(
1
,
1
,
12
),))
->
getContent
()
,
$data
,
'Пагинация инкорректна при пустом реквесте'
);
/** Проверка получемых новостей */
self
::
assertStringContainsString
(
'"list":[{"id":"00000000-0000-0000-0000-000000000000","name":"Restaurant1","detailLink":"api\/v1\/restaurants\/00000000-0000-0000-0000-000000000000","code":"restaurant_1","type":{"id":"00000000-0000-0000-0000-000000000001","name":"Type2","code":"type_2"},"check":"check1","image":{"id":"00000000-0000-0000-0000-000000000001","name":"image1","description":"description","size":512,"type":"jpg","url":"\/here'
,
(
new
JsonResponse
(
new
ListingCollection
(
[
new
RestaurantListingElementDto
(
'00000000-0000-0000-0000-000000000000'
,
'Restaurant1'
,
'restaurant_1'
,
new
RestaurantTypeDto
(
'00000000-0000-0000-0000-000000000001'
,
'Type2'
,
'type_2'
,
),
'api/v1/restaurants/00000000-0000-0000-0000-000000000000'
,
'check1'
,
new
FileDto
(
'00000000-0000-0000-0000-000000000001'
,
'image1'
,
'description'
,
512
,
'jpg'
,
'/here/'
),
),
]
)
))
->
getContent
(),
$data
,
'Полученный список новостей инккоректен при пустом реквесте'
);
/** Проверка фильтров */
self
::
assertStringContainsString
(
'"filterVariants":{"type":[{"id":"00000000-0000-0000-0000-000000000000","name":"Type1","code":"type_1"},{"id":"00000000-0000-0000-0000-000000000001","name":"Type2","code":"type_2"}],"kitchen":[{"id":"00000000-0000-0000-0000-000000000000","name":"Kitchen1","code":"kitchen_1"}]}'
,
(
new
JsonResponse
(
new
RestaurantFilterVariantsDto
(
new
RestaurantTypeCollection
(
[
new
RestaurantTypeDto
(
'00000000-0000-0000-0000-000000000000'
,
'Type1'
,
'type_1'
,
),
new
RestaurantTypeDto
(
'00000000-0000-0000-0000-000000000001'
,
'Type2'
,
'type_2'
,
),
]
),
new
KitchenCollection
(
[
new
KitchenTypeDto
(
'00000000-0000-0000-0000-000000000000'
,
'Kitchen1'
,
'kitchen_1'
,
)
]
)
)
))
->
getContent
(),
$data
,
'Пагинация инкорректна при пустом реквесте'
);
...
...
@@ -85,7 +199,7 @@ class RestaurantsControllerTests extends WebTestCase
/** Проверка пагинации */
self
::
assertStringContainsString
(
'"pagination":{"currentPage":1,"pages":1,"pageSize":12}'
,
(
new
JsonResponse
(
new
PaginationDto
(
1
,
1
,
12
),))
->
getContent
()
,
$data
,
'Пагинация инкорректна при негативных значениях'
);
...
...
@@ -101,7 +215,7 @@ class RestaurantsControllerTests extends WebTestCase
/** Проверка пагинации */
self
::
assertStringContainsString
(
'"pagination":{"currentPage":1,"pages":1,"pageSize":12}'
,
(
new
JsonResponse
(
new
PaginationDto
(
1
,
1
,
12
),))
->
getContent
()
,
$data
,
'Пагинация инкорректна при позитивных значениях'
);
...
...
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