Name: 2fingers
Owner: 2GIS
Description: simple PHP framework for REST API black-box functional testing
Created: 2015-06-09 11:30:18.0
Updated: 2017-08-17 16:05:23.0
Pushed: 2015-09-07 08:30:45.0
Homepage: null
Size: 332
Language: PHP
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
2fingers - ??? ??????? PHP-????????? ??? ????????? ????????????????? ?????????????? ?????? ??? ?????? JSON-based REST API.
?????????? ????????? ??????????? API ??????? ???????????? ??????? ????? ? ??????? ??? ????????????? ???????? ????????? ?????? ?? ???????? ??.
??? ??????? ?????? ???????????? PHPUnit, ??? ?????????? ???????? - HTTP-?????? Guzzle, ??? ?????????? ????????????? - composer.
????????????? ? ????????????? ??? ?? ????????? Linux.
???????? ????????, ? ??????????? ???? ??????? ?????? ? ???????, ????????? ????? ???????????? ??? ??????????? ?????? API ? ????????? ??!
?? ????? ???????? ?????????? 2fingers ?????? ?? leaxfm@gmail.com ??? p.asanov@flamp.ru.
sudo mv phpunit.phar /usr/local/bin/phpunit
sudo chmod u+x phpunit
phpunit <something>
clone git@github.com:2gis/2fingers.git
oser install
??????????????? ?????? ??????? server.php.dist ? server.php, ????? ??????????? ? ???????????? ?????? ???? ? ???? ??????.
onfig/
erver.php.dist server.php
server.php
????? ?? API ????? ? ????? tests. ????????? ?? ? ??????? phpunit.
nit tests/
?????? ????? ?????? ????????? ?? ??????????? ? ????????????, ????????, ? ????????? ???????????? (Auth, Users ? ?.?.). ??????????????, ????? ????????? ????? ?? ??????????? ???????:
nit tests/Users/
?????????? ???? ????? ?????????, ?????? ?????? ???? ?? ????:
nit tests/AddSomethingTest.php
??? ??????? ????? ??????????? ??????????? ??????? ????, ?? ? ???????? verbose, ???? ?? ??????? ?????? ?? ???????? ? ??????? server:
nit tests/AddSomethingTest.php --host=test.test --dbhost=test.test --dbname=test
nit tests/AddSomethingTest.php --verbose=false
???????? verbose ??????????, ????? ?? ?????????? ??????????? ?????????? ?????????? (????????? ???????, JSON-?????) ??? ??????? ?????? ? ???????. ?? ????????? ?? ?????? true.
????? ???? ??????????? ????????? ?????? ?????? (test suites):
nit --testsuite regression
??????????? ????? ?????? ????? ? ??????? phpunit.xml.
??? ???????? ??????? ????????? ??????:
anov@uk-rnd-266:~/2fingers$ phpunit tests/2.0/Comments/
?? ?°) starting 2fingers...
nit 4.3.5 by Sebastian Bergmann.
iguration read from /home/p.asanov/2fingers/phpunit.xml
........................................................... 63 / 146 ( 43%)
........................................................... 126 / 146 ( 86%)
................
: 43.17 seconds, Memory: 16.50Mb
146 tests, 1135 assertions)
?????? ????? - ??? ??????? ????????? ????-????. ????? ? ????? Comments 12 ??????? ? ???????, ?? ?????? ???? ??? ???????? 146 ????-??????, ??????? ???????? ???? ??? 1135 ???????? ????????? ? JSON. ???? ???? ????, ?????? ????? ????? ??????? ????? F (???????? ?? ??????) ??? E ( ? ????? ????????? ??????). ????? ????, ? ??????? ?? ????????? ????????? ?????????? ??????????:
................F...
: 6.48 seconds, Memory: 8.00Mb
e was 1 failure:
ddReviewTest::testAddReview with data set #20 ('141265770608749', 'rDlJ4zSUks', 5, true, NULL, 0, 403)
===========================================================
https://jazz.precise.flamp.test/api/2.0/reviews
al_id = 141265770608749
= rDlJ4zSUks
ng = 5
ecommended = true
os =
ERS:
pt: application/json;q=1;depth=1;scopes={"review":{}}
orization: Bearer 271b3df12efbbace6ff88ea98f964aa52da32a4
-----------------------------------------------------------
"code": 401,
"status": "error",
"error_code": 0,
"message": "? ??? ??? ???? ??????? ??? ?????????? ???????"
-----------------------------------------------------------
ed asserting that 401 matches expected 403.
e/p.asanov/2fingers/tests/2.0/BaseFlampApiTest.php:79
e/p.asanov/2fingers/tests/BaseTest.php:62
e/p.asanov/2fingers/tests/2.0/Reviews/AddReviewTest.php:89
URES!
s: 24, Assertions: 122, Failures: 1.
???? ?? ??????????? ????????????? ????? ?? 2fingers, ????????? PHPStorm, ????? ????? ? ?????? ?????? ???????? ????????? ?? ????? IDE:
??????? ???? ???? AddSomethingTest.php, ?????????? ? ???? PHP-????? AddSomethingTest. ???????? ????? ? ?????? ?????? ????????? ? ???????????? ?? Test.
????? ?????, ????? ?????? ??????????? ????????? ??????? ????? BaseTest:
s AddSomethingTest extends BaseTest
????????????????? ????- ??? ????-??????, ??????? ????????? ?? ???? N ??????? ??????, ? ?? ?????? ?????? N ???????? ??????.
??????? ?????? ?????? AddSomethingTest ?????? ???? 2 ???????????? ??????:
??? ????? ?????? ??????????? ?????????? ?? ????? test, ??? ???? ?????????? - ?? ????? provider. ? ????????? ??????????, ????? ???????? ??????????????? ????? ??????, ??? ??????????.
????? testAddSomething ????, ?????? ????? ???????? ??????, ????? ??????? ??? ???? ???? ????????? ? ??????? ????????? @dataProvider:
s AddSomethingTest extends BaseTest
public function providerAddSomething() {}
/**
* @dataProvider providerAddSomething
*/
public function testAddSomething() {}
????? testAddSomething ? ????????, ??????????, ???????????????? ??????, ??????????? ?? ?????????? ???????? ???????.
??? ?? ?????? ?????? ????? ????? ???????? - ?????????? ????????? ??????? ? API, ????????? ???? ?????? ? ????????? ?????!
????? ????, ?.?. ???? ?????????????????, ?? ???? ?? ?????? ????????? ?? ???? ?????????? ????????? (???????? ?????) ? ???? ?????? ??????????.
??????? ????? ?????????? - ??? ? ???? ????????? ???????, ?????? ???????? ?? ????????????. ?????? ???, ???????? ????? ????? ????????? ????, ??? ??????? ??????????? ??????, ????????? ??? ?????? ?, ????????, ?????-?? ?????????????? ??????? ?????.
?????? ???????, ??? ???????? ????? test:
ic function testAddReview($filial_id, $text, $rating, $is_recommended,
$photos, $user_id, $expected_code)
????? http-?????, ????? API, ????????? ??????? ? scopes
s->http_method = 'POST';
s->method = "reviews";
s->params = [
'filial_id' => $filial_id,
'text' => $text,
'rating' => $rating,
'is_recommended' => $is_recommended,
'photos' => $photos,
s->scopes = 'review';
???????? ?????? ? ????????? ???? ??????
s->asUser($user_id)->send();
s->waitFor($expected_code);
? ?????? providerAddSomething ??????????? ???????? ??????. ????? ???????????? ????? ?????, ??? ? ??????????? ??????? ????? ????? ?????-?? ???????? ??????. ????????, ??? ????? ???? ??????, ? ???????? ?? ????????? ?????. ????? ???????, ???? ????????? ??????? ?? ???? ??????:
????????? ?????? ?? ??????????? ????????? ??? ???????????? ???????
??????????????? ???????????? ?????? ???????? ???????. ?? ???? ??? ?????? return ??????? ????????.
ic function providerAddReview()
ial_id = Config()->filials->pac;
r_id = Db()->user()->getRandomUser()->id;
rn [
[$filial_id, Generate()->text(150), 5, true, null, $user_id, 201],
?????? ??? ???????? ?????????, ????????????? ?????? (????????). ? ??????? ?????? ???????? ? ???? ?????? (?????? ????????). ?????? ????????? ????? ????????? ???? ?? ??????? ???? ??????. ???? ????? ???????? ?????????? ?????? ???????, ????? ??????????????? ??????? asArray().
r_id = Config()->roles->guest;
?? ??? ???????? ???????? ????????? ??????. ??????? ?? ?? ???????? ???????? ???????? ? ??????? ???????????? ????. ?????? ??????? ????????? ???????/????????, ????? ??????? ??????? ? ? ????? ????? ??????? ????? ?????????.
ity = Db()->entity('review')->forFilial($filial_id)
Hidden(false)->getRandomEntity();
??????????? API. ?????????? ??? ?????? ??? ????????? ??????, ???? ?????? ? ?? ????????????, ??? ???? ?? ?? ????? ?? ???????? ??????? ?????? ?????.
)->addUserToken();
????????? ????????? ??????.
rate()->text(150)
??????, ????? ???? ????? ?????? ? ????, ??????? ?? ??? ??????? ???????? ? ????????? ??? ??????, ????? ???????? ?????????????? ???????? ????????? JSON.
???????? ????????? ?????? ????? ????? ????????? ?????? ??? ?????????? ??????. ??????? ????? ????????? ????? ?????????, ??? ???? ??????? ???????? ??? ?????? (20x).
??? ???????? ????????? ?? ?????????? ?????????? ??????????? ??????????? ????? assert(). ???? ?????? ??????????? ??????: ?? ?????????? ??? ???????: ????????? (expected) ? ??????????? (actual), ? ? ?????? ?? ???????????? ??????? ? ??????? ?????????? ?????????? (?????? / ?????) ? ????????? ?????????? ????????.
$expected_code === 201) {
$actual = ...
$expected = ...
$this->assert($expected, $actual);
??????????? ????????? - ??? ??????, ?????????? ?? JSON-?????? API. ?????? ? ???????? actual ?? ????? ??? ????? ??????, ??????? ????????? ? ?????.
???????? JSON-????? ????? ? ??????? ?????? getResponseBody(), ???????? ?? ???? ?????? ?????? - ?????? ????? ????????? ? ????????? ????? ????????.
ual = $this->getResponseBody()->review;
????????? ????????? - ??? ?????????????? ? ????? ?????? ????-????????, ??????? ????????? actual-??????. ???????????? ????? ?????? ???????????. ???????? expected ????? ??????? ? JSON-??????, ? JSON-?????? ????????.
?????? ???? ??????? ??????, ??????????, ????? ??????????????? ???????? ???????????? ???????? ? actual-???????.
?????? ?????????? ??????????:
ected = [
'filial_id' => $filial_id,
'user_id' => $user_id,
'text' => $text,
'rating' => $rating,
'is_recommended' => $is_recommended,
'date_created' => CHECK_DATETIME_FORMAT,
'date_edited' => null,
'comments_count' => 0,
'source' => CHECK_SOURCE,
'project' => CHECK_NOT_NULL,
'additional_data' => [
'is_my' => true,
'is_liked' => false,
],
'url' => CHECK_STRING_NOT_EMPTY,
'count_by_author_about_filial' => CHECK_NOT_NEGATIVE,
'id' => CHECK_POSITIVE
???????? ????? ????? ???? ?????????? ????????? ????? (????????, ?????????? ?? ?????? ??????, ???? 0, null ? ?.?.).
???? ?? ?? ?? ????? ??????? ?????????? ????????, ?? ????? ??????? ??? ? ???? ??????? (????????????? ?????, ?? NULL, ???????? ?????? ? ?.?.). ???????? ??? ? ??????? ????????? ???????? CHECK_.
| ????????? | ???????? | | ———— |—————| | CHECK_EXIST | ?????????, ??? ??????? ? ????? ?????? ? ???????? ?????????? ? ?????? | | CHECK_NOT_NULL | ?????????, ??? ???????? ???????? ??????? ?? NULL | | CHECK_POSITIVE | ?????????, ??? ???????? ???????? - ????????????? ????? | | CHECK_NOT_NEGATIVE | ?????????, ??? ???????? ???????? - ??????????????? ????? | | CHECK_STRING_NOT_EMPTY | ?????????, ??? ???????? ???????? - ???????? ??????. | | CHECK_DATETIME_FORMAT | ?????????, ??? datetime ??????? ????? ?????????? ?????? | | CHECK_SOURCE ? ?.?. | ?? ????, ???????? ?? enum. ? ?????? ?????? ??????????, ??? ???????? source ????? ?????????? ????????? ???????? |
??? ?????????? ????? ???????? ????? ???????? ????????? ? bootstrap.php ? ????? assert() ?????? BaseTest.php
??? ????????, ??????? ?? ??????? ??????????? ? ??????? ?????? assert(), ????? ?????? ? ??????? ??????????? ??????? PHPUnit assertEquals(), assertNotNull(), assertContains() ? ?.?. ?????? ?????? ?????? ?????.
???? ?????? ? ??????? MiscDbHelper ?????????:
????? ?????????? ?? SQL-??????, ?????? ??????????? ???????? ? ??????? Db(), ? ??????? ?????? ? ?? ????????? ? ???????:
ity = Db(1)->entity('review')->forFilial($filial_id)
->isHidden(false)->getRandomEntity();
????????? ?????? ??? ??? ????????, ??????? ?? ????? ??????? ? ??, ?.?. ??? ???????????? ??????????? ????? ?????? ???????? ?? ?????.
?????????? ??? ???? ???? ????? getRandomEntity(). ????? ????????? ????????? ???????? ?? ????????? ??????? ? ????????? ?? ? ?????? “??????????????” ? ??????? ??????? ????????? - ??? ?????????? ??? ???????? ??????, ????? ?? ???? ?????????? ? ??????.
??? ????? ??????? ????????????? ????? ??????? ???? ??????????? ??????.
???? ????? ???????? ? ???????? ????? ???? ??????? ???????, ??????? ????? public ????? ? MiscDBHelper ? ????????? ??? ??????? ??? ????? WHERE:
ic function forProject($project_id)
$this->where .= " AND {$this->current_table}.project_id = {$project_id}";
return $this;
?????????? ?????? ? ??????? ?????? getSubquery(). ?? ?????? ???? ? ????? ??????? ??????, ??????, ????????, getRandomEnity(). ???? ? ???, ??? ?? ?????? ?? ???? ???????? ?? ????, ? SQL-????????? ??? ?? ?????????. ????? ????? ???? ????????? ? ????????? ? ??????? idIn() ??? idNotIn() ? ???????? ???????? ??????.
query = Db()->fields('object_id')->table('comments')->getSubquery();
iew = Db()->entity('review')->idNotIn($subquery)->getRandomEntity();
? ???? ??????? ?? ??????? ??????? ?????????: ???????? ?? ??????? comments ???? object_id ??? ???? ???????.
????? ???????? ????? ????????? ?????, id ???????? ?? ?????? ? ????????? ???? ?????????.
? ?????? idIn(), idNotIn() ????? ?????????? ??? ?????????, ??? ? ?????? id (?????) ??? ???? ?????? id-??????. ? ????????? ??????? ?????? IN ??????? ???????????? ??????????? EXIST, ??? ??? ?? ??????????? ????? ?????? exist() ? notExist().
MiscDbHelper ???????????? ?????? ? JOIN'???. ??? ???? ???????????? ??????? ??????? (current) ? ??????? (main) ???????.
?????? ? ??????? ????? joinSomething(), ?????????????? ??????? table, ?? ?????? ?? ???????. ????????? ??????? ? ??????? ?????? ????? ????????????? ??? ?? table.
??? ???? ????????????? ?????? ???? joinSomething() ????? ? ??????? ??????? join() ? smartJoin(), ????????? ??. MiscDbHelper.