From a447ba971398840b33d6e5acd53dd9c7d30f13d1 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Tue, 28 Jun 2016 19:38:38 +0200 Subject: [PATCH] Use postgresql for travis --- .travis.yml | 13 ++- app/AppKernel.php | 7 ++ app/config/config_test.yml | 12 ++- app/config/config_travis.yml | 28 ++++++ .../Tests/Controller/EventControllerTest.php | 96 ++++++++++++++----- 5 files changed, 126 insertions(+), 30 deletions(-) create mode 100644 app/config/config_travis.yml diff --git a/.travis.yml b/.travis.yml index 0e741e6..90f28e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,17 @@ language: php + php: - '5.6' - '7.0' + +services: + - postgresql + install: - composer install -script: bin/phpunit -c app -before_script: phpenv config-add .travis-php-config.ini + +before_script: + - psql -c 'create database travis_ci_test;' -U postgres + - cp app/config/config_travis.yml app/config/config_test.yml + +script: bin/phpunit --verbose -c app diff --git a/app/AppKernel.php b/app/AppKernel.php index 7c11c0f..3ec9a0a 100755 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -34,4 +34,11 @@ class AppKernel extends Kernel { $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml'); } + + + public function __construct($environment, $debug) + { + date_default_timezone_set( 'Europe/Berlin' ); + parent::__construct($environment, $debug); + } } diff --git a/app/config/config_test.yml b/app/config/config_test.yml index c6d4442..3ebd046 100644 --- a/app/config/config_test.yml +++ b/app/config/config_test.yml @@ -19,8 +19,10 @@ liip_functional_test: ~ doctrine: dbal: - default_connection: default - connections: - default: - driver: pdo_sqlite - path: %kernel.cache_dir%/test.db \ No newline at end of file + driver: "pdo_pgsql" + host: "localhost" + port: "5432" + dbname: "travis_ci_test" + user: "postgres" + password: "123456" + charset: UTF8 \ No newline at end of file diff --git a/app/config/config_travis.yml b/app/config/config_travis.yml new file mode 100644 index 0000000..3d2642f --- /dev/null +++ b/app/config/config_travis.yml @@ -0,0 +1,28 @@ +imports: + - { resource: config_dev.yml } + +framework: + test: ~ + session: + storage_id: session.storage.mock_file + profiler: + collect: false + +web_profiler: + toolbar: false + intercept_redirects: false + +swiftmailer: + disable_delivery: true + +liip_functional_test: ~ + +doctrine: + dbal: + driver: "pdo_pgsql" + host: "localhost" + port: "5432" + dbname: "travis_ci_test" + user: "postgres" + password: "" + charset: UTF8 \ No newline at end of file diff --git a/src/Hackspace/Bundle/CalciferBundle/Tests/Controller/EventControllerTest.php b/src/Hackspace/Bundle/CalciferBundle/Tests/Controller/EventControllerTest.php index 0a0ac22..3274dce 100644 --- a/src/Hackspace/Bundle/CalciferBundle/Tests/Controller/EventControllerTest.php +++ b/src/Hackspace/Bundle/CalciferBundle/Tests/Controller/EventControllerTest.php @@ -2,6 +2,7 @@ namespace Hackspace\Bundle\CalciferBundle\Tests\Controller; +use Doctrine\Bundle\DoctrineBundle\Registry; use Doctrine\ORM\Decorator\EntityManagerDecorator; use Doctrine\ORM\EntityRepository; use Hackspace\Bundle\CalciferBundle\Entity\Event; @@ -9,23 +10,60 @@ use Liip\FunctionalTestBundle\Test\WebTestCase; class EventControllerTest extends WebTestCase { + /** @var \DateTime */ + private $now = null; - private function initClient() { - $this->loadFixtures([]); + /** @var \DateTime */ + private $startdate = null; + + /** @var \DateTime */ + private $enddate = null; + + const dateformat = "Y-m-d H:i"; + + /** + * EventControllerTest constructor. + */ + public function __construct($name = null, array $data = [], $dataName = '') + { + parent::__construct($name,$data,$dataName); + $this->now = new \DateTime(); + $this->now->setTime(0,0,0); + + $tz = new \DateTimeZone("Europe/Berlin"); + $this->now->setTimezone($tz); + + $this->startdate = clone $this->now; + $this->startdate->add(new \DateInterval("P1D")); + $this->enddate = clone $this->now; + $this->enddate->add(new \DateInterval("P1DT2H")); - $client = static::makeClient(); - return $client; } + public static function runCommandStatic($name) { + $command = sprintf("php app/console %s", $name); + $output = ""; + exec($command,$output); + return $output; + } + + public static function setUpBeforeClass() + { + EventControllerTest::runCommandStatic("doctrine:database:drop --force --env=test"); + EventControllerTest::runCommandStatic("doctrine:database:create --env=test"); + EventControllerTest::runCommandStatic("doctrine:schema:create --env=test"); + } + + public function testEmptyListing() { - $client = $this->initClient(); + $client = static::makeClient(); $crawler = $client->request('GET', '/'); $this->assertStatusCode(200, $client); } public function testPostEventForm() { - $client = $this->initClient(); + $client = static::makeClient(); $url = $client->getContainer()->get('router')->generate('_new'); @@ -34,19 +72,11 @@ class EventControllerTest extends WebTestCase $form = $crawler->selectButton('save')->form(); - $now = new \DateTime(); - $now->setTime(0,0,0); - $tz = new \DateTimeZone("Europe/Berlin"); - $now->setTimezone($tz); - $dateformat = "Y-m-d H:i"; - $startdate = clone $now; - $startdate->add(new \DateInterval("P1D")); - $enddate = clone $now; - $enddate->add(new \DateInterval("P1DT2H")); - $form['startdate'] = $startdate->format("Y-m-d H:i"); - $form['enddate'] = $enddate->format("Y-m-d H:i"); + + $form['startdate'] = $this->startdate->format(EventControllerTest::dateformat); + $form['enddate'] = $this->enddate->format(EventControllerTest::dateformat); $form['summary'] = "Testevent"; $form['url'] = "https://calcifer.datenknoten.me"; $form["location"] = "Krautspace"; @@ -87,8 +117,8 @@ class EventControllerTest extends WebTestCase $this->assertInstanceOf('Hackspace\Bundle\CalciferBundle\Entity\Event', $entity); - $this->assertTrue($startdate == $entity->startdate, "Startdate equal"); - $this->assertTrue($enddate == $entity->enddate, "Enddate equal"); + $this->assertTrue($this->startdate == $entity->startdate, "Startdate equal"); + $this->assertTrue($this->enddate == $entity->enddate, "Enddate equal"); $this->assertTrue($form["summary"]->getValue() == $entity->summary, "Summary equal"); $this->assertTrue($form["url"]->getValue() == $entity->url, "URL equal"); $this->assertTrue($form["description"]->getValue() == $entity->description, "Description equal"); @@ -102,10 +132,17 @@ class EventControllerTest extends WebTestCase $this->assertTrue($form["location_lat"]->getValue() == $entity->location->lat); $this->assertTrue($form["location_lon"]->getValue() == $entity->location->lon); + $em->close(); + + /** @var Registry $doc */ + $doc = $this->getContainer()->get('doctrine'); + + foreach($doc->getConnections() as $connection) { + $connection->close(); + } } public function testICS() { - $this->testPostEventForm(); $client = static::makeClient(); @@ -125,18 +162,31 @@ BEGIN:VEVENT UID:https://localhost/termine/testevent DTSTAMP;TZID=Europe/Berlin:20160627T000000 SUMMARY:Testevent -DTSTART;TZID=Europe/Berlin:20160628T000000 +DTSTART:%s DESCRIPTION:Testdescription URL;VALUE=URI:https://calcifer.datenknoten.me CATEGORIES:foo,bar,krautspace -DTEND;TZID=Europe/Berlin:20160628T020000 +DTEND:%s LOCATION:Krautspace GEO:1;2 END:VEVENT END:VCALENDAR EOF; + $new_tz = new \DateTimeZone("UTC"); + $this->startdate->setTimezone($new_tz); + $this->enddate->setTimezone($new_tz); + $start = $this->startdate->format("Ymd") . "T" . $this->startdate->format("His") . "Z"; + $end = $this->enddate->format("Ymd") . "T" . $this->enddate->format("His") . "Z"; - $this->assertEquals($test_doc, $client->getResponse()->getContent()); + $test_doc = sprintf($test_doc,$start,$end); + + $content = $client->getResponse()->getContent(); + + $content = preg_replace('~\R~u', "\r\n", $content); + $test_doc = preg_replace('~\R~u', "\r\n", $test_doc); + + $this->assertGreaterThan(0,strlen($content)); + $this->assertEquals($test_doc, $content); } }