From 1a73e1923355a74247dbb8fdf1f72e6554a4ada4 Mon Sep 17 00:00:00 2001 From: eldadfux Date: Sat, 14 Sep 2019 06:41:16 +0300 Subject: [PATCH] Updated tests env --- .travis.yml | 3 +- composer.json | 4 ++ composer.lock | 37 +++++++++- phpunit.xml | 2 +- tests/e2e/ViewTest.php | 110 +++++++++++++++++++++++++++++ tests/resources/docker-compose.yml | 6 +- 6 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 tests/e2e/ViewTest.php diff --git a/.travis.yml b/.travis.yml index a586f585ab..19b04d1916 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,8 +15,9 @@ services: - docker before_install: -- composer update --ignore-platform-reqs --optimize-autoloader --no-dev --no-plugins --no-scripts +- composer update --ignore-platform-reqs --optimize-autoloader --no-plugins --no-scripts - sudo service mysql stop +- cp -r tests/resources/mock/db tests/resources/storage/db install: - docker-compose -f tests/resources/docker-compose.yml up -d diff --git a/composer.json b/composer.json index 581fa01108..818721c470 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,9 @@ "Template\\": "src/Template" } }, + "autoload-dev": { + "psr-4": {"Tests\\E2E\\": "tests/e2e"} + }, "require": { "php": ">=7.3.0", "ext-curl": "*", @@ -37,6 +40,7 @@ "appwrite/sdk-generator": "master", "appwrite/php-clamav": "master", + "appwrite/appwrite": "master", "utopia-php/framework": "master", "utopia-php/abuse": "master", diff --git a/composer.lock b/composer.lock index a6b762fc5c..3c2580d577 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,43 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "197b677f995f7b308494e55f1dc66729", + "content-hash": "bcdcb2d9926740fea4a0515f87c58a3c", "packages": [ + { + "name": "appwrite/appwrite", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/appwrite/sdk-for-php.git", + "reference": "c3d6f82565cc5606980451221b8f0a28af6af2f5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/appwrite/sdk-for-php/zipball/c3d6f82565cc5606980451221b8f0a28af6af2f5", + "reference": "c3d6f82565cc5606980451221b8f0a28af6af2f5", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "php": ">=7.1.0" + }, + "require-dev": { + "phpunit/phpunit": "3.7.35" + }, + "type": "library", + "autoload": { + "psr-4": { + "Appwrite\\": "src/Appwrite" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Appwrite backend as a service cuts up to 70% of the time and costs required for building a modern application. We abstract and simplify common development tasks behind a REST APIs, to help you develop your app in a fast and secure way. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)", + "time": "2019-09-12T16:19:16+00:00" + }, { "name": "appwrite/php-clamav", "version": "dev-master", diff --git a/phpunit.xml b/phpunit.xml index bb76303003..5bb3ce95f7 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,7 +10,7 @@ > - ./tests/ + ./tests/e2e/ \ No newline at end of file diff --git a/tests/e2e/ViewTest.php b/tests/e2e/ViewTest.php new file mode 100644 index 0000000000..9762532ea8 --- /dev/null +++ b/tests/e2e/ViewTest.php @@ -0,0 +1,110 @@ + + * @version 1.0 RC4 + * @license The MIT License (MIT) + */ + +namespace Tests\E2E; + +use PHPUnit\Framework\TestCase; + +class ViewTest extends TestCase +{ + /** + * @var View + */ + protected $view = null; + + public function setUp() + { + $this->view = new View(__DIR__ . '/mocks/View/template.phtml'); + } + + public function tearDown() + { + $this->view = null; + } + + public function testSetParam() + { + $value = $this->view->setParam('key', 'value'); + + // Assertions + $this->assertInstanceOf('Utopia\View', $value); + } + + public function testGetParam() + { + $this->view->setParam('key', 'value'); + + // Assertions + $this->assertEquals('value', $this->view->getParam('key', 'default')); + $this->assertEquals('default', $this->view->getParam('fake', 'default')); + } + + public function testSetPath() + { + $value = $this->view->setPath('mocks/View/fake.phtml'); + + // Assertions + $this->assertInstanceOf('Utopia\View', $value); + } + + public function testSetRendered() + { + $this->view->setRendered(); + + // Assertions + $this->assertEquals(true, $this->view->isRendered()); + } + + public function testIsRendered() + { + // Assertions + $this->view->setRendered(false); + $this->assertEquals(false, $this->view->isRendered()); + + // Assertions + $this->view->setRendered(true); + $this->assertEquals(true, $this->view->isRendered()); + } + + public function testRender() + { + // Assertions + $this->assertEquals('
Test template mock
', $this->view->render()); + + $this->view->setRendered(); + $this->assertEquals('', $this->view->render()); + + try { + $this->view->setRendered(false); + $this->view->setPath('just-a-broken-string.phtml'); + $this->view->render(); + } + catch(\Exception $e) { + return; + } + + $this->fail('An expected exception has not been raised.'); + } + + public function testEscape() + { + // Assertions + $this->assertEquals('&"', $this->view->print('&"', View::FILTER_ESCAPE)); + } + + public function testNl2p() + { + // Assertions + $this->assertEquals('

line1

line2

', $this->view->print("line1\n\nline2", View::FILTER_NL2P)); + } +} \ No newline at end of file diff --git a/tests/resources/docker-compose.yml b/tests/resources/docker-compose.yml index 518c6bf698..a2044469ad 100644 --- a/tests/resources/docker-compose.yml +++ b/tests/resources/docker-compose.yml @@ -5,6 +5,8 @@ services: build: ../../ restart: unless-stopped volumes: + - ./../../:/usr/share/nginx/html + - ./../../docker/nginx.conf:/etc/nginx/nginx.conf:rw - ./storage:/storage:rw ports: - "80:80" @@ -29,8 +31,8 @@ services: restart: unless-stopped environment: - MYSQL_ROOT_PASSWORD=password - #volumes: - #- ./storage/db:/var/lib/mysql:rw + volumes: + - ./storage/db:/var/lib/mysql:rw ports: - 3306:3306/tcp