From 9f155e6e6982373e1a099167e98913abbe298924 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Mon, 10 Jul 2017 22:51:36 +0300 Subject: [PATCH 1/5] Use latest stable Phalcon --- .travis.yml | 2 +- .../Model/EagerLoading/EagerLoadingTest.php | 98 ------------------- 2 files changed, 1 insertion(+), 99 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9ce910b4c..14c9a501e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,7 +45,7 @@ env: - ZEND_DONT_UNLOAD_MODULES=1 - CC="ccache gcc" - PATH="$PATH:~/bin" - - PHALCON_VERSION="v3.2.0" + - PHALCON_VERSION="v3.2.1" before_install: - export PHP_MAJOR="$(echo $TRAVIS_PHP_VERSION | cut -d '.' -f 1)" diff --git a/tests/unit/Mvc/Model/EagerLoading/EagerLoadingTest.php b/tests/unit/Mvc/Model/EagerLoading/EagerLoadingTest.php index bb91d0ed8..d9d834129 100644 --- a/tests/unit/Mvc/Model/EagerLoading/EagerLoadingTest.php +++ b/tests/unit/Mvc/Model/EagerLoading/EagerLoadingTest.php @@ -92,17 +92,6 @@ protected function _after() */ public function testShouldLoadChildOfEmptyParentWithoutException() { - if (version_compare(PHP_VERSION, '5.6.0', '<') && - version_compare(Version::get(), '3.2.0', '=') - ) { - $this->markTestSkipped( - 'The Phalcon\Mvc\Model\Query\Builder was changed in Phalcon v3.2.0.' . PHP_EOL . - 'These changes do not allow to correctly run tests in PHP 5.5.' . PHP_EOL . - 'See https://github.com/phalcon/cphalcon/pull/12905/commits/8052204db745e93aacfc38c1b6651e29b7ba9440' . PHP_EOL . - 'And https://travis-ci.org/phalcon/incubator/jobs/244703920' - ); - } - // Has many -> Belongs to // Should be the same for Has many -> Has one $loader = new Loader(Robot::findFirstById(1), 'Bugs.Robot'); @@ -111,17 +100,6 @@ public function testShouldLoadChildOfEmptyParentWithoutException() public function testManyEagerLoadsAndConstraints() { - if (version_compare(PHP_VERSION, '5.6.0', '<') && - version_compare(Version::get(), '3.2.0', '=') - ) { - $this->markTestSkipped( - 'The Phalcon\Mvc\Model\Query\Builder was changed in Phalcon v3.2.0.' . PHP_EOL . - 'These changes do not allow to correctly run tests in PHP 5.5.' . PHP_EOL . - 'See https://github.com/phalcon/cphalcon/pull/12905/commits/8052204db745e93aacfc38c1b6651e29b7ba9440' . PHP_EOL . - 'And https://travis-ci.org/phalcon/incubator/jobs/244703920' - ); - } - $manufacturers = Manufacturer::with( [ 'Robots' => function ($builder) { @@ -219,17 +197,6 @@ public function testShouldThrowInvalidArgumentExceptionIfLoaderSubjectIsNotValid */ public function testShouldThrowLogicExceptionIfTheEntityWillBeIncomplete($method, $args) { - if (version_compare(PHP_VERSION, '5.6.0', '<') && - version_compare(Version::get(), '3.2.0', '=') - ) { - $this->markTestSkipped( - 'The Phalcon\Mvc\Model\Query\Builder was changed in Phalcon v3.2.0.' . PHP_EOL . - 'These changes do not allow to correctly run tests in PHP 5.5.' . PHP_EOL . - 'See https://github.com/phalcon/cphalcon/pull/12905/commits/8052204db745e93aacfc38c1b6651e29b7ba9440' . PHP_EOL . - 'And https://travis-ci.org/phalcon/incubator/jobs/244703920' - ); - } - call_user_func_array(['Phalcon\Test\Mvc\Model\EagerLoading\Stubs\Robot', $method], $args); } @@ -245,17 +212,6 @@ public function testShouldThrowBadMethodCallExceptionIfArgumentsWereNotProvided( public function testShouldUseEagerLoadingAndGetModelByUsingMethods() { - if (version_compare(PHP_VERSION, '5.6.0', '<') && - version_compare(Version::get(), '3.2.0', '=') - ) { - $this->markTestSkipped( - 'The Phalcon\Mvc\Model\Query\Builder was changed in Phalcon v3.2.0.' . PHP_EOL . - 'These changes do not allow to correctly run tests in PHP 5.5.' . PHP_EOL . - 'See https://github.com/phalcon/cphalcon/pull/12905/commits/8052204db745e93aacfc38c1b6651e29b7ba9440' . PHP_EOL . - 'And https://travis-ci.org/phalcon/incubator/jobs/244703920' - ); - } - $this->assertTrue(is_array(Robot::with('Parts'))); $this->assertTrue(is_object(Robot::findFirstById(1)->load('Parts'))); $this->assertTrue(is_object(Robot::findFirstWith('Parts', ['id = 1']))); @@ -263,16 +219,6 @@ public function testShouldUseEagerLoadingAndGetModelByUsingMethods() public function testShouldUseEagerLoadingAndDetectHasManyToMany() { - if (version_compare(PHP_VERSION, '5.6.0', '<') && - version_compare(Version::get(), '3.2.0', '=') - ) { - $this->markTestSkipped( - 'The Phalcon\Mvc\Model\Query\Builder was changed in Phalcon v3.2.0.' . PHP_EOL . - 'These changes do not allow to correctly run tests in PHP 5.5.' . PHP_EOL . - 'See https://github.com/phalcon/cphalcon/pull/12905/commits/8052204db745e93aacfc38c1b6651e29b7ba9440' . PHP_EOL . - 'And https://travis-ci.org/phalcon/incubator/jobs/244703920' - ); - } $rawly = Robot::findFirstById(1); $rawly->parts; @@ -302,17 +248,6 @@ public function testShouldUseEagerLoadingAndDetectHasManyToMany() public function testShouldUseEagerLoadingAndDetectHasMany() { - if (version_compare(PHP_VERSION, '5.6.0', '<') && - version_compare(Version::get(), '3.2.0', '=') - ) { - $this->markTestSkipped( - 'The Phalcon\Mvc\Model\Query\Builder was changed in Phalcon v3.2.0.' . PHP_EOL . - 'These changes do not allow to correctly run tests in PHP 5.5.' . PHP_EOL . - 'See https://github.com/phalcon/cphalcon/pull/12905/commits/8052204db745e93aacfc38c1b6651e29b7ba9440' . PHP_EOL . - 'And https://travis-ci.org/phalcon/incubator/jobs/244703920' - ); - } - $rawly = Manufacturer::findFirstById(1); $rawly->robots; @@ -342,17 +277,6 @@ public function testShouldUseEagerLoadingAndDetectHasMany() public function testShouldUseEagerLoadingAndDetectHasOne() { - if (version_compare(PHP_VERSION, '5.6.0', '<') && - version_compare(Version::get(), '3.2.0', '=') - ) { - $this->markTestSkipped( - 'The Phalcon\Mvc\Model\Query\Builder was changed in Phalcon v3.2.0.' . PHP_EOL . - 'These changes do not allow to correctly run tests in PHP 5.5.' . PHP_EOL . - 'See https://github.com/phalcon/cphalcon/pull/12905/commits/8052204db745e93aacfc38c1b6651e29b7ba9440' . PHP_EOL . - 'And https://travis-ci.org/phalcon/incubator/jobs/244703920' - ); - } - $rawly = Robot::findFirstById(1); $rawly->purpose; @@ -365,17 +289,6 @@ public function testShouldUseEagerLoadingAndDetectHasOne() public function testShouldUseEagerLoadingAndDetectBelongsToDeep() { - if (version_compare(PHP_VERSION, '5.6.0', '<') && - version_compare(Version::get(), '3.2.0', '=') - ) { - $this->markTestSkipped( - 'The Phalcon\Mvc\Model\Query\Builder was changed in Phalcon v3.2.0.' . PHP_EOL . - 'These changes do not allow to correctly run tests in PHP 5.5.' . PHP_EOL . - 'See https://github.com/phalcon/cphalcon/pull/12905/commits/8052204db745e93aacfc38c1b6651e29b7ba9440' . PHP_EOL . - 'And https://travis-ci.org/phalcon/incubator/jobs/244703920' - ); - } - $rawly = Manufacturer::findFirstById(1); $rawly->robots = $this->resultSetToEagerLoadingEquivalent($rawly->robots); @@ -398,17 +311,6 @@ public function testShouldUseEagerLoadingAndDetectBelongsToDeep() public function testBelongsTo() { - if (version_compare(PHP_VERSION, '5.6.0', '<') && - version_compare(Version::get(), '3.2.0', '=') - ) { - $this->markTestSkipped( - 'The Phalcon\Mvc\Model\Query\Builder was changed in Phalcon v3.2.0.' . PHP_EOL . - 'These changes do not allow to correctly run tests in PHP 5.5.' . PHP_EOL . - 'See https://github.com/phalcon/cphalcon/pull/12905/commits/8052204db745e93aacfc38c1b6651e29b7ba9440' . PHP_EOL . - 'And https://travis-ci.org/phalcon/incubator/jobs/244703920' - ); - } - $rawly = Bug::findFirstById(1); $rawly->robot; From 37353f0eadd67b5b7f64b0232ccb929a5db9ac3f Mon Sep 17 00:00:00 2001 From: kideny Date: Fri, 21 Jul 2017 18:18:28 +0800 Subject: [PATCH 2/5] fixed function's name error --- Library/Phalcon/Acl/Factory/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Phalcon/Acl/Factory/README.md b/Library/Phalcon/Acl/Factory/README.md index bead5edb3..7575e86be 100644 --- a/Library/Phalcon/Acl/Factory/README.md +++ b/Library/Phalcon/Acl/Factory/README.md @@ -13,7 +13,7 @@ To setup `acl` service in DI `service.php` file using `acl.ini` file: use Phalcon\Config\Adapter\Ini as ConfigIni; use Phalcon\Acl\Factory\Memory as AclMemory; -$di->setShaerd( +$di->setShared( 'acl' function () { $config = new ConfigIni(APP_PATH . '/config/acl.ini'); @@ -33,7 +33,7 @@ To setup `acl` service in DI `service.php` file using `acl.php` (array) file: use Phalcon\Config; use Phalcon\Acl\Factory\Memory as AclMemory; -$di->setShaerd( +$di->setShared( 'acl' function () { $config = new Config(APP_PATH . '/config/acl.php'); From 365a9d6b32d493d0e2ec3989777a4978b2910317 Mon Sep 17 00:00:00 2001 From: sergeysviridenko Date: Mon, 24 Jul 2017 15:40:16 +0300 Subject: [PATCH 3/5] Change query in read method of Session adapter --- Library/Phalcon/Session/Adapter/Database.php | 6 +- composer.json | 6 +- tests/_data/dump.sql | 11 ++ .../Helper/Session/Dialect/DatabaseTrait.php | 28 ++++ .../Helper/Session/Dialect/ModelSession.php | 27 ++++ tests/_support/Module/UnitTest.php | 36 +++++ tests/unit/Session/Adapter/DatabaseTest.php | 143 ++++++++++++++++++ 7 files changed, 253 insertions(+), 4 deletions(-) create mode 100644 tests/_support/Helper/Session/Dialect/DatabaseTrait.php create mode 100644 tests/_support/Helper/Session/Dialect/ModelSession.php create mode 100644 tests/_support/Module/UnitTest.php create mode 100644 tests/unit/Session/Adapter/DatabaseTest.php diff --git a/Library/Phalcon/Session/Adapter/Database.php b/Library/Phalcon/Session/Adapter/Database.php index 47dc61f40..da5481176 100644 --- a/Library/Phalcon/Session/Adapter/Database.php +++ b/Library/Phalcon/Session/Adapter/Database.php @@ -26,6 +26,7 @@ use Phalcon\Session\AdapterInterface; use Phalcon\Session\Exception; use Phalcon\Db\AdapterInterface as DbAdapter; +use Phalcon\Db\Column; /** * Phalcon\Session\Adapter\Database @@ -121,7 +122,8 @@ public function read($sessionId) $maxLifetime ), Db::FETCH_NUM, - [$sessionId, time()] + [$sessionId, time()], + [Column::BIND_PARAM_STR, Column::BIND_PARAM_INT] ); if (empty($row)) { @@ -151,7 +153,7 @@ public function write($sessionId, $data) [$sessionId] ); - if (!empty($row) && intval($row[0]) > 0) { + if ($row[0] > 0) { return $this->connection->execute( sprintf( 'UPDATE %s SET %s = ?, %s = ? WHERE %s = ?', diff --git a/composer.json b/composer.json index b649e50f6..70baa0a28 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,8 @@ "codeception/specify": "^0.4", "codeception/verify": "^0.3", "vlucas/phpdotenv": "^2.4", - "phalcon/dd": "^1.1" + "phalcon/dd": "^1.1", + "doctrine/instantiator": "1.0.5" }, "suggest": { "ext-aerospike": "*", @@ -64,7 +65,8 @@ "Phalcon\\Test\\Behavior\\Blameable\\": "tests/_data/behavior/blameable", "Phalcon\\Test\\Aerospike\\": "tests/aerospike/", "Phalcon\\Test\\Unit5x\\": "tests/unit5x/", - "Phalcon\\Test\\Collections\\": "tests/_data/collections" + "Phalcon\\Test\\Collections\\": "tests/_data/collections", + "Phalcon\\Test\\Module\\": "tests/_support/Module" }, "files": [ "tests/_support/functions.php" diff --git a/tests/_data/dump.sql b/tests/_data/dump.sql index 811de8fde..ae16c2640 100644 --- a/tests/_data/dump.sql +++ b/tests/_data/dump.sql @@ -1252,6 +1252,7 @@ CREATE TABLE `cache_data` ( `lifetime` INT, PRIMARY KEY(`key_name`) ); + DROP TABLE IF EXISTS `robots`; CREATE TABLE `robots` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, @@ -1259,6 +1260,7 @@ CREATE TABLE `robots` ( `type` varchar(32) COLLATE utf8_unicode_ci NOT NULL default 'mechanical', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + DROP TABLE if EXISTS `audit`; CREATE TABLE `audit` ( `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, @@ -1270,6 +1272,7 @@ CREATE TABLE `audit` ( `primary_key` TEXT DEFAULT NULL, /* for BC reasons */ PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + DROP TABLE if EXISTS `audit_detail`; CREATE TABLE `audit_detail` ( `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, @@ -1279,3 +1282,11 @@ CREATE TABLE `audit_detail` ( `new_value` TEXT NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +DROP TABLE if EXISTS `session`; +CREATE TABLE `sessions` ( + session_id TEXT NOT NULL, + data TEXT, + created_at INT, + modified_at INT +)ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/tests/_support/Helper/Session/Dialect/DatabaseTrait.php b/tests/_support/Helper/Session/Dialect/DatabaseTrait.php new file mode 100644 index 000000000..06280fa4b --- /dev/null +++ b/tests/_support/Helper/Session/Dialect/DatabaseTrait.php @@ -0,0 +1,28 @@ + + * @package Helper\Session\Dialect + * + * The contents of this file are subject to the New BSD License that is + * bundled with this package in the file LICENSE.txt + * + * If you did not receive a copy of the license and are unable to obtain it + * through the world-wide-web, please send an email to license@phalconphp.com + * so that we can send you a copy immediately. + */ +trait DatabaseTrait +{ + protected function getWrittenSessionData($sessionID) + { + $sql = "DELETE FROM sessions WHERE session_id = '{$sessionID}'"; + + return $sql; + } +} diff --git a/tests/_support/Helper/Session/Dialect/ModelSession.php b/tests/_support/Helper/Session/Dialect/ModelSession.php new file mode 100644 index 000000000..b00f36e8f --- /dev/null +++ b/tests/_support/Helper/Session/Dialect/ModelSession.php @@ -0,0 +1,27 @@ + + * @package Helper\Session\Dialect + * + * The contents of this file are subject to the New BSD License that is + * bundled with this package in the file LICENSE.txt + * + * If you did not receive a copy of the license and are unable to obtain it + * through the world-wide-web, please send an email to license@phalconphp.com + * so that we can send you a copy immediately. + */ + +use Phalcon\Mvc\Model; +use Phalcon\Mvc\ModelInterface; + +class ModelSession extends Model +{ + public static $table = 'sessions'; +} diff --git a/tests/_support/Module/UnitTest.php b/tests/_support/Module/UnitTest.php new file mode 100644 index 000000000..56cd32002 --- /dev/null +++ b/tests/_support/Module/UnitTest.php @@ -0,0 +1,36 @@ + + * @author Nikolaos Dimopoulos + * @package Phalcon\Test\Module + * + * The contents of this file are subject to the New BSD License that is + * bundled with this package in the file LICENSE.txt + * + * If you did not receive a copy of the license and are unable to obtain it + * through the world-wide-web, please send an email to license@phalconphp.com + * so that we can send you a copy immediately. + */ +class UnitTest extends Unit +{ + use Specify; + + /** + * UnitTester Object + * @var UnitTester + */ + protected $tester; +} diff --git a/tests/unit/Session/Adapter/DatabaseTest.php b/tests/unit/Session/Adapter/DatabaseTest.php new file mode 100644 index 000000000..9a4f38d10 --- /dev/null +++ b/tests/unit/Session/Adapter/DatabaseTest.php @@ -0,0 +1,143 @@ + + * @package Phalcon\Test\Session\Adapter + * @group Db + * + * The contents of this file are subject to the New BSD License that is + * bundled with this package in the file LICENSE.txt + * + * If you did not receive a copy of the license and are unable to obtain it + * through the world-wide-web, please send an email to license@phalconphp.com + * so that we can send you a copy immediately. + */ +class DatabaseTest extends UnitTest +{ + use DatabaseTrait; + + /** + * @var DbAdapter + */ + protected $connection; + + /** + * @var SessionAdapter + */ + protected $session; + + /** + * executed before each test + */ + protected function _before() + { + $this->connection = new Mysql( + [ + 'host' => env('TEST_DB_HOST', '127.0.0.1'), + 'username' => env('TEST_DB_USER', 'incubator'), + 'password' => env('TEST_DB_PASSWD', 'secret'), + 'dbname' => env('TEST_DB_NAME', 'incubator'), + 'charset' => env('TEST_DB_CHARSET', 'utf8'), + 'port' => env('TEST_DB_PORT', 3306) + ] + ); + + $this->session = new Database([ + 'db' => $this->connection, + 'table' => 'sessions', + 'lifetime' => 3600 + ]); + } + + /** + * Tests Database::write + * + * @test + * @author Sergii Svyrydenko + * @since 2017-07-24 + */ + public function shouldWorkSessionAdapter() + { + $this->session->start(); + $sessionID = $this->session->getId(); + $this->session->set('customer_id', 'somekey'); + $this->specify( + "Method set() hasn't worked", + function ($data, $expected) { + expect($data)->equals($expected); + }, + [ + 'examples' => [ + [$_SESSION['customer_id'], 'somekey'] + ] + ] + ); + + + $this->session->write($sessionID, session_encode()); + $this->tester->seeInDatabase(ModelSession::$table, ['session_id' => $sessionID]); + $this->tester->seeInDatabase(ModelSession::$table, ['data' => 'customer_id|s:7:"somekey";']); + $this->session->remove('customer_id'); + + + $sessionData = $this->session->read($sessionID); + session_start(); + session_decode($sessionData); + + $this->specify( + "Method read() hasn't worked", + function ($data, $expected) { + expect($data)->equals($expected); + }, + [ + 'examples' => [ + [$_SESSION['customer_id'], 'somekey'] + ] + ] + ); + + $this->session->set('customer_id', 'somekey'); + $this->session->set('customer_id2', 'somekey2'); + $this->session->write($sessionID, session_encode()); + $this->tester->seeInDatabase(ModelSession::$table, ['session_id' => $sessionID]); + $this->tester->seeInDatabase(ModelSession::$table, ['data' => 'customer_id|s:7:"somekey";customer_id2|s:8:"somekey2";']); + $this->session->remove('customer_id'); + $this->session->remove('customer_id2'); + + $sessionData = $this->session->read($sessionID); + session_start(); + session_decode($sessionData); + + $this->specify( + "Method update() hasn't worked", + function ($data, $expected) { + expect($data)->equals($expected); + }, + [ + 'examples' => [ + [$_SESSION['customer_id'], 'somekey'], + [$_SESSION['customer_id2'], 'somekey2'] + ] + ] + ); + + $this->connection->execute($this->getWrittenSessionData($sessionID)); + $this->tester->dontSeeInDatabase(ModelSession::$table, ['session_id' => $sessionID]); + } +} From 0544482f3a99fd824b31162c8772f59ae3e3b844 Mon Sep 17 00:00:00 2001 From: Mike Joseph Date: Mon, 24 Jul 2017 13:47:43 -0400 Subject: [PATCH 4/5] merges PR #753 onto 3.2.x branch --- .../Phalcon/Mvc/View/Engine/Twig/CoreExtension.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Library/Phalcon/Mvc/View/Engine/Twig/CoreExtension.php b/Library/Phalcon/Mvc/View/Engine/Twig/CoreExtension.php index 89a0bf2b4..8c2ade5ab 100644 --- a/Library/Phalcon/Mvc/View/Engine/Twig/CoreExtension.php +++ b/Library/Phalcon/Mvc/View/Engine/Twig/CoreExtension.php @@ -50,8 +50,16 @@ public function getFunctions() ]; return [ - 'assetsOutputCss' => new \Twig_Function_Method($this, 'functionAssetsOutputCss', $options), - 'assetsOutputJs' => new \Twig_Function_Method($this, 'functionAssetsOutputJs', $options), + 'assetsOutputCss' => new \Twig_SimpleFunction( + 'assetsOutputCss', + [$this, 'functionAssetsOutputCss'], + $options + ), + 'assetsOutputJs' => new \Twig_SimpleFunction( + 'assetsOutputJs', + [$this, 'functionAssetsOutputJs'], + $options + ) ]; } From dbc98c710a2e450461748f76380b33647018ed4e Mon Sep 17 00:00:00 2001 From: Stefan Chiriac Date: Mon, 31 Jul 2017 19:31:00 +0300 Subject: [PATCH 5/5] fix view when engines are objects --- Library/Phalcon/Mailer/Manager.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Library/Phalcon/Mailer/Manager.php b/Library/Phalcon/Mailer/Manager.php index 8c8b315b0..23e538a90 100644 --- a/Library/Phalcon/Mailer/Manager.php +++ b/Library/Phalcon/Mailer/Manager.php @@ -338,7 +338,15 @@ protected function getView() $view = $this->getDI()->get('\Phalcon\Mvc\View\Simple'); $view->setViewsDir($viewsDir); - if ($engines = $viewApp->getRegisteredEngines()) { + if ($registeredEngines = $viewApp->getRegisteredEngines()) { + $engines = []; + foreach ($registeredEngines as $key => $engine) { + if (is_object($engine)) { + $engines[$key] = get_class($engine); + } else { + $engines[$key] = $engine; + } + } $view->registerEngines($engines); }