Skip to content

Commit e2733f7

Browse files
committed
Fix style for tests also.
1 parent 1e59c1e commit e2733f7

12 files changed

+82
-127
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
$finder = (new PhpCsFixer\Finder())
4-
->in(__DIR__ . "/src")
4+
->in([__DIR__ . "/src", __DIR__ . "/tests"]);
55
;
66
$rules = [
77
'@PER-CS2.0' => true,

tests/Feature/AssetTest.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
use Storyblok\ManagementApi\Data\AssetsData;
66
use Storyblok\ManagementApi\Endpoints\AssetApi;
77
use Storyblok\ManagementApi\ManagementApiClient;
8-
98
use Storyblok\ManagementApi\QueryParameters\AssetsParams;
109
use Storyblok\ManagementApi\QueryParameters\PaginationParams;
1110
use Symfony\Component\HttpClient\MockHttpClient;
1211
use Symfony\Component\HttpClient\Response\JsonMockResponse;
1312

14-
1513
test('Testing One asset, AssetData', function (): void {
1614
$responses = [
1715
\mockResponse("one-asset", 200),
@@ -24,7 +22,7 @@
2422

2523
$storyblokResponse = $assetApi->get("111");
2624

27-
$storyblokData = $storyblokResponse->data();
25+
$storyblokData = $storyblokResponse->data();
2826
expect($storyblokData->get("id"))
2927
->toBe(111)
3028
->and($storyblokData->filenameCDN())->toBe("https://a.storyblok.com/f/222/3799x6005/3af265ee08/mypic.jpg")
@@ -35,9 +33,8 @@
3533
->and($storyblokData->updatedAt())->toBe('2025-01-19');
3634

3735
$storyblokResponse = $assetApi->get("111notexists");
38-
expect( $storyblokResponse->getResponseStatusCode())->toBe(404) ;
39-
expect( $storyblokResponse->asJson())->toBe('["This record could not be found"]');
40-
36+
expect($storyblokResponse->getResponseStatusCode())->toBe(404) ;
37+
expect($storyblokResponse->asJson())->toBe('["This record could not be found"]');
4138

4239
});
4340

@@ -54,27 +51,26 @@
5451
$storyblokResponse = $assetApi->page();
5552

5653
/** @var AssetsData $storyblokData */
57-
$storyblokData = $storyblokResponse->data();
54+
$storyblokData = $storyblokResponse->data();
5855
foreach ($storyblokData as $asset) {
5956
expect($asset->id())->toBeGreaterThan(10);
6057
}
6158

6259
expect($storyblokResponse->getResponseStatusCode())->toBe(200);
63-
expect( $storyblokResponse->getErrorMessage())->toBe("No error detected, HTTP Status Code: 200") ;
60+
expect($storyblokResponse->getErrorMessage())->toBe("No error detected, HTTP Status Code: 200") ;
6461
expect($storyblokResponse->total())->toBe(2);
6562
expect($storyblokResponse->perPage())->toBe(25);
6663

6764
$storyblokResponse = $assetApi->page(page: new \Storyblok\ManagementApi\QueryParameters\PaginationParams(page: 100000));
68-
expect( $storyblokResponse->getResponseStatusCode())->toBe(404) ;
69-
expect( $storyblokResponse->asJson())->toBe('["This record could not be found"]');
70-
expect( $storyblokResponse->isOk())->toBeFalse() ;
71-
expect( $storyblokResponse->getErrorMessage())->toStartWith("404 - Not Found.") ;
65+
expect($storyblokResponse->getResponseStatusCode())->toBe(404) ;
66+
expect($storyblokResponse->asJson())->toBe('["This record could not be found"]');
67+
expect($storyblokResponse->isOk())->toBeFalse() ;
68+
expect($storyblokResponse->getErrorMessage())->toStartWith("404 - Not Found.") ;
7269

7370
$assetsData = AssetsData::make([]);
7471
expect($assetsData)->toBeInstanceOf(AssetsData::class);
7572
});
7673

77-
7874
test('Testing list of assets, Params', function (): void {
7975
$responses = [
8076
\mockResponse("list-assets", 200, ["total"=>2, "per-page" => 25 ]),
@@ -97,7 +93,8 @@
9793
$storyblokResponse = $assetApi->page(
9894
params: new AssetsParams(
9995
inFolder: -1
100-
),page: new PaginationParams(5, 30)
96+
),
97+
page: new PaginationParams(5, 30)
10198
);
10299
$string = $storyblokResponse->getLastCalledUrl();
103100
expect($string)->toMatch('/.*in_folder=-1.*$/');
@@ -107,14 +104,14 @@
107104
params: new AssetsParams(
108105
search: "something",
109106
withTags: "aaa"
110-
),page: new PaginationParams(5, 30)
107+
),
108+
page: new PaginationParams(5, 30)
111109
);
112110
$string = $storyblokResponse->getLastCalledUrl();
113111
expect($string)->toMatch('/.*search=something.*$/');
114112
expect($string)->toMatch('/.*with_tags=aaa.*$/');
115113
expect($string)->toMatch('/.*page=5&per_page=30.*$/');
116114

117-
118115
});
119116

120117
test('testing asset payload', function (): void {
@@ -135,7 +132,6 @@
135132
expect($payload)->toHaveKey("filename");
136133
});
137134

138-
139135
test('delete one asset', function (): void {
140136
$responses = [
141137
\mockResponse("one-asset", 200, ["total"=>2, "per-page" => 25 ]),
@@ -162,10 +158,9 @@
162158
\mockResponse('one-asset', 200),
163159
];
164160

165-
166161
$httpClient = new MockHttpClient($responses);
167162
$httpAssetClient = new MockHttpClient($responsesAsset);
168-
$mapiClient = ManagementApiClient::initTest($httpClient, $httpAssetClient );
163+
$mapiClient = ManagementApiClient::initTest($httpClient, $httpAssetClient);
169164
$assetApi = new AssetApi($mapiClient, "222");
170165

171166
$response = $assetApi->upload("./tests/Feature/Data/image-test.png");
@@ -182,10 +177,9 @@
182177
\mockResponse('one-asset', 200),
183178
];
184179

185-
186180
$httpClient = new MockHttpClient($responses);
187181
$httpAssetClient = new MockHttpClient($responsesAsset);
188-
$mapiClient = ManagementApiClient::initTest($httpClient, $httpAssetClient );
182+
$mapiClient = ManagementApiClient::initTest($httpClient, $httpAssetClient);
189183
$assetApi = new AssetApi($mapiClient, "222");
190184

191185
$response = $assetApi->upload("./tests/Feature/Data/image-test.png");
@@ -202,10 +196,9 @@
202196
\mockResponse('one-asset', 400),
203197
];
204198

205-
206199
$httpClient = new MockHttpClient($responses);
207200
$httpAssetClient = new MockHttpClient($responsesAsset);
208-
$mapiClient = ManagementApiClient::initTest($httpClient, $httpAssetClient );
201+
$mapiClient = ManagementApiClient::initTest($httpClient, $httpAssetClient);
209202
$assetApi = new AssetApi($mapiClient, "222");
210203

211204
$response = $assetApi->upload("./tests/Feature/Data/image-test.png");

tests/Feature/ManagementApiTest.php

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
declare(strict_types=1);
44

55
use Storyblok\ManagementApi\ManagementApiClient;
6-
76
use Symfony\Component\HttpClient\MockHttpClient;
87

9-
108
test('Testing multiple resources, StoryblokData', function (): void {
119
$responses = [
12-
\mockResponse("list-tags", 200,
13-
["total"=>8, "per-page" => 25 ]),
10+
\mockResponse(
11+
"list-tags",
12+
200,
13+
["total"=>8, "per-page" => 25 ]
14+
),
1415
\mockResponse("empty-tags", 404),
1516
];
1617

@@ -40,21 +41,18 @@
4041
expect($tag->get("id"))->toBeNumeric()->toBeGreaterThan(1000);
4142
}
4243

43-
4444
$response = $managementApi->get(
4545
sprintf('spaces/%s/internal_tags', $spaceId),
4646
[
4747
"by_object_type" => "asset",
48-
"search" => "somethingnotexists"
48+
"search" => "somethingnotexists",
4949
]
5050
);
51-
expect( $response->getResponseStatusCode())->toBe(404) ;
52-
expect( $response->asJson())->toBe('["This record could not be found"]');
53-
51+
expect($response->getResponseStatusCode())->toBe(404) ;
52+
expect($response->asJson())->toBe('["This record could not be found"]');
5453

5554
});
5655

57-
5856
test('Testing create resource, StoryblokData', function (): void {
5957
$responses = [
6058
\mockResponse("one-tag", 200),
@@ -65,11 +63,10 @@
6563
$mapiClient = ManagementApiClient::initTest($client);
6664
$managementApi = $mapiClient->managementApi();
6765

68-
6966
// CREATE A TAG
7067
$tag = [
7168
"name" => "new tag",
72-
"object_type" => "asset"
69+
"object_type" => "asset",
7370
];
7471
$spaceId = "321388";
7572
$response = $managementApi->post(
@@ -94,14 +91,13 @@
9491
$mapiClient = ManagementApiClient::initTest($client);
9592
$managementApi = $mapiClient->managementApi();
9693

97-
9894
// CREATE A TAG
9995
$tag = [
10096
"name" => "new tag",
101-
"object_type" => "asset"
97+
"object_type" => "asset",
10298
];
10399
$spaceId = "321388";
104-
$tagId="56980";
100+
$tagId = "56980";
105101
$response = $managementApi->delete(
106102
sprintf('spaces/%s/internal_tags/%s', $spaceId, $tagId)
107103
);
@@ -123,14 +119,13 @@
123119
$mapiClient = ManagementApiClient::initTest($client);
124120
$managementApi = $mapiClient->managementApi();
125121

126-
127122
// CREATE A TAG
128123
$tag = [
129124
"name" => "some",
130-
"object_type" => "asset"
125+
"object_type" => "asset",
131126
];
132127
$spaceId = "321388";
133-
$tagId="56980";
128+
$tagId = "56980";
134129
$response = $managementApi->put(
135130
sprintf('spaces/%s/internal_tags/%s', $spaceId, $tagId)
136131
);
@@ -169,9 +164,3 @@
169164
expect($response->toArray())->toBeArray();
170165

171166
});
172-
173-
174-
175-
176-
177-

tests/Feature/SpaceTest.php

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Symfony\Component\HttpClient\Response\MockResponse;
1010
use Symfony\Component\HttpClient\MockHttpClient;
1111

12-
1312
test("Testing making space", function (): void {
1413
$spaceData = \Storyblok\ManagementApi\Data\SpaceData::make([]);
1514
expect($spaceData)->toBeInstanceOf(\Storyblok\ManagementApi\Data\SpaceData::class);
@@ -25,21 +24,19 @@
2524
$spaceApi = $mapiClient->spaceApi();
2625
expect($spaceApi)->toBeInstanceOf(SpaceApi::class);
2726

28-
2927
});
3028
test('Testing One space, SpaceData', function (): void {
3129
$responses = [
3230
\mockResponse("one-space", 200),
3331
\mockResponse("empty-space", 404),
3432
];
3533

36-
3734
$client = new MockHttpClient($responses);
3835
$mapiClient = ManagementApiClient::initTest($client);
3936
$spaceApi = new SpaceApi($mapiClient);
4037

4138
$storyblokResponse = $spaceApi->get("111");
42-
$storyblokData = $storyblokResponse->data();
39+
$storyblokData = $storyblokResponse->data();
4340
expect($storyblokData->get("name"))
4441
->toBe("Example Space")
4542
->and($storyblokData->name())->toBe("Example Space")
@@ -49,8 +46,8 @@
4946
->and($storyblokResponse->getResponseStatusCode())->toBe(200);
5047

5148
$storyblokResponse = $spaceApi->get("111notexists");
52-
expect( $storyblokResponse->getResponseStatusCode())->toBe(404) ;
53-
expect( $storyblokResponse->asJson())->toBe('["This record could not be found"]');
49+
expect($storyblokResponse->getResponseStatusCode())->toBe(404) ;
50+
expect($storyblokResponse->asJson())->toBe('["This record could not be found"]');
5451

5552
$storyblokData->setName("New Name");
5653
expect($storyblokData->get("name"))
@@ -71,17 +68,15 @@
7168
\mockResponse("empty-space", 404),
7269
];
7370

74-
7571
$client = new MockHttpClient($responses);
7672
$mapiClient = ManagementApiClient::initTest($client);
7773
$spaceApi = new SpaceApi($mapiClient);
7874

79-
$spaceData = new SpaceData();
75+
$spaceData = new SpaceData();
8076

8177
$spaceData->setName("New Name");
8278
$spaceData->setDomain("https://example.storyblok.com");
8379

84-
8580
expect($spaceData->get("name"))
8681
->toBe("New Name")
8782
->and($spaceData->createdAt())->toBe("")
@@ -90,7 +85,7 @@
9085
$storyblokResponse = $spaceApi->create(
9186
$spaceData
9287
);
93-
$storyblokData = $storyblokResponse->data();
88+
$storyblokData = $storyblokResponse->data();
9489
expect($storyblokData->get("name"))
9590
->toBe("Example Space")
9691
->and($storyblokData->name())->toBe("Example Space")
@@ -104,7 +99,6 @@
10499
\mockResponse("empty-space", 404),
105100
];
106101

107-
108102
$client = new MockHttpClient($responses);
109103
$mapiClient = ManagementApiClient::initTest($client);
110104
$spaceApi = new SpaceApi($mapiClient);
@@ -119,15 +113,14 @@
119113
\mockResponse("empty-space", 404),
120114
];
121115

122-
123116
$client = new MockHttpClient($responses);
124117
$mapiClient = ManagementApiClient::initTest($client);
125118
$spaceApi = new SpaceApi($mapiClient);
126119

127120
$storyblokResponse = $spaceApi->backup(
128121
"111"
129122
);
130-
$storyblokData = $storyblokResponse->data();
123+
$storyblokData = $storyblokResponse->data();
131124
expect($storyblokData->get("name"))
132125
->toBe("Example Space")
133126
->and($storyblokData->name())->toBe("Example Space")
@@ -143,15 +136,14 @@
143136
\mockResponse("empty-space", 404),
144137
];
145138

146-
147139
$client = new MockHttpClient($responses);
148140
$mapiClient = ManagementApiClient::initTest($client);
149141
$spaceApi = new SpaceApi($mapiClient);
150142

151143
$storyblokResponse = $spaceApi->delete(
152144
"111"
153145
);
154-
$storyblokData = $storyblokResponse->data();
146+
$storyblokData = $storyblokResponse->data();
155147
expect($storyblokData->get("name"))
156148
->toBe("Example Space")
157149
->and($storyblokData->name())->toBe("Example Space")
@@ -167,7 +159,6 @@
167159
\mockResponse("empty-space", 404),
168160
];
169161

170-
171162
$client = new MockHttpClient($responses);
172163
$mapiClient = ManagementApiClient::initTest($client);
173164
$spaceApi = new SpaceApi($mapiClient);
@@ -176,7 +167,7 @@
176167
"111",
177168
"New Space Name"
178169
);
179-
$storyblokData = $storyblokResponse->data();
170+
$storyblokData = $storyblokResponse->data();
180171
expect($storyblokData->get("name"))
181172
->toBe("Example Space")
182173
->and($storyblokData->name())->toBe("Example Space")
@@ -186,7 +177,6 @@
186177

187178
});
188179

189-
190180
test('Testing multiple spaces, SpaceData', function (): void {
191181
$responses = [
192182
\mockResponse("list-spaces", 200),

0 commit comments

Comments
 (0)