Commit 0e426b30 authored by Виктор Волков's avatar Виктор Волков
Browse files

Merge branch 'develop' into 'master'

Develop

See merge request !1
parents bfaa11c4 a5c73aaa
......@@ -38,9 +38,17 @@ class ApiQL extends AbstractLanguage
*/
private function executeFields()
{
$isProjection = false;
if (array_key_exists('fields', $this->expression)) {
$fields = !is_array($this->expression['fields']) ? explode(',', $this->expression['fields']) :
$this->expression['fields'];
$isProjection = true;
$fieldsName = 'fields';
} elseif (array_key_exists('select', $this->expression)) {
$isProjection = true;
$fieldsName = 'select';
}
if ($isProjection) {
$fields = !is_array($this->expression[$fieldsName]) ? explode(',', $this->expression[$fieldsName]) :
$this->expression[$fieldsName];
if (!empty($fields)) {
foreach ($fields as $field) {
self::$builder->addSelect($field);
......@@ -48,7 +56,7 @@ class ApiQL extends AbstractLanguage
} else {
self::$builder->addSelect('*');
}
unset($this->expression['fields']);
unset($this->expression[$fieldsName]);
} else {
self::$builder->addSelect('*');
}
......
......@@ -779,21 +779,37 @@ final class ApiTest extends TestCase
public function testDynamicFields()
{
//arrange
$payload = ["spec" => "not_in", "b" => [2, 5, 7], "fields" => ["a", "c"]];
$repo = new ApiRepository(self::$cnx);
//act
$data = $repo->get($payload);
//assert
$this->assertArrayHasKey(
"a",
$data[0]
);
//assert
$this->assertArrayHasKey(
"c",
$data[0]
);
//arrange
$payload = ["spec" => "not_in", "b" => [2, 5, 7], "fields" => ["a", "c"]];
$repo = new ApiRepository(self::$cnx);
//act
$data = $repo->get($payload);
//assert
$this->assertArrayHasKey(
"a",
$data[0]
);
//assert
$this->assertArrayHasKey(
"c",
$data[0]
);
//arrange
$payload = ["spec" => "not_in", "b" => [2, 5, 7], "select" => ["a", "c"]];
$repo = new ApiRepository(self::$cnx);
//act
$data = $repo->get($payload);
//assert
$this->assertArrayHasKey(
"a",
$data[0]
);
//assert
$this->assertArrayHasKey(
"c",
$data[0]
);
//arrange
$payload = ["spec" => "not_in", "b" => "2,5,7", "fields" => ["a", "c"]];
......@@ -1333,6 +1349,7 @@ final class ApiTest extends TestCase
$repo = new ApiRepository(self::$cnx);
//act
$data = $repo->get($payload);
//assert
$this->assertCount(
3,
$data
......@@ -1343,6 +1360,7 @@ final class ApiTest extends TestCase
$repo = new ApiRepository(self::$cnx);
//act
$data = $repo->get($payload);
//assert
$this->assertCount(
3,
$data
......@@ -1354,6 +1372,7 @@ final class ApiTest extends TestCase
$repo = new ApiRepository(self::$cnx);
//act
$data = $repo->get($payload);
//assert
$this->assertCount(
2,
$data
......@@ -1364,6 +1383,7 @@ final class ApiTest extends TestCase
$repo = new ApiRepository(self::$cnx);
//act
$data = $repo->get($payload);
//assert
$this->assertCount(
2,
$data
......@@ -1374,6 +1394,7 @@ final class ApiTest extends TestCase
$repo = new ApiRepository(self::$cnx);
//act
$data = $repo->get($payload);
//assert
$this->assertCount(
2,
$data
......@@ -1394,6 +1415,7 @@ final class ApiTest extends TestCase
$repo = new ApiRepository(self::$cnx);
//act
$data = $repo->get($payload);
//assert
$this->assertCount(
2,
$data
......@@ -1404,6 +1426,7 @@ final class ApiTest extends TestCase
$repo = new ApiRepository(self::$cnx);
//act
$data = $repo->get($payload);
//assert
$this->assertCount(
2,
$data
......@@ -1414,6 +1437,7 @@ final class ApiTest extends TestCase
$repo = new ApiRepository(self::$cnx);
//act
$data = $repo->get($payload);
//assert
$this->assertCount(
2,
$data
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment