From 5a2e7d2d87d012eac6642b773bd998664ee53cee Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Tue, 2 Feb 2021 14:23:17 +0100 Subject: [PATCH] Add some very basic API tests --- composer.json | 2 + composer.lock | 226 +++++++++++++++++++++++++++- config/packages/test/framework.yaml | 2 + phpunit.xml.dist | 1 + symfony.lock | 9 ++ tests/Test.php | 34 +++++ 6 files changed, 273 insertions(+), 1 deletion(-) create mode 100644 config/packages/test/framework.yaml create mode 100644 tests/Test.php diff --git a/composer.json b/composer.json index 37b786a..59052a0 100644 --- a/composer.json +++ b/composer.json @@ -97,7 +97,9 @@ "friendsofphp/php-cs-fixer": "^2.16", "phpstan/phpstan": "^0.12.7", "phpstan/phpstan-phpunit": "^0.12.6", + "symfony/browser-kit": "^4.4", "symfony/debug-bundle": "^4.4", + "symfony/http-client": "^4.4", "symfony/phpunit-bridge": "^4.4", "symfony/profiler-pack": "^1.0", "symfony/var-dumper": "^4.4", diff --git a/composer.lock b/composer.lock index 0d76a27..4ae4517 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "a224ab344497eaff627fc37360295ae2", + "content-hash": "f316125123858eef6044de806b7dfde5", "packages": [ { "name": "adldap2/adldap2", @@ -7688,6 +7688,77 @@ ], "time": "2020-10-26T13:10:38+00:00" }, + { + "name": "symfony/browser-kit", + "version": "v4.4.19", + "source": { + "type": "git", + "url": "https://github.com/symfony/browser-kit.git", + "reference": "f6f060bdc473c3f3b1f00e2ebdeb3d02eda77f82" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/browser-kit/zipball/f6f060bdc473c3f3b1f00e2ebdeb3d02eda77f82", + "reference": "f6f060bdc473c3f3b1f00e2ebdeb3d02eda77f82", + "shasum": "" + }, + "require": { + "php": ">=7.1.3", + "symfony/dom-crawler": "^3.4|^4.0|^5.0" + }, + "require-dev": { + "symfony/css-selector": "^3.4|^4.0|^5.0", + "symfony/http-client": "^4.3|^5.0", + "symfony/mime": "^4.3|^5.0", + "symfony/process": "^3.4|^4.0|^5.0" + }, + "suggest": { + "symfony/process": "" + }, + "type": "library", + "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": "Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/browser-kit/tree/v4.4.19" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-27T09:09:26+00:00" + }, { "name": "symfony/debug-bundle", "version": "v4.4.19", @@ -7766,6 +7837,159 @@ ], "time": "2021-01-10T16:25:35+00:00" }, + { + "name": "symfony/dom-crawler", + "version": "v4.4.19", + "source": { + "type": "git", + "url": "https://github.com/symfony/dom-crawler.git", + "reference": "21032c566558255e551d23f4a516434c9e3a9a78" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/21032c566558255e551d23f4a516434c9e3a9a78", + "reference": "21032c566558255e551d23f4a516434c9e3a9a78", + "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|^5.0" + }, + "suggest": { + "symfony/css-selector": "" + }, + "type": "library", + "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": "Eases DOM navigation for HTML and XML documents", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/dom-crawler/tree/v4.4.19" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-27T09:09:26+00:00" + }, + { + "name": "symfony/http-client", + "version": "v4.4.19", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client.git", + "reference": "d8df50fe9229576b254c6822eb5cfff36c02c967" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client/zipball/d8df50fe9229576b254c6822eb5cfff36c02c967", + "reference": "d8df50fe9229576b254c6822eb5cfff36c02c967", + "shasum": "" + }, + "require": { + "php": ">=7.1.3", + "psr/log": "^1.0", + "symfony/http-client-contracts": "^1.1.10|^2", + "symfony/polyfill-php73": "^1.11", + "symfony/service-contracts": "^1.0|^2" + }, + "provide": { + "php-http/async-client-implementation": "*", + "php-http/client-implementation": "*", + "psr/http-client-implementation": "1.0", + "symfony/http-client-implementation": "1.1" + }, + "require-dev": { + "guzzlehttp/promises": "^1.4", + "nyholm/psr7": "^1.0", + "php-http/httplug": "^1.0|^2.0", + "psr/http-client": "^1.0", + "symfony/dependency-injection": "^4.3|^5.0", + "symfony/http-kernel": "^4.4.13", + "symfony/process": "^4.2|^5.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\HttpClient\\": "" + }, + "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": "Provides powerful methods to fetch HTTP resources synchronously or asynchronously", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/http-client/tree/v4.4.19" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-01-27T09:09:26+00:00" + }, { "name": "symfony/options-resolver", "version": "v4.4.19", diff --git a/config/packages/test/framework.yaml b/config/packages/test/framework.yaml new file mode 100644 index 0000000..5941713 --- /dev/null +++ b/config/packages/test/framework.yaml @@ -0,0 +1,2 @@ +framework: + test: true \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f98bfaf..5249cb7 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -14,6 +14,7 @@ <server name="SHELL_VERBOSITY" value="-1"/> <server name="SYMFONY_PHPUNIT_REMOVE" value=""/> <server name="SYMFONY_PHPUNIT_VERSION" value="9"/> + <server name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/> </php> <testsuites> <testsuite name="Project Test Suite"> diff --git a/symfony.lock b/symfony.lock index 291aed9..2fc7043 100644 --- a/symfony.lock +++ b/symfony.lock @@ -211,6 +211,9 @@ "symfony/asset": { "version": "v4.4.16" }, + "symfony/browser-kit": { + "version": "v4.4.19" + }, "symfony/cache": { "version": "v4.4.16" }, @@ -257,6 +260,9 @@ "symfony/doctrine-bridge": { "version": "v4.4.16" }, + "symfony/dom-crawler": { + "version": "v4.4.19" + }, "symfony/dotenv": { "version": "v4.4.16" }, @@ -311,6 +317,9 @@ "src/Kernel.php" ] }, + "symfony/http-client": { + "version": "v4.4.19" + }, "symfony/http-client-contracts": { "version": "v2.3.1" }, diff --git a/tests/Test.php b/tests/Test.php new file mode 100644 index 0000000..18eda91 --- /dev/null +++ b/tests/Test.php @@ -0,0 +1,34 @@ +<?php + +declare(strict_types=1); + +namespace App\Tests; + +use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase; +use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client; +use Symfony\Component\HttpFoundation\Response; + +class Test extends ApiTestCase +{ + /** @var Client */ + protected $client; + + protected function setUp(): void + { + parent::setUp(); + $this->client = static::createClient(); + } + + public function testIndex() + { + $response = $this->client->request('GET', '/'); + $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); + } + + public function testJSONLD() + { + $response = $this->client->request('GET', '/', ['headers' => ['HTTP_ACCEPT' => 'application/ld+json']]); + $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); + $this->assertJson($response->getContent(false)); + } +} -- GitLab