2gis/2fingers

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

2fingers

?????? ? ????

2fingers - ??? ??????? PHP-????????? ??? ????????? ????????????????? ?????????????? ?????? ??? ?????? JSON-based REST API.

?????????? ????????? ??????????? API ??????? ???????????? ??????? ????? ? ??????? ??? ????????????? ???????? ????????? ?????? ?? ???????? ??.

??? ??????? ?????? ???????????? PHPUnit, ??? ?????????? ???????? - HTTP-?????? Guzzle, ??? ?????????? ????????????? - composer.

????????????? ? ????????????? ??? ?? ????????? Linux.

???????? ????????, ? ??????????? ???? ??????? ?????? ? ???????, ????????? ????? ???????????? ??? ??????????? ?????? API ? ????????? ??!

?? ????? ???????? ?????????? 2fingers ?????? ?? leaxfm@gmail.com ??? p.asanov@flamp.ru.

?????????? ? ??????
????????? ??????????
????????? composer ? phpunit
???????? ?????? ?? ???????????
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.
????????? ??? PHPStorm

???? ?? ??????????? ????????????? ????? ?? 2fingers, ????????? PHPStorm, ????? ????? ? ?????? ?????? ???????? ????????? ?? ????? IDE:

??? ?????? ????? ? 2fingers
????????? ?????

??????? ???? ???? 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() {}

????? ????? test

????? testAddSomething ? ????????, ??????????, ???????????????? ??????, ??????????? ?? ?????????? ???????? ???????.

??? ?? ?????? ?????? ????? ????? ???????? - ?????????? ????????? ??????? ? API, ????????? ???? ?????? ? ????????? ?????!

????? ????, ?.?. ???? ?????????????????, ?? ???? ?? ?????? ????????? ?? ???? ?????????? ????????? (???????? ?????) ? ???? ?????? ??????????.

??????? ????? ?????????? - ??? ? ???? ????????? ???????, ?????? ???????? ?? ????????????. ?????? ???, ???????? ????? ????? ????????? ????, ??? ??????? ??????????? ??????, ????????? ??? ?????? ?, ????????, ?????-?? ?????????????? ??????? ?????.

?????? ???????, ??? ???????? ????? test:

????? dataProvider

? ?????? providerAddSomething ??????????? ???????? ??????. ????? ???????????? ????? ?????, ??? ? ??????????? ??????? ????? ????? ?????-?? ???????? ??????. ????????, ??? ????? ???? ??????, ? ???????? ?? ????????? ?????. ????? ???????, ???? ????????? ??????? ?? ???? ??????:

??????, ????? ???? ????? ?????? ? ????, ??????? ?? ??? ??????? ???????? ? ????????? ??? ??????, ????? ???????? ?????????????? ???????? ????????? JSON.

???????? ????????? ?????? ????? ????? ????????? ?????? ??? ?????????? ??????. ??????? ????? ????????? ????? ?????????, ??? ???? ??????? ???????? ??? ?????? (20x).

??? ???????? ????????? ?? ?????????? ?????????? ??????????? ??????????? ????? assert(). ???? ?????? ??????????? ??????: ?? ?????????? ??? ???????: ????????? (expected) ? ??????????? (actual), ? ? ?????? ?? ???????????? ??????? ? ??????? ?????????? ?????????? (?????? / ?????) ? ????????? ?????????? ????????.

$expected_code === 201) {

$actual = ...

$expected = ...

$this->assert($expected, $actual);

Actual

??????????? ????????? - ??? ??????, ?????????? ?? JSON-?????? API. ?????? ? ???????? actual ?? ????? ??? ????? ??????, ??????? ????????? ? ?????.

???????? JSON-????? ????? ? ??????? ?????? getResponseBody(), ???????? ?? ???? ?????? ?????? - ?????? ????? ????????? ? ????????? ????? ????????.

ual = $this->getResponseBody()->review;
Expected

????????? ????????? - ??? ?????????????? ? ????? ?????? ????-????????, ??????? ????????? 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().

JOIN

MiscDbHelper ???????????? ?????? ? JOIN'???. ??? ???? ???????????? ??????? ??????? (current) ? ??????? (main) ???????.

?????? ? ??????? ????? joinSomething(), ?????????????? ??????? table, ?? ?????? ?? ???????. ????????? ??????? ? ??????? ?????? ????? ????????????? ??? ?? table.

??? ???? ????????????? ?????? ???? joinSomething() ????? ? ??????? ??????? join() ? smartJoin(), ????????? ??. MiscDbHelper.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.