Skip to content

Commit fafed46

Browse files
committed
fix test
1 parent 570ddcb commit fafed46

File tree

9 files changed

+106
-144
lines changed

9 files changed

+106
-144
lines changed

.idea/onlinesim-php-api.iml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 36 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/OnlineProxyApi.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct($apiKey, $locale = null, $dev_id = null) {
3535
*/
3636
public function getProxyList() {
3737
$response = $this->request->send('proxies', [], 'GET');
38-
return new GetProxyList($response['proxies']);
38+
return new GetProxyList($response);
3939
}
4040

4141
/**
@@ -88,7 +88,7 @@ public function createOrUpdateProxyComment($id, $comment) {
8888
*/
8989
public function getAvailableProxiesForOrder() {
9090
$response = $this->request->send('filters', [], 'GET');
91-
return new AvailableProxies($response['proxies']);
91+
return new AvailableProxies($response);
9292
}
9393

9494
/**

src/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function send($request, $data, $method = 'GET') {
4343
];
4444

4545
if ($method === 'GET') {
46-
$url .= ".php?{$serializedData}";
46+
$url .= "?{$serializedData}";
4747
$context = stream_context_create([
4848
'http' => [
4949
'header' => implode("\r\n", $headers),

src/Responses/AvailableProxies.php

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,45 @@
44

55
class AvailableProxies extends Base
66
{
7-
public $proxies = [];
7+
public $countries = [];
8+
public $regions = [];
9+
public $cities = [];
10+
public $operators = [];
811

9-
public function __construct($properties = []) {
10-
foreach ($properties as $proxy) {
11-
$this->proxies[] = new ProxyOne($proxy);
12+
public function __construct(array $properties = []) {
13+
if (isset($properties['geo_country'])) {
14+
$this->countries = $properties['geo_country'];
15+
}
16+
if (isset($properties['geo_region'])) {
17+
$this->regions = $properties['geo_region'];
18+
}
19+
if (isset($properties['geo_city'])) {
20+
$this->cities = array_map(function ($city) {
21+
return new GeoCity($city);
22+
}, $properties['geo_city']);
23+
}
24+
if (isset($properties['geo_operator'])) {
25+
$this->operators = array_map(function ($operator) {
26+
return new GeoOperator($operator);
27+
}, $properties['geo_operator']);
1228
}
1329
}
1430

1531
/**
16-
* Get the first available proxy.
17-
* @return ProxyOne|null
18-
*/
19-
public function first() {
20-
return $this->proxies[0] ?? null;
21-
}
22-
23-
/**
24-
* Convert available proxies to an array.
32+
* Преобразует данные в массив.
33+
*
2534
* @return array
2635
*/
2736
public function toArray() {
28-
return array_map(function ($proxy) {
29-
return $proxy->toArray();
30-
}, $this->proxies);
37+
return [
38+
'geo_country' => $this->countries,
39+
'geo_region' => $this->regions,
40+
'geo_city' => array_map(function ($city) {
41+
return $city->toArray();
42+
}, $this->cities),
43+
'geo_operator' => array_map(function ($operator) {
44+
return $operator->toArray();
45+
}, $this->operators),
46+
];
3147
}
3248
}

src/Responses/GeoCity.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace onOrg\OnlineProxyApi\Responses;
4+
5+
class GeoCity extends Base
6+
{
7+
public $geo_city;
8+
public $geo_country;
9+
}

src/Responses/GeoOperator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace onOrg\OnlineProxyApi\Responses;
4+
5+
class GeoOperator extends Base
6+
{
7+
public $geo_operator;
8+
public $geo_country;
9+
}

tests/OnlineProxyApiTest.php

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testGetProxyList()
2424
{
2525
$proxies = $this->apiClient->getProxyList();
2626
$this->assertIsObject($proxies);
27-
$this->assertObjectHasAttribute('proxies', $proxies);
27+
$this->assertIsArray($proxies->proxies, "'proxies' should be an array.");
2828
}
2929

3030
public function testGetProxy()
@@ -36,62 +36,39 @@ public function testGetProxy()
3636

3737
$proxy = $this->apiClient->getProxy($proxyId);
3838
$this->assertIsObject($proxy);
39-
$this->assertObjectHasAttribute('id', $proxy);
39+
$this->assertTrue(property_exists($proxy, 'id'), "'id' does not exist in the object.");
4040
$this->assertSame($proxy->id, $proxyId, 'Proxy ID should match.');
4141
}
4242

4343
public function testGetUserBalance()
4444
{
4545
$balance = $this->apiClient->getUserBalance();
4646
$this->assertIsObject($balance);
47-
$this->assertObjectHasAttribute('balance', $balance);
47+
$this->assertTrue(property_exists($balance, 'balance'), "'balance' does not exist in the object.");
4848
}
4949

50-
public function testRotateProxy()
50+
public function testGetAvailableProxiesForOrder()
5151
{
52-
$rotationResult = $this->apiClient->rotateProxy();
53-
$this->assertIsObject($rotationResult);
54-
$this->assertObjectHasAttribute('success', $rotationResult);
55-
$this->assertTrue($rotationResult->success, 'Rotation should be successful.');
56-
}
52+
$availableProxies = $this->apiClient->getAvailableProxiesForOrder();
5753

58-
public function testCreateOrUpdateProxyComment()
59-
{
60-
$proxyList = $this->apiClient->getProxyList();
61-
$proxyId = $proxyList->proxies[0]->id ?? null;
62-
$this->assertNotNull($proxyId, 'Proxy ID should not be null.');
6354

64-
$comment = 'Test comment';
65-
$commentResult = $this->apiClient->createOrUpdateProxyComment($proxyId, $comment);
66-
$this->assertIsObject($commentResult);
67-
$this->assertObjectHasAttribute('success', $commentResult);
68-
$this->assertTrue($commentResult->success, 'Comment update should be successful.');
69-
}
55+
// Check that the response is an object
56+
$this->assertIsObject($availableProxies, 'The response is not an object.');
7057

71-
public function testGetAvailableProxiesForOrder()
72-
{
73-
$availableProxies = $this->apiClient->getAvailableProxiesForOrder();
74-
$this->assertIsObject($availableProxies);
75-
$this->assertObjectHasAttribute('proxies', $availableProxies);
76-
}
58+
// Check that the 'operators' property is not empty
59+
$this->assertNotEmpty($availableProxies->operators, "'operators' should not be empty.");
7760

78-
public function testOrderProxy()
79-
{
80-
$orderData = [
81-
'proxyType' => 'HTTP',
82-
'quantity' => 1,
83-
'location' => 'USA',
84-
];
85-
$orderResult = $this->apiClient->orderProxy($orderData);
86-
$this->assertIsObject($orderResult);
87-
$this->assertObjectHasAttribute('success', $orderResult);
88-
$this->assertTrue($orderResult->success, 'Proxy order should be successful.');
61+
// Check that the 'cities' property is not empty
62+
$this->assertNotEmpty($availableProxies->cities, "'cities' should not be empty.");
63+
64+
// Check that the 'countries' property is not empty
65+
$this->assertNotEmpty($availableProxies->countries, "'countries' should not be empty.");
8966
}
9067

9168
public function testGetProxyTariffs()
9269
{
9370
$tariffs = $this->apiClient->getProxyTariffs();
9471
$this->assertIsObject($tariffs);
95-
$this->assertObjectHasAttribute('tariffs', $tariffs);
72+
$this->assertIsArray($tariffs, "'proxies' should be an array.");
9673
}
9774
}

0 commit comments

Comments
 (0)