Skip to content

Commit 7062100

Browse files
authored
Merge pull request #1 from rest-control/0.4
0.4
2 parents b0be926 + 157be9b commit 7062100

9 files changed

+115
-32
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ NAME ?= rest-control
44
CONSOLE := docker-compose -p $(NAME) -f ./Docker/docker.yml
55

66
start:
7+
- docker network create rest-control
78
@-$(CONSOLE) up -d
89
stop:
910
@-$(CONSOLE) stop

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"require": {
13-
"rest-control/rest-control": "0.3.0-alpha",
13+
"rest-control/rest-control": "dev-master",
1414
"symfony/console": "^3.4"
1515
},
1616
"autoload": {

examples/ExpressionLanguageTest.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ class ExpressionLanguageTest extends AbstractTestCase
1515
*/
1616
public function exampleEndsWith()
1717
{
18-
return $this->send()
18+
return send()
1919
->get('sample.service/users/1')
2020
->expectedResponse()
2121
->json()
22-
->jsonPath('$.address.street', $this->endsWith('Light'))
23-
->jsonPath('$.email', $this->endsWith('[email protected]'))
24-
->jsonPath('$.phone', $this->endsWith('-770-736-8031 x56442'));
22+
->jsonPath('$.address.street', endsWith('Light'))
23+
->jsonPath('$.email', endsWith('[email protected]'))
24+
->jsonPath('$.phone', endsWith('-770-736-8031 x56442'));
2525
}
2626

2727
/**
@@ -33,13 +33,13 @@ public function exampleEndsWith()
3333
*/
3434
public function exampleContainsString()
3535
{
36-
return $this->send()
36+
return send()
3737
->get('sample.service/users/1')
3838
->expectedResponse()
3939
->json()
40-
->jsonPath('$.address.street', $this->containsString('ight'))
41-
->jsonPath('$.phone', $this->containsString('736-8031'))
42-
->jsonPath('$.company.bs', $this->containsString('harness'));
40+
->jsonPath('$.address.street', containsString('ight'))
41+
->jsonPath('$.phone', containsString('736-8031'))
42+
->jsonPath('$.company.bs', containsString('harness'));
4343
}
4444

4545
/**
@@ -51,13 +51,13 @@ public function exampleContainsString()
5151
*/
5252
public function exampleStartsWith()
5353
{
54-
return $this->send()
54+
return send()
5555
->get('sample.service/users/1')
5656
->expectedResponse()
5757
->json()
58-
->jsonPath('$.address.street', $this->startsWith('Kulas'))
59-
->jsonPath('$.phone', $this->startsWith('1-770-736'))
60-
->jsonPath('$.company.catchPhrase', $this->startsWith('Multi-layered client'));
58+
->jsonPath('$.address.street', startsWith('Kulas'))
59+
->jsonPath('$.phone', startsWith('1-770-736'))
60+
->jsonPath('$.company.catchPhrase', startsWith('Multi-layered client'));
6161
}
6262
/**
6363
* @test(
@@ -68,12 +68,12 @@ public function exampleStartsWith()
6868
*/
6969
public function exampleEqualsTo()
7070
{
71-
return $this->send()
71+
return send()
7272
->get('sample.service/users/1')
7373
->expectedResponse()
7474
->json()
75-
->jsonPath('$.id', $this->equalsTo(1))
76-
->jsonPath('$.phone', $this->equalsTo('1-770-736-8031 x56442'))
77-
->jsonPath('$.company.catchPhrase', $this->equalsTo('Multi-layered client-server neural-net'));
75+
->jsonPath('$.id', equalsTo(1))
76+
->jsonPath('$.phone', equalsTo('1-770-736-8031 x56442'))
77+
->jsonPath('$.company.catchPhrase', equalsTo('Multi-layered client-server neural-net'));
7878
}
7979
}

examples/HasItemTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ public function exampleFindUser()
1818
{
1919
$userItem = new UserObject();
2020

21-
return $this->send()
22-
->get('sample.service/users/1')
23-
->expectedResponse()
24-
->json()
25-
->hasItem($userItem);
21+
return send()
22+
->get('sample.service/users/1')
23+
->expectedResponse()
24+
->json()
25+
->hasItem($userItem);
2626
}
2727

2828
/**
@@ -46,7 +46,7 @@ public function exampleFindUser1WithRequiredValues()
4646
],
4747
]);
4848

49-
return $this->send()
49+
return send()
5050
->get('sample.service/users/1')
5151
->expectedResponse()
5252
->json()
@@ -67,7 +67,7 @@ public function exampleFindUser1WithOnlyGivenRequiredValuesFails()
6767
'name' => 'Leanne Graham',
6868
]);
6969

70-
return $this->send()
70+
return send()
7171
->get('sample.service/users/1')
7272
->expectedResponse()
7373
->json()

examples/HasItemsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function exampleGetUsers()
1919
{
2020
$userItemsCollection = new ResponseItemsCollection(UserObject::class);
2121

22-
return $this->send()
22+
return send()
2323
->get('sample.service/users')
2424
->expectedResponse()
2525
->json()
@@ -64,7 +64,7 @@ public function exampleGetUsersWithRequiredValues()
6464
])
6565
);
6666

67-
return $this->send()
67+
return send()
6868
->get('sample.service/users')
6969
->expectedResponse()
7070
->json()

examples/HttpBasicAuthTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Examples;
4+
5+
use RestControl\TestCase\AbstractTestCase;
6+
7+
class HttpBasicAuthTest extends AbstractTestCase
8+
{
9+
/**
10+
* @test(
11+
* title="Login via http basic auth",
12+
* description="Login via http basic auth (For this test you need RestControl training server, https://github.com/rest-control/training-server.)",
13+
* tags="auth httpBasicAuth"
14+
* )
15+
*/
16+
public function exampleHttpBasicAuthSuccess()
17+
{
18+
return send()
19+
->get( $this->getVar('training') . 'basic-auth')
20+
->httpBasicAuth('[email protected]', 'eId4ZuZBCiI7')
21+
->expectedResponse()
22+
->json()
23+
->httpCode(200)
24+
->jsonPath('$.status', equalsTo('ok'));
25+
}
26+
27+
/**
28+
* @test(
29+
* title="Login via http basic auth",
30+
* description="Login via http basic auth (For this test you need RestControl training server, https://github.com/rest-control/training-server.)",
31+
* tags="auth httpBasicAuthInvalidCredentials"
32+
* )
33+
*/
34+
public function exampleHttpBasicAuthInvalidCredentials ()
35+
{
36+
return send()
37+
->get( $this->getVar('training') . 'basic-auth')
38+
->httpBasicAuth('sampleInvalidUser', 'samplePassword')
39+
->expectedResponse()
40+
->httpCode(401);
41+
}
42+
}

examples/HttpStatusCodesTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Examples;
4+
5+
use RestControl\TestCase\AbstractTestCase;
6+
7+
class HttpStatusCodesTest extends AbstractTestCase
8+
{
9+
/**
10+
* @test(
11+
* title="Check given httpCode.",
12+
* description="Check httpCode with given value",
13+
* tags="httpStatusCodes givenHttpCode"
14+
* )
15+
*/
16+
public function exampleGivenHttpStatusCodes()
17+
{
18+
return send()
19+
->get('sample.service/users/1')
20+
->expectedResponse()
21+
->httpCode(200);
22+
}
23+
24+
/**
25+
* @test(
26+
* title="Check httpCode via helper.",
27+
* description="Check httpCode via helper",
28+
* tags="httpStatusCodes httpCodeOkHelper"
29+
* )
30+
*/
31+
public function exampleOkHelper()
32+
{
33+
return send()
34+
->get('sample.service/users/1')
35+
->expectedResponse()
36+
->httpStatusOk();
37+
}
38+
}

examples/JsonPathTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class JsonPathTest extends AbstractTestCase
1515
*/
1616
public function exampleSimpleValue()
1717
{
18-
return $this->send()
18+
return send()
1919
->get('sample.service/users/1')
2020
->expectedResponse()
2121
->json()
22-
->jsonPath('$.address.street', $this->endsWith('Light'));
22+
->jsonPath('$.address.street', endsWith('Light'));
2323
}
2424

2525
/**
@@ -31,11 +31,11 @@ public function exampleSimpleValue()
3131
*/
3232
public function exampleSimpleValueOnList()
3333
{
34-
return $this->send()
34+
return send()
3535
->get('sample.service/users')
3636
->expectedResponse()
3737
->json()
38-
->jsonPath('$..company.constValue', $this->endsWith('Value'));
38+
->jsonPath('$..company.constValue', endsWith('Value'));
3939
}
4040

4141
/**
@@ -47,7 +47,7 @@ public function exampleSimpleValueOnList()
4747
*/
4848
public function exampleSimpleValueWithCallback()
4949
{
50-
return $this->send()
50+
return send()
5151
->get('sample.service/users')
5252
->expectedResponse()
5353
->json()

rest-control.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ apiMockResponses:
1111
apiClient: \RestControl\ApiClient\MockApiClient
1212
#Custom response filters
1313
#responseFilters:
14-
# - \Sample\Filter\Response\Class
14+
# - \Sample\Filter\Response\Class
15+
variables:
16+
training: http://{{TRAINING_SERVER_CONTAINER_WEB_IP}}/

0 commit comments

Comments
 (0)