You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-08-13 22:12:50 +02:00
Allow testing controllers for integration testing
This commit is contained in:
78
phpunit.xml.dist
Normal file
78
phpunit.xml.dist
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
|
||||||
|
backupGlobals="false"
|
||||||
|
colors="true"
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
failOnRisky="true"
|
||||||
|
failOnWarning="true"
|
||||||
|
>
|
||||||
|
<php>
|
||||||
|
<ini name="error_reporting" value="-1" />
|
||||||
|
<ini name="intl.default_locale" value="en" />
|
||||||
|
<ini name="intl.error_level" value="0" />
|
||||||
|
<ini name="memory_limit" value="-1" />
|
||||||
|
<env name="DUMP_LIGHT_ARRAY" value="" />
|
||||||
|
<env name="DUMP_STRING_LENGTH" value="" />
|
||||||
|
<env name="LDAP_HOST" value="127.0.0.1" />
|
||||||
|
<env name="LDAP_PORT" value="3389" />
|
||||||
|
<env name="REDIS_HOST" value="localhost" />
|
||||||
|
<env name="MEMCACHED_HOST" value="localhost" />
|
||||||
|
<server name="KERNEL_DIR" value="app/" />
|
||||||
|
</php>
|
||||||
|
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Symfony Test Suite">
|
||||||
|
<directory>./src/Symfony/Bridge/*/Tests/</directory>
|
||||||
|
<directory>./src/Symfony/Component/*/Tests/</directory>
|
||||||
|
<directory>./src/Symfony/Component/*/*/Tests/</directory>
|
||||||
|
<directory>./src/Symfony/Bundle/*/Tests/</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
|
||||||
|
<groups>
|
||||||
|
<exclude>
|
||||||
|
<group>benchmark</group>
|
||||||
|
<group>intl-data</group>
|
||||||
|
</exclude>
|
||||||
|
</groups>
|
||||||
|
|
||||||
|
<filter>
|
||||||
|
<whitelist>
|
||||||
|
<directory>./src/Symfony/</directory>
|
||||||
|
<exclude>
|
||||||
|
<directory>./src/Symfony/Bridge/*/Tests</directory>
|
||||||
|
<directory>./src/Symfony/Component/*/Tests</directory>
|
||||||
|
<directory>./src/Symfony/Component/*/*/Tests</directory>
|
||||||
|
<directory>./src/Symfony/Bundle/*/Tests</directory>
|
||||||
|
<directory>./src/Symfony/Bundle/*/Resources</directory>
|
||||||
|
<directory>./src/Symfony/Component/*/Resources</directory>
|
||||||
|
<directory>./src/Symfony/Component/*/*/Resources</directory>
|
||||||
|
<directory>./src/Symfony/Bridge/*/vendor</directory>
|
||||||
|
<directory>./src/Symfony/Bundle/*/vendor</directory>
|
||||||
|
<directory>./src/Symfony/Component/*/vendor</directory>
|
||||||
|
<directory>./src/Symfony/Component/*/*/vendor</directory>
|
||||||
|
</exclude>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
|
||||||
|
<listeners>
|
||||||
|
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
|
||||||
|
<arguments>
|
||||||
|
<array>
|
||||||
|
<element key="time-sensitive">
|
||||||
|
<array>
|
||||||
|
<element><string>Cache\IntegrationTests</string></element>
|
||||||
|
<element><string>Doctrine\Common\Cache</string></element>
|
||||||
|
<element><string>Symfony\Component\Cache</string></element>
|
||||||
|
<element><string>Symfony\Component\Cache\Traits</string></element>
|
||||||
|
<element><string>Symfony\Component\Console</string></element>
|
||||||
|
<element><string>Symfony\Component\HttpFoundation</string></element>
|
||||||
|
</array>
|
||||||
|
</element>
|
||||||
|
</array>
|
||||||
|
</arguments>
|
||||||
|
</listener>
|
||||||
|
</listeners>
|
||||||
|
</phpunit>
|
@@ -1,3 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# php phpunit-5.7.20.phar --bootstrap vendor/autoload.php tests/Model/
|
# php phpunit-5.7.20.phar --bootstrap vendor/autoload.php tests/Model/
|
||||||
php phpunit-5.7.20.phar --filter testConflict ChangeTest tests/Model/ChangeTest.php --bootstrap vendor/autoload.php tests/Model/
|
# php phpunit-5.7.20.phar --filter testConflict ChangeTest tests/Model/ChangeTest.php --bootstrap vendor/autoload.php tests/Model/
|
||||||
|
# php phpunit-5.7.20.phar --filter SynchronizerControllerTest tests/Controller/SynchronizerControllerTest.php --bootstrap vendor/autoload.php tests/Controller/
|
||||||
|
|
||||||
|
php phpunit-5.7.20.phar --bootstrap vendor/autoload.php tests/Controller/
|
@@ -66,11 +66,10 @@ abstract class ApiController extends Controller {
|
|||||||
|
|
||||||
$s = $this->session();
|
$s = $this->session();
|
||||||
|
|
||||||
// TODO: find less hacky way to get request path and method
|
$request = $this->container->get('request_stack')->getCurrentRequest();
|
||||||
$requestPath = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
|
$requestPath = $request->getPathInfo();
|
||||||
$requestPath = ltrim($requestPath, '/');
|
$requestPath = ltrim($requestPath, '/');
|
||||||
$requestPath = rtrim($requestPath, '?');
|
$method = $request->getMethod();
|
||||||
$method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
|
|
||||||
|
|
||||||
$sessionRequired = true;
|
$sessionRequired = true;
|
||||||
if ($method == 'POST' && $requestPath == 'sessions') $sessionRequired = false;
|
if ($method == 'POST' && $requestPath == 'sessions') $sessionRequired = false;
|
||||||
|
36
tests/BaseControllerTestCase.php
Normal file
36
tests/BaseControllerTestCase.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once dirname(__FILE__) . '/setup.php';
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
|
class BaseControllerTestCase extends WebTestCase {
|
||||||
|
|
||||||
|
public function request($method, $path, $query = array(), $data = null) {
|
||||||
|
if (count($query)) $path .= '?' . http_build_query($query);
|
||||||
|
|
||||||
|
$client = static::createClient();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ($data) {
|
||||||
|
$client->request($method, $path, $data);
|
||||||
|
} else {
|
||||||
|
$client->request($method, $path);
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
if (method_exists($e, 'toErrorArray')) return $e->toErrorArray();
|
||||||
|
return array(
|
||||||
|
'error' => $e->getMessage(),
|
||||||
|
'code' => $e->getCode(),
|
||||||
|
'type' => get_class($e),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$r = $client->getResponse();
|
||||||
|
if (!$r) throw new Exception('Cannot read response from HTTP request'); // Shouldn't happen
|
||||||
|
|
||||||
|
$r = $r->getContent();
|
||||||
|
return json_decode($r, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
tests/Controller/SynchronizerControllerTest.php
Normal file
11
tests/Controller/SynchronizerControllerTest.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once dirname(dirname(__FILE__)) . '/setup.php';
|
||||||
|
|
||||||
|
class SynchronizerControllerTest extends BaseControllerTestCase {
|
||||||
|
|
||||||
|
public function testShowPost() {
|
||||||
|
// $r = $this->request('POST', '/users', null, array('email' => 'laurent', 'password' => '12345678'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -48,65 +48,63 @@ class ChangeTest extends BaseTestCase {
|
|||||||
$this->assertEquals($r, $text2);
|
$this->assertEquals($r, $text2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConflict() {
|
// public function testConflict() {
|
||||||
// Scenario where two different clients change the same note at the same time.
|
// // Scenario where two different clients change the same note at the same time.
|
||||||
//
|
// //
|
||||||
// Client 1: 'abcd efgh ijkl' => 'XXXX'
|
// // Client 1: 'abcd efgh ijkl' => 'XXXX'
|
||||||
// Client 2: 'abcd efgh ijkl' => 'YYYY'
|
// // Client 2: 'abcd efgh ijkl' => 'YYYY'
|
||||||
// Expected: 'cd CLIENT1 efgh ijkl FROMCLIENT2'
|
// // Expected: 'cd CLIENT1 efgh ijkl FROMCLIENT2'
|
||||||
|
|
||||||
$text1 = 'abcd efgh ijkl';
|
// $text1 = 'abcd efgh ijkl';
|
||||||
|
|
||||||
$itemId = $this->createModelId('note');
|
// $itemId = $this->createModelId('note');
|
||||||
|
|
||||||
$change = new Change();
|
// $change = new Change();
|
||||||
$change->user_id = $this->user()->id;
|
// $change->user_id = $this->user()->id;
|
||||||
$change->client_id = $this->clientId(1);
|
// $change->client_id = $this->clientId(1);
|
||||||
$change->item_type = BaseItem::enumId('type', 'note');
|
// $change->item_type = BaseItem::enumId('type', 'note');
|
||||||
$change->item_field = 'body';
|
// $change->item_field = 'body';
|
||||||
$change->type = Change::enumId('type', 'create');
|
// $change->type = Change::enumId('type', 'create');
|
||||||
$change->item_id = $itemId;
|
// $change->item_id = $itemId;
|
||||||
$change->createDelta($text1);
|
// $change->createDelta($text1);
|
||||||
$change->save();
|
// $change->save();
|
||||||
|
|
||||||
$changeId1 = $change->id;
|
// $changeId1 = $change->id;
|
||||||
|
|
||||||
$text2 = 'XXXX';
|
// $text2 = 'XXXX';
|
||||||
|
|
||||||
$change = new Change();
|
// $change = new Change();
|
||||||
$change->user_id = $this->user()->id;
|
// $change->user_id = $this->user()->id;
|
||||||
$change->client_id = $this->clientId(2);
|
// $change->client_id = $this->clientId(2);
|
||||||
$change->item_type = BaseItem::enumId('type', 'note');
|
// $change->item_type = BaseItem::enumId('type', 'note');
|
||||||
$change->item_field = 'body';
|
// $change->item_field = 'body';
|
||||||
$change->type = Change::enumId('type', 'update');
|
// $change->type = Change::enumId('type', 'update');
|
||||||
$change->item_id = $itemId;
|
// $change->item_id = $itemId;
|
||||||
$change->previous_id = $changeId1;
|
// $change->previous_id = $changeId1;
|
||||||
$change->createDelta($text2);
|
// $change->createDelta($text2);
|
||||||
$change->save();
|
// $change->save();
|
||||||
|
|
||||||
$changeId2 = $change->id;
|
// $changeId2 = $change->id;
|
||||||
|
|
||||||
$text3 = 'YYYY';
|
// $text3 = 'YYYY';
|
||||||
|
|
||||||
$change = new Change();
|
// $change = new Change();
|
||||||
$change->user_id = $this->user()->id;
|
// $change->user_id = $this->user()->id;
|
||||||
$change->client_id = $this->clientId(1);
|
// $change->client_id = $this->clientId(1);
|
||||||
$change->item_type = BaseItem::enumId('type', 'note');
|
// $change->item_type = BaseItem::enumId('type', 'note');
|
||||||
$change->item_field = 'body';
|
// $change->item_field = 'body';
|
||||||
$change->type = Change::enumId('type', 'update');
|
// $change->type = Change::enumId('type', 'update');
|
||||||
$change->item_id = $itemId;
|
// $change->item_id = $itemId;
|
||||||
$change->previous_id = $changeId1;
|
// $change->previous_id = $changeId1;
|
||||||
$change->createDelta($text3);
|
// $change->createDelta($text3);
|
||||||
$change->save();
|
// $change->save();
|
||||||
|
|
||||||
$changeId3 = $change->id;
|
// $changeId3 = $change->id;
|
||||||
|
|
||||||
$r = Change::fullFieldText($itemId, 'body');
|
// $r = Change::fullFieldText($itemId, 'body');
|
||||||
|
|
||||||
var_dump($r);die();
|
// $this->assertEquals($r, 'cd CLIENT1 efgh ijkl FROMCLIENT2');
|
||||||
|
// }
|
||||||
$this->assertEquals($r, 'cd CLIENT1 efgh ijkl FROMCLIENT2');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testSame() {
|
public function testSame() {
|
||||||
$note = new Note();
|
$note = new Note();
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
require_once dirname(__FILE__) . '/BaseTestCase.php';
|
require_once dirname(__FILE__) . '/BaseTestCase.php';
|
||||||
|
require_once dirname(__FILE__) . '/BaseControllerTestCase.php';
|
||||||
|
|
||||||
$dbConfig = array(
|
$dbConfig = array(
|
||||||
'dbName' => 'notes_test',
|
'dbName' => 'notes_test',
|
||||||
|
Reference in New Issue
Block a user