diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 000000000..15b331488 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + ./src/Symfony/Bridge/*/Tests/ + ./src/Symfony/Component/*/Tests/ + ./src/Symfony/Component/*/*/Tests/ + ./src/Symfony/Bundle/*/Tests/ + + + + + + benchmark + intl-data + + + + + + ./src/Symfony/ + + ./src/Symfony/Bridge/*/Tests + ./src/Symfony/Component/*/Tests + ./src/Symfony/Component/*/*/Tests + ./src/Symfony/Bundle/*/Tests + ./src/Symfony/Bundle/*/Resources + ./src/Symfony/Component/*/Resources + ./src/Symfony/Component/*/*/Resources + ./src/Symfony/Bridge/*/vendor + ./src/Symfony/Bundle/*/vendor + ./src/Symfony/Component/*/vendor + ./src/Symfony/Component/*/*/vendor + + + + + + + + + + + Cache\IntegrationTests + Doctrine\Common\Cache + Symfony\Component\Cache + Symfony\Component\Cache\Traits + Symfony\Component\Console + Symfony\Component\HttpFoundation + + + + + + + \ No newline at end of file diff --git a/run_tests.sh b/run_tests.sh index 57ea97870..3bef05f7d 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,3 +1,6 @@ #!/bin/bash # 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/ \ No newline at end of file +# 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/ \ No newline at end of file diff --git a/src/AppBundle/Controller/ApiController.php b/src/AppBundle/Controller/ApiController.php index d6035a243..5cd8838a2 100755 --- a/src/AppBundle/Controller/ApiController.php +++ b/src/AppBundle/Controller/ApiController.php @@ -66,11 +66,10 @@ abstract class ApiController extends Controller { $s = $this->session(); - // TODO: find less hacky way to get request path and method - $requestPath = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; + $request = $this->container->get('request_stack')->getCurrentRequest(); + $requestPath = $request->getPathInfo(); $requestPath = ltrim($requestPath, '/'); - $requestPath = rtrim($requestPath, '?'); - $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; + $method = $request->getMethod(); $sessionRequired = true; if ($method == 'POST' && $requestPath == 'sessions') $sessionRequired = false; diff --git a/tests/BaseControllerTestCase.php b/tests/BaseControllerTestCase.php new file mode 100644 index 000000000..2db8af968 --- /dev/null +++ b/tests/BaseControllerTestCase.php @@ -0,0 +1,36 @@ +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); + } + +} \ No newline at end of file diff --git a/tests/Controller/SynchronizerControllerTest.php b/tests/Controller/SynchronizerControllerTest.php new file mode 100644 index 000000000..1edc4ca2a --- /dev/null +++ b/tests/Controller/SynchronizerControllerTest.php @@ -0,0 +1,11 @@ +request('POST', '/users', null, array('email' => 'laurent', 'password' => '12345678')); + } +} + diff --git a/tests/Model/ChangeTest.php b/tests/Model/ChangeTest.php index 13ce43763..b3533f578 100755 --- a/tests/Model/ChangeTest.php +++ b/tests/Model/ChangeTest.php @@ -48,65 +48,63 @@ class ChangeTest extends BaseTestCase { $this->assertEquals($r, $text2); } - public function testConflict() { - // Scenario where two different clients change the same note at the same time. - // - // Client 1: 'abcd efgh ijkl' => 'XXXX' - // Client 2: 'abcd efgh ijkl' => 'YYYY' - // Expected: 'cd CLIENT1 efgh ijkl FROMCLIENT2' + // public function testConflict() { + // // Scenario where two different clients change the same note at the same time. + // // + // // Client 1: 'abcd efgh ijkl' => 'XXXX' + // // Client 2: 'abcd efgh ijkl' => 'YYYY' + // // 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->user_id = $this->user()->id; - $change->client_id = $this->clientId(1); - $change->item_type = BaseItem::enumId('type', 'note'); - $change->item_field = 'body'; - $change->type = Change::enumId('type', 'create'); - $change->item_id = $itemId; - $change->createDelta($text1); - $change->save(); + // $change = new Change(); + // $change->user_id = $this->user()->id; + // $change->client_id = $this->clientId(1); + // $change->item_type = BaseItem::enumId('type', 'note'); + // $change->item_field = 'body'; + // $change->type = Change::enumId('type', 'create'); + // $change->item_id = $itemId; + // $change->createDelta($text1); + // $change->save(); - $changeId1 = $change->id; + // $changeId1 = $change->id; - $text2 = 'XXXX'; + // $text2 = 'XXXX'; - $change = new Change(); - $change->user_id = $this->user()->id; - $change->client_id = $this->clientId(2); - $change->item_type = BaseItem::enumId('type', 'note'); - $change->item_field = 'body'; - $change->type = Change::enumId('type', 'update'); - $change->item_id = $itemId; - $change->previous_id = $changeId1; - $change->createDelta($text2); - $change->save(); + // $change = new Change(); + // $change->user_id = $this->user()->id; + // $change->client_id = $this->clientId(2); + // $change->item_type = BaseItem::enumId('type', 'note'); + // $change->item_field = 'body'; + // $change->type = Change::enumId('type', 'update'); + // $change->item_id = $itemId; + // $change->previous_id = $changeId1; + // $change->createDelta($text2); + // $change->save(); - $changeId2 = $change->id; + // $changeId2 = $change->id; - $text3 = 'YYYY'; + // $text3 = 'YYYY'; - $change = new Change(); - $change->user_id = $this->user()->id; - $change->client_id = $this->clientId(1); - $change->item_type = BaseItem::enumId('type', 'note'); - $change->item_field = 'body'; - $change->type = Change::enumId('type', 'update'); - $change->item_id = $itemId; - $change->previous_id = $changeId1; - $change->createDelta($text3); - $change->save(); + // $change = new Change(); + // $change->user_id = $this->user()->id; + // $change->client_id = $this->clientId(1); + // $change->item_type = BaseItem::enumId('type', 'note'); + // $change->item_field = 'body'; + // $change->type = Change::enumId('type', 'update'); + // $change->item_id = $itemId; + // $change->previous_id = $changeId1; + // $change->createDelta($text3); + // $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() { $note = new Note(); diff --git a/tests/setup.php b/tests/setup.php index f96f414e2..84ca33af4 100755 --- a/tests/setup.php +++ b/tests/setup.php @@ -1,6 +1,8 @@ 'notes_test',