Skip to content

Commit

Permalink
add api test case
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Apr 18, 2017
1 parent 3b7d5cd commit a350bd5
Show file tree
Hide file tree
Showing 10 changed files with 972 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ before_script:
- sh -e /etc/init.d/xvfb start
- cd public
- php server.php --warmup
- php server.php --deploy
- (php -S 127.0.0.1:8008 server.php) &
- (node fusio/node_modules/protractor/bin/webdriver-manager start > /dev/null 2>&1) &
- sleep 8
Expand All @@ -33,6 +34,7 @@ script:
- cd public/fusio/tests
- node ../node_modules/protractor/bin/protractor conf.js
- cd ../../..
- vendor/bin/phpunit
env:
- DB=mysql
- DB=sqlite
13 changes: 13 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php">
<testsuites>
<testsuite name="Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
73 changes: 30 additions & 43 deletions public/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,66 +20,43 @@
*/

// entry point for the internal php server for testing
$fileUris = [
'^\/developer\/',
'^\/documentation\/',
'^\/fusio\/',
];
if (isset($_SERVER['REQUEST_URI'])) {
$fileUris = [
'^\/developer\/',
'^\/documentation\/',
'^\/fusio\/',
];

foreach ($fileUris as $regexp) {
if (isset($_SERVER['REQUEST_URI']) && preg_match('/' . $regexp . '/', $_SERVER['REQUEST_URI'])) {
return false;
foreach ($fileUris as $regexp) {
if (preg_match('/' . $regexp . '/', $_SERVER['REQUEST_URI'])) {
return false;
}
}
}

// strip if the requests starts with /index.php/
if (isset($_SERVER['REQUEST_URI']) && substr($_SERVER['REQUEST_URI'], 0, 11) == '/index.php/') {
$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 10);
// strip if the requests starts with /index.php/
if (substr($_SERVER['REQUEST_URI'], 0, 11) == '/index.php/') {
$_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 10);
}
}

$loader = require(__DIR__ . '/../vendor/autoload.php');
$container = require_once(__DIR__ . '/../container.php');
$container = require_once(__DIR__ . '/../tests/container.php');

PSX\Framework\Bootstrap::setupEnvironment($container->get('config'));

// setup connection
$params = null;
switch (getenv('DB')) {
case 'mysql':
$params = array(
'dbname' => 'fusio_ui',
'user' => 'root',
'password' => '',
'host' => 'localhost',
'driver' => 'pdo_mysql',
);
break;

default:
case 'sqlite':
$params = array(
'path' => PSX_PATH_CACHE . '/fusio_ui.db',
'driver' => 'pdo_sqlite',
);
break;
}

$config = new Doctrine\DBAL\Configuration();
$connection = Doctrine\DBAL\DriverManager::getConnection($params, $config);

$container->set('connection', $connection);

if (isset($_SERVER['argv']) && in_array('--warmup', $_SERVER['argv'])) {
// warmup
$loader->addClassMap([
'Fusio\Impl\Tests\Fixture' => __DIR__ . '/../vendor/fusio/impl/tests/Fixture.php',
'Fusio\Impl\Tests\Fixture' => __DIR__ . '/../vendor/fusio/impl/tests/Fixture.php',
'Fusio\Impl\Tests\TestSchema' => __DIR__ . '/../vendor/fusio/impl/tests/TestSchema.php',
]);

// create schema
/** @var \Doctrine\DBAL\Connection $connection */
$connection = $container->get('connection');
$fromSchema = $connection->getSchemaManager()->createSchema();
$version = \Fusio\Impl\Database\Installer::getLatestVersion();
$toSchema = $version->getSchema();
$version = \Fusio\Impl\Database\Installer::getLatestVersion();
$toSchema = $version->getSchema();
Fusio\Impl\Tests\TestSchema::appendSchema($toSchema);

$queries = $fromSchema->getMigrateToSql($toSchema, $connection->getDatabasePlatform());
Expand All @@ -92,6 +69,16 @@
PHPUnit_Extensions_Database_Operation_Factory::CLEAN_INSERT()->execute($connection, Fusio\Impl\Tests\Fixture::getDataSet());

echo 'Warmup successful' . "\n";
} elseif (isset($_SERVER['argv']) && in_array('--deploy', $_SERVER['argv'])) {
/** @var \Symfony\Component\Console\Application $console */
$console = $container->get('console');
/** @var \Symfony\Component\Console\Command\Command $command */
$command = $container->get('console')->find('system:deploy');

$input = new \Symfony\Component\Console\Input\ArrayInput(['file' => __DIR__ . '/../.fusio.yml']);
$output = new \Symfony\Component\Console\Output\ConsoleOutput();

$command->run($input, $output);
} else {
// run
$request = $container->get('request_factory')->createRequest();
Expand Down
106 changes: 106 additions & 0 deletions tests/Api/IndexTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/*
* Fusio
* A web-application to create dynamically RESTful APIs
*
* Copyright (C) 2015-2016 Christoph Kappestein <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Fusio\Custom\Tests\Api\Todo;

use Fusio\Custom\Tests\ApiTestCase;

/**
* IndexTest
*
* @author Christoph Kappestein <[email protected]>
* @license http://www.gnu.org/licenses/agpl-3.0
* @link http://fusio-project.org
*/
class IndexTest extends ApiTestCase
{
public function testGet()
{
$response = $this->send('GET', '');

$actual = (string) $response->getBody();
$expect = <<<'JSON'
{
"message": "Congratulations the installation of Fusio was successful",
"links": [
{
"rel": "about",
"name": "http:\/\/fusio-project.org"
}
]
}
JSON;

$this->assertEquals(200, $response->getStatusCode(), $actual);
$this->assertJsonStringEqualsJsonString($expect, $actual, $actual);
}

public function testPost()
{
$response = $this->send('POST', '');

$actual = (string) $response->getBody();
$expect = <<<'JSON'
{
"success": false,
"title": "Internal Server Error",
"message": "Given request method is not supported"
}
JSON;

$this->assertEquals(405, $response->getStatusCode(), $actual);
$this->assertJsonStringEqualsJsonString($expect, $actual, $actual);
}

public function testPut()
{
$response = $this->send('PUT', '');

$actual = (string) $response->getBody();
$expect = <<<'JSON'
{
"success": false,
"title": "Internal Server Error",
"message": "Given request method is not supported"
}
JSON;

$this->assertEquals(405, $response->getStatusCode(), $actual);
$this->assertJsonStringEqualsJsonString($expect, $actual, $actual);
}

public function testDelete()
{
$response = $this->send('DELETE', '');

$actual = (string) $response->getBody();
$expect = <<<'JSON'
{
"success": false,
"title": "Internal Server Error",
"message": "Given request method is not supported"
}
JSON;

$this->assertEquals(405, $response->getStatusCode(), $actual);
$this->assertJsonStringEqualsJsonString($expect, $actual, $actual);
}
}
Loading

0 comments on commit a350bd5

Please sign in to comment.