Skip to content

Commit

Permalink
Merge branch '5.0.x' into #15363-fix-db-delete
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG-5.0.md
  • Loading branch information
Jeckerson committed May 10, 2021
2 parents d4eec3b + e99d8eb commit e352198
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 204 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

## Changed
- Changed version format to allow alpha/beta/RC releases on PECL.
- Changes `Phalcon\Db\Adapter\AbstractAdapter:delete()` signature of optional parameters. [#15363](https://github.com/phalcon/cphalcon/issues/15363)
- Changed:
- `Phalcon\Mvc\Model\Resultset\Complex::__construct` now accepts `Psr\SimpleCache\CacheInterface` for the cache
- `Phalcon\Mvc\Model\Resultset\Simple::__construct` now accepts `Psr\SimpleCache\CacheInterface` for the cache
- `Phalcon\Mvc\Model\Resultset::__construct` now accepts `Psr\SimpleCache\CacheInterface` for the cache
- `Phalcon\Mvc\Model\Resultset::getCache` now returns `Psr\SimpleCache\CacheInterface` [#15471](https://github.com/phalcon/cphalcon/issues/15471)
- Changed `Phalcon\Db\Adapter\AbstractAdapter:delete()` signature of optional parameters. [#15363](https://github.com/phalcon/cphalcon/issues/15363)

## Fixed
- Fixed `Phalcon\Db\Adapter\AbstractAdapter:delete()` when `bindTypes` argument is passed. [#15363](https://github.com/phalcon/cphalcon/issues/15363)
Expand Down
3 changes: 2 additions & 1 deletion docker/7.4/.bashrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

ZEPHIR_VERSION="0.13.4"
ZEPHIR_VERSION="0.13.5"

# Easier navigation: .., ..., ...., ....., ~ and -
alias ..="cd .."
Expand Down Expand Up @@ -86,4 +86,5 @@ alias cpl='zf && zg && cd ext/ && ./install && ..'
alias codecept='php -d extension=ext/modules/phalcon.so ./vendor/bin/codecept '
alias phpcs='php -d extension=ext/modules/phalcon.so ./vendor/bin/phpcs '
alias phpcbf='php -d extension=ext/modules/phalcon.so ./vendor/bin/phpcbf '
alias psalm='php ./vendor/bin/psalm '

3 changes: 2 additions & 1 deletion docker/8.0/.bashrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

ZEPHIR_VERSION="0.13.4"
ZEPHIR_VERSION="0.13.5"

# Easier navigation: .., ..., ...., ....., ~ and -
alias ..="cd .."
Expand Down Expand Up @@ -86,3 +86,4 @@ alias cpl='zf && zg && cd ext/ && ./install && ..'
alias codecept='php -d extension=ext/modules/phalcon.so ./vendor/bin/codecept '
alias phpcs='php -d extension=ext/modules/phalcon.so ./vendor/bin/phpcs '
alias phpcbf='php -d extension=ext/modules/phalcon.so ./vendor/bin/phpcbf '
alias psalm='php ./vendor/bin/psalm '
5 changes: 3 additions & 2 deletions phalcon/Mvc/Model/Query.zep
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use Phalcon\Mvc\Model\Resultset\Simple;
use Phalcon\Di\InjectionAwareInterface;
use Phalcon\Db\DialectInterface;
use Phalcon\Mvc\Model\Query\Lang;
use Psr\SimpleCache\CacheInterface;

/**
* Phalcon\Mvc\Model\Query
Expand Down Expand Up @@ -291,8 +292,8 @@ class Query implements QueryInterface, InjectionAwareInterface
cacheService = Arr::get(cacheOptions, "service", "modelsCache"),
cache = this->container->getShared(cacheService);

if unlikely typeof cache != "object" {
throw new Exception("Cache service must be an object");
if unlikely !(cache instanceof CacheInterface) {
throw new Exception("Cache service must be an object implementing Psr\SimpleCache\CacheInterface");
}

let result = cache->get(key);
Expand Down
10 changes: 5 additions & 5 deletions phalcon/Mvc/Model/Resultset.zep
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use Phalcon\Db\Enum;
use Phalcon\Messages\MessageInterface;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\ModelInterface;
use Phalcon\Cache\Adapter\AdapterInterface;
use Phalcon\Storage\Serializer\SerializerInterface;
use Psr\SimpleCache\CacheInterface;
use SeekableIterator;
use Serializable;

Expand Down Expand Up @@ -80,7 +80,7 @@ abstract class Resultset
protected activeRow = null;

/**
* @var AdapterInterface|null
* @var CacheInterface|null
*/
protected cache = null;

Expand Down Expand Up @@ -130,9 +130,9 @@ abstract class Resultset
* Phalcon\Mvc\Model\Resultset constructor
*
* @param ResultInterface|false result
* @param AdapterInterface|null cache
* @param CacheInterface|null cache
*/
public function __construct(result, <AdapterInterface> cache = null)
public function __construct(result, <CacheInterface> cache = null)
{
var prefetchRecords, rowCount, rows;

Expand Down Expand Up @@ -330,7 +330,7 @@ abstract class Resultset
/**
* Returns the associated cache for the resultset
*/
public function getCache() -> <AdapterInterface>
public function getCache() -> <CacheInterface> | null
{
return this->cache;
}
Expand Down
8 changes: 4 additions & 4 deletions phalcon/Mvc/Model/Resultset/Complex.zep
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Phalcon\Mvc\Model\Resultset;

use Phalcon\Cache\Adapter\AdapterInterface;
use Phalcon\Di;
use Phalcon\Di\DiInterface;
use Phalcon\Db\ResultInterface;
Expand All @@ -21,6 +20,7 @@ use Phalcon\Mvc\Model\ResultsetInterface;
use Phalcon\Mvc\Model\Row;
use Phalcon\Mvc\ModelInterface;
use Phalcon\Storage\Serializer\SerializerInterface;
use Psr\SimpleCache\CacheInterface;
use stdClass;

/**
Expand All @@ -47,14 +47,14 @@ class Complex extends Resultset implements ResultsetInterface
/**
* Phalcon\Mvc\Model\Resultset\Complex constructor
*
* @param array columnTypes
* @param array columnTypes
* @param ResultInterface|null result
* @param AdapterInterface|null cache
* @param CacheInterface|null cache
*/
public function __construct(
var columnTypes,
<ResultInterface> result = null,
<AdapterInterface> cache = null
<CacheInterface> cache = null
)
{
/**
Expand Down
12 changes: 6 additions & 6 deletions phalcon/Mvc/Model/Resultset/Simple.zep
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Phalcon\Mvc\Model\Resultset;

use Phalcon\Cache\Adapter\AdapterInterface;
use Phalcon\Di;
use Phalcon\Di\DiInterface;
use Phalcon\Mvc\Model;
Expand All @@ -19,6 +18,7 @@ use Phalcon\Mvc\Model\Resultset;
use Phalcon\Mvc\Model\Row;
use Phalcon\Mvc\ModelInterface;
use Phalcon\Storage\Serializer\SerializerInterface;
use Psr\SimpleCache\CacheInterface;

/**
* Phalcon\Mvc\Model\Resultset\Simple
Expand Down Expand Up @@ -46,17 +46,17 @@ class Simple extends Resultset
/**
* Phalcon\Mvc\Model\Resultset\Simple constructor
*
* @param array columnMap
* @param ModelInterface|Row model
* @param array columnMap
* @param ModelInterface|Row model
* @param \Phalcon\Db\ResultInterface|false result
* @param AdapterInterface|null cache
* @param bool keepSnapshots false
* @param CacheInterface|null cache
* @param bool keepSnapshots false
*/
public function __construct(
var columnMap,
var model,
result,
<AdapterInterface> cache = null,
<CacheInterface> cache = null,
bool keepSnapshots = false
)
{
Expand Down
4 changes: 2 additions & 2 deletions phalcon/Mvc/Model/ResultsetInterface.zep
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Phalcon\Mvc\Model;
use Closure;
use Phalcon\Messages\MessageInterface;
use Phalcon\Mvc\ModelInterface;
use Phalcon\Cache\Adapter\AdapterInterface;
use Psr\SimpleCache\CacheInterface;

/**
* Phalcon\Mvc\Model\ResultsetInterface
Expand Down Expand Up @@ -45,7 +45,7 @@ interface ResultsetInterface
/**
* Returns the associated cache for the resultset
*/
public function getCache() -> <AdapterInterface>;
public function getCache() -> <CacheInterface> | null;

/**
* Get first row in the resultset
Expand Down
53 changes: 48 additions & 5 deletions tests/database/Mvc/Model/FindCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

use DatabaseTester;
use PDO;
use Phalcon\Cache;
use Phalcon\Cache\AdapterFactory;
use Phalcon\Mvc\Model\Exception;
use Phalcon\Storage\SerializerFactory;
use Phalcon\Test\Fixtures\Migrations\CustomersMigration;
use Phalcon\Test\Fixtures\Migrations\ObjectsMigration;
Expand Down Expand Up @@ -104,8 +106,9 @@ public function mvcModelFindWithCache(DatabaseTester $I)
$serializerFactory = new SerializerFactory();
$adapterFactory = new AdapterFactory($serializerFactory);
$adapter = $adapterFactory->newInstance('stream', $options);
$cache = new Cache($adapter);

$this->container->setShared('modelsCache', $adapter);
$this->container->setShared('modelsCache', $cache);

/**
* Get the records (should cache the resultset)
Expand Down Expand Up @@ -175,10 +178,7 @@ public function mvcModelFindResultsetSecondIteration(DatabaseTester $I)

$customers = Customers::find();

$I->assertCount(
2,
$customers
);
$I->assertCount(2, $customers);

/**
* First iteration
Expand Down Expand Up @@ -210,4 +210,47 @@ public function mvcModelFindResultsetSecondIteration(DatabaseTester $I)
);
}
}

/**
* Tests Phalcon\Mvc\Model :: find() - with cache/exception
*
* @author Phalcon Team <[email protected]>
* @since 2021-05-10
*
* @group mysql
* @group pgsql
* @group sqlite
*/
public function mvcModelFindWithCacheException(DatabaseTester $I)
{
$I->wantToTest('Mvc\Model - find() - with cache - exception');

$I->expectThrowable(
new Exception(
'Cache service must be an object implementing Psr\SimpleCache\CacheInterface'
),
function () {
$options = [
'storageDir' => outputDir(),
'lifetime' => 172800,
'prefix' => 'data-',
];

// Models Cache setup
$serializerFactory = new SerializerFactory();
$adapterFactory = new AdapterFactory($serializerFactory);
$adapter = $adapterFactory->newInstance('stream', $options);

$this->container->setShared('modelsCache', $adapter);

Objects::find(
[
'cache' => [
'key' => 'my-cache',
],
]
);
}
);
}
}
Loading

0 comments on commit e352198

Please sign in to comment.