-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
213 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/* | ||
* Fusio is an open source API management platform which helps to create innovative API solutions. | ||
* For the current version and information visit <https://www.fusio-project.org/> | ||
* | ||
* Copyright 2015-2023 Christoph Kappestein <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Fusio\Impl\Backend\Action\Statistic; | ||
|
||
use Fusio\Engine\ActionInterface; | ||
use Fusio\Engine\ContextInterface; | ||
use Fusio\Engine\ParametersInterface; | ||
use Fusio\Engine\RequestInterface; | ||
use Fusio\Impl\Backend\View; | ||
|
||
/** | ||
* GetTestCoverage | ||
* | ||
* @author Christoph Kappestein <[email protected]> | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 | ||
* @link https://www.fusio-project.org | ||
*/ | ||
class GetTestCoverage implements ActionInterface | ||
{ | ||
private View\Statistic\TestCoverage $view; | ||
|
||
public function __construct(View\Statistic\TestCoverage $view) | ||
{ | ||
$this->view = $view; | ||
} | ||
|
||
public function handle(RequestInterface $request, ParametersInterface $configuration, ContextInterface $context): mixed | ||
{ | ||
return $this->view->getView( | ||
$context | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/* | ||
* Fusio is an open source API management platform which helps to create innovative API solutions. | ||
* For the current version and information visit <https://www.fusio-project.org/> | ||
* | ||
* Copyright 2015-2023 Christoph Kappestein <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Fusio\Impl\Backend\View\Statistic; | ||
|
||
use Fusio\Engine\ContextInterface; | ||
use Fusio\Impl\Table; | ||
use PSX\Sql\ViewAbstract; | ||
|
||
/** | ||
* TestCoverage | ||
* | ||
* @author Christoph Kappestein <[email protected]> | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 | ||
* @link https://www.fusio-project.org | ||
*/ | ||
class TestCoverage extends ViewAbstract | ||
{ | ||
public function getView(ContextInterface $context) | ||
{ | ||
$status = [ | ||
Table\Test::STATUS_PENDING => 'Pending', | ||
Table\Test::STATUS_SUCCESS => 'Success', | ||
Table\Test::STATUS_WARNING => 'Warning', | ||
Table\Test::STATUS_ERROR => 'Error', | ||
]; | ||
|
||
$data = []; | ||
$labels = []; | ||
|
||
foreach ($status as $key => $label) { | ||
$count = (int) $this->connection->fetchOne('SELECT COUNT(*) AS cnt FROM fusio_test WHERE tenant_id = :tenant AND category_id = :category AND status = :status', [ | ||
'tenant' => $context->getTenantId(), | ||
'category' => $context->getUser()->getCategoryId(), | ||
'status' => $key, | ||
]); | ||
|
||
$data[] = $count; | ||
$labels[] = $label; | ||
} | ||
|
||
return [ | ||
'labels' => $labels, | ||
'data' => [$data], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/* | ||
* Fusio is an open source API management platform which helps to create innovative API solutions. | ||
* For the current version and information visit <https://www.fusio-project.org/> | ||
* | ||
* Copyright 2015-2023 Christoph Kappestein <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Fusio\Impl\Tests\Backend\Api\Statistic; | ||
|
||
use Fusio\Impl\Tests\Fixture; | ||
use PSX\Framework\Test\ControllerDbTestCase; | ||
|
||
/** | ||
* TestCoverageTest | ||
* | ||
* @author Christoph Kappestein <[email protected]> | ||
* @license http://www.apache.org/licenses/LICENSE-2.0 | ||
* @link https://www.fusio-project.org | ||
*/ | ||
class TestCoverageTest extends ControllerDbTestCase | ||
{ | ||
public function getDataSet(): array | ||
{ | ||
return Fixture::getDataSet(); | ||
} | ||
|
||
public function testGet() | ||
{ | ||
$response = $this->sendRequest('/backend/statistic/test_coverage?from=2015-06-01T00:00:00&to=2015-06-30T23:59:59', 'GET', array( | ||
'User-Agent' => 'Fusio TestCase', | ||
'Authorization' => 'Bearer da250526d583edabca8ac2f99e37ee39aa02a3c076c0edc6929095e20ca18dcf' | ||
)); | ||
|
||
$body = (string) $response->getBody(); | ||
|
||
$expect = <<<JSON | ||
{ | ||
"labels": [ | ||
"Pending", | ||
"Success", | ||
"Warning", | ||
"Error" | ||
], | ||
"data": [ | ||
[ | ||
0, | ||
0, | ||
0, | ||
0 | ||
] | ||
] | ||
} | ||
JSON; | ||
|
||
$this->assertEquals(200, $response->getStatusCode(), $body); | ||
$this->assertJsonStringEqualsJsonString($expect, $body, $body); | ||
} | ||
} |