diff --git a/api/.env.test b/api/.env.test new file mode 100644 index 0000000000000000000000000000000000000000..d0486867ed386d60931f80353f41aaef61974081 --- /dev/null +++ b/api/.env.test @@ -0,0 +1,5 @@ +# define your env variables for the test env here +KERNEL_CLASS='App\Kernel' +APP_SECRET='$ecretf0rt3st' +SYMFONY_DEPRECATIONS_HELPER=999999 +PANTHER_APP_ENV=panther diff --git a/api/.gitignore b/api/.gitignore index c05dd56c07c3431e9799d03e92056d9850b1d43a..8f66341d467ef628f5dbd77973fa6f7828d08847 100644 --- a/api/.gitignore +++ b/api/.gitignore @@ -14,3 +14,9 @@ /.php_cs /.php_cs.cache ###< friendsofphp/php-cs-fixer ### + +###> symfony/phpunit-bridge ### +.phpunit +.phpunit.result.cache +/phpunit.xml +###< symfony/phpunit-bridge ### diff --git a/api/bin/phpunit b/api/bin/phpunit new file mode 100755 index 0000000000000000000000000000000000000000..4d1ed05d3c5434e3da54cd09b150d5904ac3e79f --- /dev/null +++ b/api/bin/phpunit @@ -0,0 +1,13 @@ +#!/usr/bin/env php +=5.3.3" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1", + "json-schema/json-schema-test-suite": "1.2.0", + "phpunit/phpunit": "^4.8.35" + }, + "bin": [ + "bin/validate-json" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "JsonSchema\\": "src/JsonSchema/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bruno Prieto Reis", + "email": "bruno.p.reis@gmail.com" + }, + { + "name": "Justin Rainbow", + "email": "justin.rainbow@gmail.com" + }, + { + "name": "Igor Wiedler", + "email": "igor@wiedler.ch" + }, + { + "name": "Robert Schönthal", + "email": "seroscho@googlemail.com" + } + ], + "description": "A library to validate a json schema.", + "homepage": "https://github.com/justinrainbow/json-schema", + "keywords": [ + "json", + "schema" + ], + "time": "2019-09-25T14:49:45+00:00" + }, { "name": "league/html-to-markdown", "version": "4.9.0", @@ -6190,6 +6257,179 @@ ], "time": "2018-02-15T16:58:55+00:00" }, + { + "name": "symfony/browser-kit", + "version": "v4.3.9", + "source": { + "type": "git", + "url": "https://github.com/symfony/browser-kit.git", + "reference": "b14fa08508afd152257d5dcc7adb5f278654d972" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/browser-kit/zipball/b14fa08508afd152257d5dcc7adb5f278654d972", + "reference": "b14fa08508afd152257d5dcc7adb5f278654d972", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/dom-crawler": "~3.4|~4.0" + }, + "require-dev": { + "symfony/css-selector": "~3.4|~4.0", + "symfony/http-client": "^4.3", + "symfony/mime": "^4.3", + "symfony/process": "~3.4|~4.0" + }, + "suggest": { + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\BrowserKit\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony BrowserKit Component", + "homepage": "https://symfony.com", + "time": "2019-10-28T17:07:32+00:00" + }, + { + "name": "symfony/css-selector", + "version": "v4.3.9", + "source": { + "type": "git", + "url": "https://github.com/symfony/css-selector.git", + "reference": "f4b3ff6a549d9ed28b2b0ecd1781bf67cf220ee9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/f4b3ff6a549d9ed28b2b0ecd1781bf67cf220ee9", + "reference": "f4b3ff6a549d9ed28b2b0ecd1781bf67cf220ee9", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\CssSelector\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Jean-François Simon", + "email": "jeanfrancois.simon@sensiolabs.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony CssSelector Component", + "homepage": "https://symfony.com", + "time": "2019-10-02T08:36:26+00:00" + }, + { + "name": "symfony/dom-crawler", + "version": "v4.3.9", + "source": { + "type": "git", + "url": "https://github.com/symfony/dom-crawler.git", + "reference": "4b9efd5708c3a38593e19b6a33e40867f4f89d72" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/4b9efd5708c3a38593e19b6a33e40867f4f89d72", + "reference": "4b9efd5708c3a38593e19b6a33e40867f4f89d72", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "masterminds/html5": "<2.6" + }, + "require-dev": { + "masterminds/html5": "^2.6", + "symfony/css-selector": "~3.4|~4.0" + }, + "suggest": { + "symfony/css-selector": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\DomCrawler\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony DomCrawler Component", + "homepage": "https://symfony.com", + "time": "2019-10-28T17:07:32+00:00" + }, { "name": "symfony/maker-bundle", "version": "v1.14.3", @@ -6312,6 +6552,71 @@ ], "time": "2019-10-28T20:59:01+00:00" }, + { + "name": "symfony/phpunit-bridge", + "version": "v5.0.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/phpunit-bridge.git", + "reference": "010cf42a81e7bec744edfdef5f76d6394f4906a7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/010cf42a81e7bec744edfdef5f76d6394f4906a7", + "reference": "010cf42a81e7bec744edfdef5f76d6394f4906a7", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "conflict": { + "phpunit/phpunit": "<5.4.3" + }, + "suggest": { + "symfony/error-handler": "For tracking deprecated interfaces usages at runtime with DebugClassLoader" + }, + "bin": [ + "bin/simple-phpunit" + ], + "type": "symfony-bridge", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + }, + "thanks": { + "name": "phpunit/phpunit", + "url": "https://github.com/sebastianbergmann/phpunit" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Bridge\\PhpUnit\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony PHPUnit Bridge", + "homepage": "https://symfony.com", + "time": "2019-11-28T14:20:16+00:00" + }, { "name": "symfony/process", "version": "v4.3.8", @@ -6389,6 +6694,34 @@ "description": "A pack for the Symfony web profiler", "time": "2018-12-10T12:11:44+00:00" }, + { + "name": "symfony/test-pack", + "version": "v1.0.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/test-pack.git", + "reference": "ff87e800a67d06c423389f77b8209bc9dc469def" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/test-pack/zipball/ff87e800a67d06c423389f77b8209bc9dc469def", + "reference": "ff87e800a67d06c423389f77b8209bc9dc469def", + "shasum": "" + }, + "require": { + "php": "^7.0", + "symfony/browser-kit": "*", + "symfony/css-selector": "*", + "symfony/phpunit-bridge": "*" + }, + "type": "symfony-pack", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A pack for functional and end-to-end testing within a Symfony app", + "time": "2019-06-21T06:27:32+00:00" + }, { "name": "symfony/var-dumper", "version": "v4.3.8", diff --git a/api/phpunit.xml.dist b/api/phpunit.xml.dist new file mode 100644 index 0000000000000000000000000000000000000000..5b7c82022104a0bda3efc1ea5d1d55fca4bd5132 --- /dev/null +++ b/api/phpunit.xml.dist @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + tests + + + + + + src + + + + + + + diff --git a/api/symfony.lock b/api/symfony.lock index 55a3eb5820d66891d23f09f0eefad1268a24b849..1607aea62f4d612ba07fb7fd684c4206ad580eb1 100644 --- a/api/symfony.lock +++ b/api/symfony.lock @@ -149,6 +149,9 @@ "jdorn/sql-formatter": { "version": "v1.2.17" }, + "justinrainbow/json-schema": { + "version": "5.2.9" + }, "league/html-to-markdown": { "version": "4.9.0" }, @@ -209,6 +212,9 @@ "symfony/asset": { "version": "v4.3.8" }, + "symfony/browser-kit": { + "version": "v4.3.9" + }, "symfony/cache": { "version": "v4.3.8" }, @@ -231,6 +237,9 @@ "config/bootstrap.php" ] }, + "symfony/css-selector": { + "version": "v4.3.9" + }, "symfony/debug": { "version": "v4.3.8" }, @@ -240,6 +249,9 @@ "symfony/doctrine-bridge": { "version": "v4.3.8" }, + "symfony/dom-crawler": { + "version": "v4.3.9" + }, "symfony/dotenv": { "version": "v4.3.8" }, @@ -334,6 +346,22 @@ "symfony/options-resolver": { "version": "v4.3.8" }, + "symfony/phpunit-bridge": { + "version": "4.3", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "4.3", + "ref": "170be6250b77b421f02e986e2853df86c7bd6516" + }, + "files": [ + ".env.test", + "bin/phpunit", + "config/bootstrap.php", + "phpunit.xml.dist", + "tests/.gitignore" + ] + }, "symfony/polyfill-intl-idn": { "version": "v1.12.0" }, @@ -405,6 +433,9 @@ "symfony/stopwatch": { "version": "v4.3.8" }, + "symfony/test-pack": { + "version": "v1.0.6" + }, "symfony/translation-contracts": { "version": "v1.1.7" }, diff --git a/api/tests/.gitignore b/api/tests/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/api/tests/AnalyticsTest.php b/api/tests/AnalyticsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..be86618673aef3b51e22b917870b577163977ea1 --- /dev/null +++ b/api/tests/AnalyticsTest.php @@ -0,0 +1,164 @@ +request('GET', '/property_sales/average_surface_price'); + + // Asserts that the response has 200 Status Code + $this->assertResponseIsSuccessful(); + // Asserts that the returned content type is JSON + $this->assertResponseHeaderSame('content-type', 'application/json'); + } + + public function testSalesByRegionOk(): void + { + $response = static::createClient()->request('GET', '/property_sales/sales_by_region', [ + 'query' => [ + 'year' => 2016 + ], + ]); + + // Asserts that the response has 200 Status Code + $this->assertResponseIsSuccessful(); + // Asserts that the returned content type is JSON (the default) + $this->assertResponseHeaderSame('content-type', 'application/json'); + } + + public function testSalesByRegionIncorrect(): void + { + $response = static::createClient()->request('GET', '/property_sales/sales_by_region', [ + 'query' => [ + 'year' => 201677 + ], + ]); + + // Assertion on the Status Code + $this->assertResponseStatusCodeSame(400); + // Asserts that the returned content type is Text (errors respond with texts) + $this->assertResponseHeaderSame('content-type', 'application/text'); + + $text = $response->getContent(false); + assert(strcmp($text, 'Bad Request') !== false, "Tests the text returned with the error"); + } + + public function testSalesByRegionNoParameter(): void + { + $response = static::createClient()->request('GET', '/property_sales/sales_by_region'); + + // Assertion on the Status Code + $this->assertResponseStatusCodeSame(400); + // Asserts that the returned content type is Text (errors respond with texts) + $this->assertResponseHeaderSame('content-type', 'application/text'); + } + + public function testSalesByGranularityOk(): void + { + $response = static::createClient()->request('GET', '/property_sales/sales_by_granularity', [ + 'query' => [ + 'granularity' => 'day', + 'date_start' => '2018-11-24', + 'date_end' => '2018-12-24' + ], + ]); + + // Asserts that the response has 200 Status Code + $this->assertResponseIsSuccessful(); + // Asserts that the returned content type is JSON (the default) + $this->assertResponseHeaderSame('content-type', 'application/json'); + } + + public function testSalesByGranularityGranularityIncorrect(): void + { + $response = static::createClient()->request('GET', '/property_sales/sales_by_granularity', [ + 'query' => [ + 'granularity' => 'week', + 'date_start' => '2018-11-24', + 'date_end' => '2018-12-24' + ], + ]); + + // Assertion on the Status Code + $this->assertResponseStatusCodeSame(400); + // Asserts that the returned content type is Text (errors respond with texts) + $this->assertResponseHeaderSame('content-type', 'application/text'); + + $text = $response->getContent(false); + assert(strpos($text, 'wrong format') !== false, "Tests that the error is a wrong format"); + } + + public function testSalesByGranularityDateStartIncorrect(): void + { + $response = static::createClient()->request('GET', '/property_sales/sales_by_granularity', [ + 'query' => [ + 'granularity' => 'day', + 'date_start' => 'arriva', + 'date_end' => '2018-12-24' + ], + ]); + + // Assertion on the Status Code + $this->assertResponseStatusCodeSame(400); + // Asserts that the returned content type is Text (errors respond with texts) + $this->assertResponseHeaderSame('content-type', 'application/text'); + + $text = $response->getContent(false); + assert(strpos($text, 'wrong format') !== false, "Tests that the error is a wrong format"); + } + + public function testSalesByGranularityDateEndIncorrect(): void + { + $response = static::createClient()->request('GET', '/property_sales/sales_by_granularity', [ + 'query' => [ + 'granularity' => 'day', + 'date_start' => '2018-11-24', + 'date_end' => 'speedy gonzales' + ], + ]); + + // Assertion on the Status Code + $this->assertResponseStatusCodeSame(400); + // Asserts that the returned content type is Text (errors respond with texts) + $this->assertResponseHeaderSame('content-type', 'application/text'); + + $text = $response->getContent(false); + assert(strpos($text, 'wrong format') !== false, "Tests that the error is a wrong format"); + } + + public function testSalesByGranularityDateEndBeforeDateStart(): void + { + $response = static::createClient()->request('GET', '/property_sales/sales_by_granularity', [ + 'query' => [ + 'granularity' => 'day', + 'date_start' => '2018-11-24', + 'date_end' => '2017-11-24' + ], + ]); + + // Assertion on the Status Code + $this->assertResponseStatusCodeSame(400); + // Asserts that the returned content type is Text (errors respond with texts) + $this->assertResponseHeaderSame('content-type', 'application/text'); + + $text = $response->getContent(false); + assert(strpos($text, 'before') !== false, "Tests that the error is a end before start"); + } + + public function testSalesByGranularityNoParameter(): void + { + $response = static::createClient()->request('GET', '/property_sales/sales_by_granularity'); + + // Assertion on the Status Code + $this->assertResponseStatusCodeSame(400); + // Asserts that the returned content type is Text (errors respond with texts) + $this->assertResponseHeaderSame('content-type', 'application/text'); + } +} +?> \ No newline at end of file