From fb4dd58cde1cdb89b47ed17457f20a1cb333d2c9 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Fri, 29 Mar 2019 18:44:22 +0100 Subject: [PATCH] Optimized code for FormatFunctionTest --- administration/clear.sh | 5 +- .../tests/Functional/FormatFunctionTest.php | 52 ++++++++++++------- .../tests/Unit/Entity/Meta/LawTest.php | 11 ++++ 3 files changed, 48 insertions(+), 20 deletions(-) diff --git a/administration/clear.sh b/administration/clear.sh index 89393d7..cb1f800 100644 --- a/administration/clear.sh +++ b/administration/clear.sh @@ -1,6 +1,7 @@ #!/bin/bash ( -cd "$(dirname "$(readlink -f "${0}")")/../docker-symfony/" && +cd "$(dirname "$(readlink -f "${0}")")/../docker-symfony/" && docker-compose exec php php /var/www/symfony/bin/console cache:clear && -docker-compose exec php php /var/www/symfony/bin/console cache:clear --env=prod +docker-compose exec php php /var/www/symfony/bin/console cache:clear --env=prod && +docker-compose exec php php /var/www/symfony/bin/console cache:clear --env=test ) diff --git a/application/symfony/tests/Functional/FormatFunctionTest.php b/application/symfony/tests/Functional/FormatFunctionTest.php index b157cc4..b2880d9 100644 --- a/application/symfony/tests/Functional/FormatFunctionTest.php +++ b/application/symfony/tests/Functional/FormatFunctionTest.php @@ -4,43 +4,59 @@ namespace Tests\Functional; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Bundle\FrameworkBundle\Client; /** * @author kevinfrantz */ class FormatFunctionTest extends WebTestCase { + /** + * @var Client + */ + private $client; + + public function setUp(): void + { + $this->client = static::createClient(); + } + public function testHomepage(): void { - $client = static::createClient(); - $client->request(Request::METHOD_GET, 'api/rest/source/HOMEPAGE'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertContains('getResponse()->getContent()); + $this->client->request(Request::METHOD_GET, 'api/rest/source/HOMEPAGE'); + $this->assertEquals(200, $this->client->getResponse() + ->getStatusCode()); + $this->assertJson($this->client->getResponse() + ->getContent()); } public function testHomepageWithHTML(): void { - $client = static::createClient(); - $client->request(Request::METHOD_GET, 'api/rest/source/HOMEPAGE.html'); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertContains('getResponse()->getContent()); + $this->client->request(Request::METHOD_GET, 'api/rest/source/HOMEPAGE.html'); + $this->assertEquals(200, $this->client->getResponse() + ->getStatusCode()); + $this->assertContains('client->getResponse() + ->getContent()); } public function testHomepageWithJSON(): void { - $client = static::createClient(); - $client->request(Request::METHOD_GET, 'api/rest/source/HOMEPAGE.json'); - echo $client->getResponse()->getContent(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); -// $this->assertContains('getResponse()->getContent()); + $this->client->request(Request::METHOD_GET, 'api/rest/source/HOMEPAGE.json'); + $this->assertEquals(200, $this->client->getResponse() + ->getStatusCode()); + $this->assertJson($this->client->getResponse() + ->getContent()); } public function testHomepageWithXML(): void { - $client = static::createClient(); - $client->request(Request::METHOD_GET, 'api/rest/source/HOMEPAGE.xml'); - echo $client->getResponse()->getContent(); - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - // $this->assertContains('getResponse()->getContent()); + $this->client->request(Request::METHOD_GET, 'api/rest/source/HOMEPAGE.xml'); + $this->assertEquals(200, $this->client->getResponse() + ->getStatusCode()); + $content = $this->client->getResponse()->getContent(); + $xml = new \XMLReader(); + $xml->XML($content); + $xml->setParserProperty(\XMLReader::VALIDATE, true); + $this->assertTrue($xml->isValid()); } } diff --git a/application/symfony/tests/Unit/Entity/Meta/LawTest.php b/application/symfony/tests/Unit/Entity/Meta/LawTest.php index 4b9f836..b296d25 100644 --- a/application/symfony/tests/Unit/Entity/Meta/LawTest.php +++ b/application/symfony/tests/Unit/Entity/Meta/LawTest.php @@ -34,4 +34,15 @@ class LawTest extends TestCase $this->assertNull($this->law->setRights($rights)); $this->assertEquals($right, $this->law->getRights()->get(0)); } + + /** + * Implemented to debug where ReflectionException "Property Infinito\\Entity\\Meta\\Law::$relation does not exist" is coming from. + */ + public function testRelationNotSet(): void + { + $reflectionClass = new \ReflectionClass($this->law); + $this->assertFalse($reflectionClass->hasMethod('getRelation')); + $this->assertFalse($reflectionClass->hasMethod('setRelation')); + $this->assertFalse($reflectionClass->hasProperty('relation')); + } }