Added the stats type test cases.
parent
deeb0863d9
commit
125d7c1151
|
@ -43,6 +43,7 @@
|
|||
"php": "^7.1",
|
||||
"ext-json": "*",
|
||||
"ext-pdo": "*",
|
||||
"ext-bcmath": "*",
|
||||
"monarc/frontoffice": "dev-feature/stats",
|
||||
"monarc/core": "dev-feature/stats as 2.9.18",
|
||||
"laminas/laminas-mvc": "^3.1",
|
||||
|
@ -51,7 +52,9 @@
|
|||
"laminas/laminas-log": "^2.11",
|
||||
"laminas/laminas-i18n": "^2.9",
|
||||
"symfony/console": "^5.0",
|
||||
"laminas/laminas-dependency-plugin": "^1.0"
|
||||
"laminas/laminas-dependency-plugin": "^1.0",
|
||||
"ocramius/proxy-manager": "<2.3",
|
||||
"ocramius/package-versions": "<1.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"roave/security-advisories": "dev-master",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "eb1f56ed4a5268340b0a0b42c260c7c5",
|
||||
"content-hash": "c663d6a8230fb19d7a5e3b7195f97d16",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brick/math",
|
||||
|
@ -394,6 +394,71 @@
|
|||
],
|
||||
"time": "2020-06-14T02:01:05+00:00"
|
||||
},
|
||||
{
|
||||
"name": "composer/package-versions-deprecated",
|
||||
"version": "1.8.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/composer/package-versions-deprecated.git",
|
||||
"reference": "98df7f1b293c0550bd5b1ce6b60b59bdda23aa47"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/98df7f1b293c0550bd5b1ce6b60b59bdda23aa47",
|
||||
"reference": "98df7f1b293c0550bd5b1ce6b60b59bdda23aa47",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"composer-plugin-api": "^1.1.0 || ^2.0",
|
||||
"php": "^7"
|
||||
},
|
||||
"replace": {
|
||||
"ocramius/package-versions": "1.2 - 1.8.99"
|
||||
},
|
||||
"require-dev": {
|
||||
"composer/composer": "^1.9.3 || ^2.0@dev",
|
||||
"ext-zip": "^1.13",
|
||||
"phpunit/phpunit": "^6.5 || ^7"
|
||||
},
|
||||
"type": "composer-plugin",
|
||||
"extra": {
|
||||
"class": "PackageVersions\\Installer",
|
||||
"branch-alias": {
|
||||
"dev-master": "1.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PackageVersions\\": "src/PackageVersions"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Marco Pivetta",
|
||||
"email": "ocramius@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Jordi Boggiano",
|
||||
"email": "j.boggiano@seld.be"
|
||||
}
|
||||
],
|
||||
"description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://packagist.com",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2020-04-23T11:49:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "container-interop/container-interop",
|
||||
"version": "1.2.0",
|
||||
|
@ -3004,16 +3069,16 @@
|
|||
},
|
||||
{
|
||||
"name": "laminas/laminas-mail",
|
||||
"version": "2.10.1",
|
||||
"version": "2.11.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laminas/laminas-mail.git",
|
||||
"reference": "cfe0711446c8d9c392e9fc664c9ccc180fa89005"
|
||||
"reference": "4c5545637eea3dc745668ddff1028692ed004c4b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laminas/laminas-mail/zipball/cfe0711446c8d9c392e9fc664c9ccc180fa89005",
|
||||
"reference": "cfe0711446c8d9c392e9fc664c9ccc180fa89005",
|
||||
"url": "https://api.github.com/repos/laminas/laminas-mail/zipball/4c5545637eea3dc745668ddff1028692ed004c4b",
|
||||
"reference": "4c5545637eea3dc745668ddff1028692ed004c4b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -3043,8 +3108,8 @@
|
|||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.10.x-dev",
|
||||
"dev-develop": "2.11.x-dev"
|
||||
"dev-master": "2.11.x-dev",
|
||||
"dev-develop": "2.12.x-dev"
|
||||
},
|
||||
"laminas": {
|
||||
"component": "Laminas\\Mail",
|
||||
|
@ -3072,7 +3137,7 @@
|
|||
"type": "community_bridge"
|
||||
}
|
||||
],
|
||||
"time": "2020-04-21T16:42:19+00:00"
|
||||
"time": "2020-06-30T20:17:23+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laminas/laminas-mime",
|
||||
|
@ -3987,12 +4052,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/monarc-project/zm-core.git",
|
||||
"reference": "25e3dd77b7ae4d85ee0393e450c17a2398e2365f"
|
||||
"reference": "5338a9caaab59a8be2e8a70e5c33ae7beb6514af"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/monarc-project/zm-core/zipball/25e3dd77b7ae4d85ee0393e450c17a2398e2365f",
|
||||
"reference": "25e3dd77b7ae4d85ee0393e450c17a2398e2365f",
|
||||
"url": "https://api.github.com/repos/monarc-project/zm-core/zipball/5338a9caaab59a8be2e8a70e5c33ae7beb6514af",
|
||||
"reference": "5338a9caaab59a8be2e8a70e5c33ae7beb6514af",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -4009,8 +4074,7 @@
|
|||
"laminas/laminas-log": "^2.11",
|
||||
"laminas/laminas-mail": "^2.10",
|
||||
"laminas/laminas-mvc": "^3.1",
|
||||
"ocramius/package-versions": "<1.5",
|
||||
"ocramius/proxy-manager": "<2.3",
|
||||
"ocramius/proxy-manager": "^2.2",
|
||||
"php": "^7.1",
|
||||
"ramsey/uuid-doctrine": "^1.5",
|
||||
"robmorgan/phinx": "^0.11.1"
|
||||
|
@ -4067,7 +4131,7 @@
|
|||
}
|
||||
],
|
||||
"description": "Core for monarc/monarc application",
|
||||
"time": "2020-06-18T15:18:49+00:00"
|
||||
"time": "2020-07-02T10:36:58+00:00"
|
||||
},
|
||||
{
|
||||
"name": "monarc/frontoffice",
|
||||
|
@ -4075,12 +4139,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/monarc-project/zm-client.git",
|
||||
"reference": "ee8f911281b042784173b86fff59c1cb86bb9ad9"
|
||||
"reference": "11b1912a489964534f20ff6e1169124037026623"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/monarc-project/zm-client/zipball/ee8f911281b042784173b86fff59c1cb86bb9ad9",
|
||||
"reference": "ee8f911281b042784173b86fff59c1cb86bb9ad9",
|
||||
"url": "https://api.github.com/repos/monarc-project/zm-client/zipball/11b1912a489964534f20ff6e1169124037026623",
|
||||
"reference": "11b1912a489964534f20ff6e1169124037026623",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -4155,7 +4219,7 @@
|
|||
}
|
||||
],
|
||||
"description": "Frontoffice for monarc/monarc application",
|
||||
"time": "2020-06-25T14:28:32+00:00"
|
||||
"time": "2020-06-30T19:17:13+00:00"
|
||||
},
|
||||
{
|
||||
"name": "monarc/phpword",
|
||||
|
@ -4260,56 +4324,6 @@
|
|||
],
|
||||
"time": "2019-09-12T12:23:28+00:00"
|
||||
},
|
||||
{
|
||||
"name": "ocramius/package-versions",
|
||||
"version": "1.4.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Ocramius/PackageVersions.git",
|
||||
"reference": "44af6f3a2e2e04f2af46bcb302ad9600cba41c7d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Ocramius/PackageVersions/zipball/44af6f3a2e2e04f2af46bcb302ad9600cba41c7d",
|
||||
"reference": "44af6f3a2e2e04f2af46bcb302ad9600cba41c7d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"composer-plugin-api": "^1.0.0",
|
||||
"php": "^7.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"composer/composer": "^1.6.3",
|
||||
"doctrine/coding-standard": "^5.0.1",
|
||||
"ext-zip": "*",
|
||||
"infection/infection": "^0.7.1",
|
||||
"phpunit/phpunit": "^7.5.17"
|
||||
},
|
||||
"type": "composer-plugin",
|
||||
"extra": {
|
||||
"class": "PackageVersions\\Installer",
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"PackageVersions\\": "src/PackageVersions"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Marco Pivetta",
|
||||
"email": "ocramius@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
|
||||
"time": "2019-11-15T16:17:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "ocramius/proxy-manager",
|
||||
"version": "2.2.3",
|
||||
|
@ -6352,20 +6366,20 @@
|
|||
},
|
||||
{
|
||||
"name": "myclabs/deep-copy",
|
||||
"version": "1.9.5",
|
||||
"version": "1.10.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/myclabs/DeepCopy.git",
|
||||
"reference": "b2c28789e80a97badd14145fda39b545d83ca3ef"
|
||||
"reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/b2c28789e80a97badd14145fda39b545d83ca3ef",
|
||||
"reference": "b2c28789e80a97badd14145fda39b545d83ca3ef",
|
||||
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/969b211f9a51aa1f6c01d1d2aef56d3bd91598e5",
|
||||
"reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1"
|
||||
"php": "^7.1 || ^8.0"
|
||||
},
|
||||
"replace": {
|
||||
"myclabs/deep-copy": "self.version"
|
||||
|
@ -6396,7 +6410,13 @@
|
|||
"object",
|
||||
"object graph"
|
||||
],
|
||||
"time": "2020-01-17T21:11:47+00:00"
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2020-06-29T13:22:24+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phar-io/manifest",
|
||||
|
@ -6502,25 +6522,25 @@
|
|||
},
|
||||
{
|
||||
"name": "phpdocumentor/reflection-common",
|
||||
"version": "2.1.0",
|
||||
"version": "2.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpDocumentor/ReflectionCommon.git",
|
||||
"reference": "6568f4687e5b41b054365f9ae03fcb1ed5f2069b"
|
||||
"reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/6568f4687e5b41b054365f9ae03fcb1ed5f2069b",
|
||||
"reference": "6568f4687e5b41b054365f9ae03fcb1ed5f2069b",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b",
|
||||
"reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
"php": "^7.2 || ^8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.x-dev"
|
||||
"dev-2.x": "2.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -6547,7 +6567,7 @@
|
|||
"reflection",
|
||||
"static analysis"
|
||||
],
|
||||
"time": "2020-04-27T09:25:28+00:00"
|
||||
"time": "2020-06-27T09:03:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpdocumentor/reflection-docblock",
|
||||
|
@ -6604,25 +6624,24 @@
|
|||
},
|
||||
{
|
||||
"name": "phpdocumentor/type-resolver",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpDocumentor/TypeResolver.git",
|
||||
"reference": "30441f2752e493c639526b215ed81d54f369d693"
|
||||
"reference": "e878a14a65245fbe78f8080eba03b47c3b705651"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/30441f2752e493c639526b215ed81d54f369d693",
|
||||
"reference": "30441f2752e493c639526b215ed81d54f369d693",
|
||||
"url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e878a14a65245fbe78f8080eba03b47c3b705651",
|
||||
"reference": "e878a14a65245fbe78f8080eba03b47c3b705651",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2",
|
||||
"php": "^7.2 || ^8.0",
|
||||
"phpdocumentor/reflection-common": "^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-tokenizer": "^7.2",
|
||||
"mockery/mockery": "~1"
|
||||
"ext-tokenizer": "*"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
|
@ -6646,7 +6665,7 @@
|
|||
}
|
||||
],
|
||||
"description": "A PSR-5 based resolver of Class names, Types and Structural Element Names",
|
||||
"time": "2020-06-19T20:22:09+00:00"
|
||||
"time": "2020-06-27T10:12:23+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpspec/prophecy",
|
||||
|
@ -8065,7 +8084,8 @@
|
|||
"platform": {
|
||||
"php": "^7.1",
|
||||
"ext-json": "*",
|
||||
"ext-pdo": "*"
|
||||
"ext-pdo": "*",
|
||||
"ext-bcmath": "*"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "1.1.0"
|
||||
|
|
|
@ -0,0 +1,234 @@
|
|||
<?php
|
||||
|
||||
namespace MonarcAppFo\Tests\Integration\Service;
|
||||
|
||||
use DateTime;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Laminas\ServiceManager\ServiceManager;
|
||||
use Monarc\FrontOffice\Model\Table\AnrTable;
|
||||
use Monarc\FrontOffice\Model\Table\SettingTable;
|
||||
use Monarc\FrontOffice\Stats\DataObject\StatsDataObject;
|
||||
use Monarc\FrontOffice\Stats\Exception\StatsAlreadyCollectedException;
|
||||
use Monarc\FrontOffice\Stats\Provider\StatsApiProvider;
|
||||
use Monarc\FrontOffice\Stats\Service\StatsAnrService;
|
||||
use MonarcAppFo\Tests\Integration\AbstractIntegrationTestCase;
|
||||
|
||||
class StatsAnrServiceTest extends AbstractIntegrationTestCase
|
||||
{
|
||||
/** @var MockHandler */
|
||||
private $mockHandler;
|
||||
|
||||
/** @var array */
|
||||
private $currentDateParams;
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
static::createMyPrintTestData();
|
||||
}
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->currentDateParams = $this->getCurrentDateParams();
|
||||
}
|
||||
|
||||
protected function configureServiceManager(ServiceManager $serviceManager)
|
||||
{
|
||||
$serviceManager->setAllowOverride(true);
|
||||
|
||||
$this->mockHandler = new MockHandler();
|
||||
$statsApiProvider = new StatsApiProvider(
|
||||
$serviceManager->get(SettingTable::class),
|
||||
[],
|
||||
$this->mockHandler
|
||||
);
|
||||
$serviceManager->setService(StatsApiProvider::class, $statsApiProvider);
|
||||
|
||||
$serviceManager->setAllowOverride(false);
|
||||
}
|
||||
|
||||
public function testItThrowsTheErrorWhenTheTheStatsAlreadyGeneratedForToday()
|
||||
{
|
||||
$this->expectException(StatsAlreadyCollectedException::class);
|
||||
$this->expectExceptionMessage('The stats is already collected for today.');
|
||||
|
||||
$this->mockHandler->append(new Response(200, [], $this->getStatsResponse([
|
||||
[
|
||||
'type' => StatsDataObject::TYPE_RISK,
|
||||
'data' => [
|
||||
'category' => 'ANR 1',
|
||||
'series' => [
|
||||
[
|
||||
'label' => 'Low risks',
|
||||
'value' => 50,
|
||||
|
||||
],
|
||||
[
|
||||
'label' => 'Medium risks',
|
||||
'value' => 30,
|
||||
|
||||
],
|
||||
[
|
||||
'label' => 'High risks',
|
||||
'value' => 10,
|
||||
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
])));
|
||||
|
||||
/** @var StatsAnrService $statsAnrService */
|
||||
$statsAnrService = $this->getApplicationServiceLocator()->get(StatsAnrService::class);
|
||||
$statsAnrService->collectStats();
|
||||
}
|
||||
|
||||
public function testItDoesNotSendTheStatsWhenTheDataIsEmpty()
|
||||
{
|
||||
$this->mockHandler->append(new Response(200, [], $this->getStatsResponse()));
|
||||
|
||||
/** @var StatsAnrService $statsAnrService */
|
||||
$statsAnrService = $this->getApplicationServiceLocator()->get(StatsAnrService::class);
|
||||
$statsAnrService->collectStats([99, 78]);
|
||||
|
||||
$this->assertEquals('GET', $this->mockHandler->getLastRequest()->getMethod());
|
||||
}
|
||||
|
||||
public function testItCanGenerateTheStatsForAllTheAnrs()
|
||||
{
|
||||
/** @var AnrTable $anrTable */
|
||||
$anrTable = $this->getApplicationServiceLocator()->get(AnrTable::class);
|
||||
$anrs = $anrTable->findAll();
|
||||
$anrUuids = [];
|
||||
foreach ($anrs as $anr) {
|
||||
$anrUuids[] = $anr->getUuid();
|
||||
}
|
||||
|
||||
$this->mockHandler->append(new Response(200, [], $this->getStatsResponse()));
|
||||
$this->mockHandler->append(new Response(201, [], '{"status": "ok"}'));
|
||||
|
||||
/** @var StatsAnrService $statsAnrService */
|
||||
$statsAnrService = $this->getApplicationServiceLocator()->get(StatsAnrService::class);
|
||||
$statsAnrService->collectStats();
|
||||
|
||||
$this->assertJsonStringEqualsJsonString(
|
||||
$this->getExpectedStatsDataJson($anrUuids),
|
||||
$this->mockHandler->getLastRequest()->getBody()->getContents()
|
||||
);
|
||||
}
|
||||
|
||||
public function testItGenerateTheStatsOnlyForPassedAnrs()
|
||||
{
|
||||
$anrIdsToGenerateTheStats = [1, 2, 3];
|
||||
|
||||
/** @var AnrTable $anrTable */
|
||||
$anrTable = $this->getApplicationServiceLocator()->get(AnrTable::class);
|
||||
$anrs = $anrTable->findByIds($anrIdsToGenerateTheStats);
|
||||
$anrUuids = [];
|
||||
foreach ($anrs as $num => $anr) {
|
||||
$anrUuids[] = $anr->getUuid();
|
||||
}
|
||||
|
||||
$this->assertCount(\count($anrIdsToGenerateTheStats), $anrUuids);
|
||||
|
||||
$this->mockHandler->append(new Response(200, [], $this->getStatsResponse()));
|
||||
$this->mockHandler->append(new Response(201, [], '{"status": "ok"}'));
|
||||
|
||||
/** @var StatsAnrService $statsAnrService */
|
||||
$statsAnrService = $this->getApplicationServiceLocator()->get(StatsAnrService::class);
|
||||
$statsAnrService->collectStats($anrIdsToGenerateTheStats);
|
||||
|
||||
$this->assertJsonStringEqualsJsonString(
|
||||
$this->getExpectedStatsDataJson($anrUuids),
|
||||
$this->mockHandler->getLastRequest()->getBody()->getContents()
|
||||
);
|
||||
}
|
||||
/*
|
||||
public function testItThrowsTheExceptionIfUserIsNotLoggedIn()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testItThrowsTheExceptionIfUserDoesNotHaveTheRightsToGetTheStats()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testItAddsToTheFilterAllowedForTheUserAnrUuids()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testItAllowsToFilterBySpecificAnrsForCeoRole()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testItAllowsToGetStatsWithoutAnrsLimitationForCeoRole()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testItCanSendDifferentAggregationParamsToGetTheStats()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testItFetchesStatsForDefaultPeriodIfFromAndToDatesAreNotPassed()
|
||||
{
|
||||
}
|
||||
*/
|
||||
private function getStatsResponse(array $results = []): string
|
||||
{
|
||||
return json_encode([
|
||||
'metadata' => [
|
||||
'resultset' => [
|
||||
'count' => \count($results),
|
||||
'offset' => 0,
|
||||
'limit' => 0,
|
||||
],
|
||||
],
|
||||
'data' => $results,
|
||||
]);
|
||||
}
|
||||
|
||||
private function getExpectedStatsDataJson(array $anrUuids): string
|
||||
{
|
||||
$statsData = json_decode(
|
||||
file_get_contents($this->testPath . '/data/expected_stats_data_for_my_print.json'),
|
||||
true
|
||||
);
|
||||
|
||||
$expectedStats = [];
|
||||
foreach ($anrUuids as $num => $anrUuid) {
|
||||
foreach ($statsData as $data) {
|
||||
$data['anr'] = $anrUuid;
|
||||
$data['day'] = $this->currentDateParams['day'];
|
||||
$data['week'] = $this->currentDateParams['week'];
|
||||
$data['month'] = $this->currentDateParams['month'];
|
||||
$data['quarter'] = $this->currentDateParams['quarter'];
|
||||
$data['year'] = $this->currentDateParams['year'];
|
||||
$expectedStats[] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode($expectedStats);
|
||||
}
|
||||
|
||||
private function getCurrentDateParams(): array
|
||||
{
|
||||
$dateTime = new DateTime();
|
||||
|
||||
return [
|
||||
'day' => (int)$dateTime->format('z') + 1,
|
||||
'week' => (int)$dateTime->format('W'),
|
||||
'month' => (int)$dateTime->format('m'),
|
||||
'quarter' => (int)ceil($dateTime->format('m') / 3),
|
||||
'year' => (int)$dateTime->format('Y'),
|
||||
];
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ use Doctrine\ORM\EntityNotFoundException;
|
|||
use Laminas\InputFilter\InputFilter;
|
||||
use Monarc\FrontOffice\Model\Entity\Anr;
|
||||
use Monarc\FrontOffice\Model\Table\AnrTable;
|
||||
use Monarc\FrontOffice\Stats\DataObject\StatsDataObject;
|
||||
use Monarc\FrontOffice\Stats\Validator\GetStatsQueryParamsValidator;
|
||||
use Monarc\FrontOffice\Validator\FieldValidator\AnrExistenceValidator;
|
||||
use MonarcAppFo\Tests\Unit\AbstractUnitTestCase;
|
||||
|
@ -33,6 +34,7 @@ class GetStatsQueryParamsValidatorTest extends AbstractUnitTestCase
|
|||
public function testItIsNotValidWhenDateToLowerThenDateFromOrBiggerThenCurrentDate()
|
||||
{
|
||||
static::assertFalse($this->getStatsQueryParamsValidator->isValid([
|
||||
'type' => StatsDataObject::TYPE_RISK,
|
||||
'dateFrom' => '2020-01-01',
|
||||
'dateTo' => '2019-12-01',
|
||||
]));
|
||||
|
@ -46,6 +48,7 @@ class GetStatsQueryParamsValidatorTest extends AbstractUnitTestCase
|
|||
);
|
||||
|
||||
static::assertFalse($this->getStatsQueryParamsValidator->isValid([
|
||||
'type' => StatsDataObject::TYPE_RISK,
|
||||
'dateFrom' => '3020-01-01',
|
||||
'dateTo' => '3019-12-01',
|
||||
]));
|
||||
|
@ -62,24 +65,26 @@ class GetStatsQueryParamsValidatorTest extends AbstractUnitTestCase
|
|||
public function testItIsValidWhenTheDatesAreTheSameOrDateFromIsLessThenDateTo()
|
||||
{
|
||||
static::assertTrue($this->getStatsQueryParamsValidator->isValid([
|
||||
'type' => StatsDataObject::TYPE_RISK,
|
||||
'dateFrom' => '2019-12-01',
|
||||
'dateTo' => '2020-06-01',
|
||||
]));
|
||||
|
||||
static::assertEmpty($this->getStatsQueryParamsValidator->getErrorMessages());
|
||||
static::assertEquals(
|
||||
['dateFrom' => '2019-12-01', 'dateTo' => '2020-06-01', 'anrs' => []],
|
||||
['dateFrom' => '2019-12-01', 'dateTo' => '2020-06-01', 'anrs' => [], 'type' => StatsDataObject::TYPE_RISK],
|
||||
$this->getStatsQueryParamsValidator->getValidData()
|
||||
);
|
||||
|
||||
static::assertTrue($this->getStatsQueryParamsValidator->isValid([
|
||||
'type' => StatsDataObject::TYPE_RISK,
|
||||
'dateFrom' => '2019-12-01',
|
||||
'dateTo' => '2019-12-01',
|
||||
]));
|
||||
|
||||
static::assertEmpty($this->getStatsQueryParamsValidator->getErrorMessages());
|
||||
static::assertEquals(
|
||||
['dateFrom' => '2019-12-01', 'dateTo' => '2019-12-01', 'anrs' => []],
|
||||
['dateFrom' => '2019-12-01', 'dateTo' => '2019-12-01', 'anrs' => [], 'type' => StatsDataObject::TYPE_RISK],
|
||||
$this->getStatsQueryParamsValidator->getValidData()
|
||||
);
|
||||
}
|
||||
|
@ -91,6 +96,7 @@ class GetStatsQueryParamsValidatorTest extends AbstractUnitTestCase
|
|||
$this->anrTable->expects($this->at(2))->method('findById')->willThrowException(new EntityNotFoundException());
|
||||
|
||||
static::assertFalse($this->getStatsQueryParamsValidator->isValid([
|
||||
'type' => StatsDataObject::TYPE_RISK,
|
||||
'anrs' => [1, 2, 3, 7],
|
||||
]));
|
||||
|
||||
|
@ -101,4 +107,28 @@ class GetStatsQueryParamsValidatorTest extends AbstractUnitTestCase
|
|||
$this->getStatsQueryParamsValidator->getErrorMessages()
|
||||
);
|
||||
}
|
||||
|
||||
public function testItIsNotValidWhenTypeIsNotPassedOrWrong()
|
||||
{
|
||||
static::assertFalse($this->getStatsQueryParamsValidator->isValid([]));
|
||||
static::assertEquals(
|
||||
[
|
||||
'type' => ['isEmpty' => 'Value is required and can\'t be empty']
|
||||
],
|
||||
$this->getStatsQueryParamsValidator->getErrorMessages()
|
||||
);
|
||||
|
||||
static::assertFalse($this->getStatsQueryParamsValidator->isValid([
|
||||
'type' => 'not-existed-type'
|
||||
]));
|
||||
static::assertEquals(
|
||||
[
|
||||
'type' => [
|
||||
'notInArray' => 'Type should be one of the values: '
|
||||
. implode(', ', StatsDataObject::getAvailableTypes())
|
||||
]
|
||||
],
|
||||
$this->getStatsQueryParamsValidator->getErrorMessages()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
TRUNCATE TABLE `anrs`;
|
||||
TRUNCATE TABLE `amvs`;
|
||||
TRUNCATE TABLE `anrs_objects`;
|
||||
TRUNCATE TABLE `anrs_objects_categories`;
|
||||
TRUNCATE TABLE `assets`;
|
||||
TRUNCATE TABLE `deliveries`;
|
||||
TRUNCATE TABLE `instances`;
|
||||
TRUNCATE TABLE `instances_consequences`;
|
||||
TRUNCATE TABLE `instances_risks`;
|
||||
TRUNCATE TABLE `instances_risks_op`;
|
||||
TRUNCATE TABLE `interviews`;
|
||||
TRUNCATE TABLE `measures`;
|
||||
TRUNCATE TABLE `measures_amvs`;
|
||||
TRUNCATE TABLE `measures_measures`;
|
||||
TRUNCATE TABLE `measures_rolf_risks`;
|
||||
TRUNCATE TABLE `objects`;
|
||||
TRUNCATE TABLE `objects_categories`;
|
||||
TRUNCATE TABLE `objects_objects`;
|
||||
TRUNCATE TABLE `questions`;
|
||||
TRUNCATE TABLE `questions_choices`;
|
||||
TRUNCATE TABLE `recommandations`;
|
||||
TRUNCATE TABLE `recommandations_risks`;
|
||||
TRUNCATE TABLE `recommandations_sets`;
|
||||
TRUNCATE TABLE `referentials`;
|
||||
TRUNCATE TABLE `rolf_risks_tags`;
|
||||
TRUNCATE TABLE `rolf_risks`;
|
||||
TRUNCATE TABLE `rolf_tags`;
|
||||
TRUNCATE TABLE `scales`;
|
||||
TRUNCATE TABLE `scales_comments`;
|
||||
TRUNCATE TABLE `scales_impact_types`;
|
||||
TRUNCATE TABLE `soa`;
|
||||
TRUNCATE TABLE `soacategory`;
|
||||
TRUNCATE TABLE `themes`;
|
||||
TRUNCATE TABLE `threats`;
|
||||
TRUNCATE TABLE `vulnerabilities`;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue