Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed return type hint for Phalcon\Mvc\Model::sum #15001

Merged
merged 3 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Changed the default ACL access level from boolean `FALSE` to `Enum::DENY` [#14974](https://github.com/phalcon/cphalcon/pull/14974)
- Changed the way `Phalcon\Http\Response::__construct` checks `content` data type. Now a `TypeError` will be thrown if incompatible data type was passed [#14983](https://github.com/phalcon/cphalcon/issues/14983)
- Changed return type hints of the following `Phalcon\Flash\FlashInterface`'s methods: `error`, `message`, `notice`, `success` and `warning` [#14994](https://github.com/phalcon/cphalcon/issues/14994)
- Changed return type hints for `Phalcon\Mvc\ModelInterface::sum` [#15000](https://github.com/phalcon/cphalcon/issues/15000)

## Fixed
- Fixed `Phalcon\Mvc\Model\Query\Builder::getPhql` to add single quote between string value on a simple condition [#14874](https://github.com/phalcon/cphalcon/issues/14874)
Expand Down Expand Up @@ -41,6 +42,7 @@
- Fixed return type hint for `Phalcon\Di::getInternalEventsManager` [#14992](https://github.com/phalcon/cphalcon/issues/14992)
- Fixed return type hints of the following `Phalcon\Flash\AbstractFlash`'s methods: `error`, `notice`, `success` and `warning` [#14994](https://github.com/phalcon/cphalcon/issues/14994)
- Fixed return type hint for `Phalcon\Translate\InterpolatorFactory::newInstance` [#14996](https://github.com/phalcon/cphalcon/issues/14996)
- Fixed return type hint for `Phalcon\Mvc\Model::sum` [#15000](https://github.com/phalcon/cphalcon/issues/15000)

[#14987](https://github.com/phalcon/cphalcon/issues/14987)

Expand Down
594 changes: 297 additions & 297 deletions ext/phalcon/mvc/model.zep.c

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions ext/phalcon/mvc/model.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions ext/phalcon/mvc/modelinterface.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions ext/phalcon/mvc/modelinterface.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions phalcon/Mvc/Model.zep
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

/**
* This file is part of the Phalcon.
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.com>
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
* For the full copyright and license information, please view the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Phalcon\Mvc;
Expand Down Expand Up @@ -2982,9 +2983,9 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
* ```
*
* @param array parameters
* @return double
* @return double | ResultsetInterface
*/
public static function sum(var parameters = null) -> float
public static function sum(var parameters = null) -> float | <ResultsetInterface>
{
return self::_groupResult("SUM", "sumatory", parameters);
}
Expand Down
13 changes: 7 additions & 6 deletions phalcon/Mvc/ModelInterface.zep
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

/**
* This file is part of the Phalcon.
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.com>
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
* For the full copyright and license information, please view the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Phalcon\Mvc;
Expand Down Expand Up @@ -248,9 +249,9 @@ interface ModelInterface
* Allows to calculate a sum on a column that match the specified conditions
*
* @param array parameters
* @return double
* @return double | ResultsetInterface
*/
public static function sum(parameters = null) -> float;
public static function sum(parameters = null) -> float | <ResultsetInterface>;

/**
* Check whether validation process has generated any messages
Expand Down
56 changes: 17 additions & 39 deletions tests/_data/fixtures/Traits/RecordsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,17 @@
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
* For the full copyright and license information, please view the
* LICENSE.txt file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Test\Fixtures\Traits;

use DatabaseTester;
use PDO;
use Phalcon\Annotations\Adapter\Memory as AnnotationsMemory;
use Phalcon\Cache\Adapter\Libmemcached as StorageLibmemcached;
use Phalcon\Cache\Adapter\Stream as StorageStream;
use Phalcon\Cli\Console as CliConsole;
use Phalcon\Crypt;
use Phalcon\Db\Adapter\PdoFactory;
use Phalcon\Di;
use Phalcon\Di\DiInterface;
use Phalcon\Di\FactoryDefault;
use Phalcon\Di\FactoryDefault\Cli as CliFactoryDefault;
use Phalcon\Escaper;
use Phalcon\Events\Manager as EventsManager;
use Phalcon\Filter;
use Phalcon\Http\Request;
use Phalcon\Http\Response;
use Phalcon\Mvc\Model\Manager as ModelsManager;
use Phalcon\Mvc\Model\Metadata\Memory as MetadataMemory;
use Phalcon\Mvc\View;
use Phalcon\Mvc\View\Simple;
use Phalcon\Session\Adapter\Libmemcached as SessionLibmemcached;
use Phalcon\Session\Adapter\Noop as SessionNoop;
use Phalcon\Session\Adapter\Redis as SessionRedis;
use Phalcon\Session\Adapter\Stream as SessionFiles;
use Phalcon\Session\Manager as SessionManager;
use Phalcon\Storage\SerializerFactory;
use Phalcon\Test\Fixtures\Migrations\InvoicesMigration;
use Phalcon\Url;
use function dataDir;
use function getOptionsLibmemcached;
use function getOptionsMysql;
use function getOptionsPostgresql;
use function getOptionsRedis;
use function getOptionsSqlite;
use PHPUnit\Framework\Assert;

use function uniqid;

trait RecordsTrait
Expand All @@ -59,7 +27,7 @@ trait RecordsTrait
*/
private function getFibonacci(int $number)
{
return round(pow((sqrt(5) + 1) / 2, $number) / sqrt(5));
return round((((sqrt(5) + 1) / 2) ** $number) / sqrt(5));
}

/**
Expand All @@ -78,15 +46,25 @@ private function insertDataInvoices(
string $prefix,
int $pad = 0
) {
$title = uniqid($prefix . '-');
$title = uniqid($prefix . '-', true);
for ($counter = 1; $counter <= $count; $counter++) {
$migration->insert(
$result = $migration->insert(
$invId,
$custId,
1,
$title,
$this->getFibonacci($pad + $counter)
);

if (!$result) {
$table = $migration->getTable();
$driver = $migration->getDriverName();
Assert::fail(
sprintf("Failed to insert row #%d into table '%s' using '%s' driver", $counter, $table, $driver)
);
}


}
}
}
17 changes: 17 additions & 0 deletions tests/database/Mvc/Model/QueryCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ public function _before(DatabaseTester $I): void
$this->invoiceMigration = new InvoicesMigration($I->getConnection());
}

/**
* Executed after each test
*
* @param DatabaseTester $I
* @return void
*/
public function _after(DatabaseTester $I): void
{
if ($this->invoiceMigration) {
$this->invoiceMigration->clear();
}

if ($this->customerMigration) {
$this->customerMigration->clear();
}
}

/**
* Tests Phalcon\Mvc\Model :: query()
*
Expand Down
68 changes: 51 additions & 17 deletions tests/database/Mvc/Model/SumCest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<?php

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the
* LICENSE.txt file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Test\Database\Mvc\Model;

use DatabaseTester;
use Phalcon\Mvc\Model\Resultset\Simple;
use Phalcon\Storage\Exception;
use Phalcon\Test\Fixtures\Migrations\InvoicesMigration;
use Phalcon\Test\Fixtures\Traits\DiTrait;
use Phalcon\Test\Fixtures\Traits\RecordsTrait;
Expand All @@ -16,20 +26,48 @@ class SumCest
use DiTrait;
use RecordsTrait;

public function _before(DatabaseTester $I)
/**
* @var InvoicesMigration
*/
private $invoiceMigration;

/**
* Executed before each test
*
* @param DatabaseTester $I
* @return void
*/
public function _before(DatabaseTester $I): void
{
$this->setNewFactoryDefault();
try {
$this->setNewFactoryDefault();
} catch (Exception $e) {
$I->fail($e->getMessage());
}

$this->setDatabase($I);

/** @var PDO $connection */
$connection = $I->getConnection();
$migration = new InvoicesMigration($connection);
$migration->clear();
$this->invoiceMigration = new InvoicesMigration($I->getConnection());
}

/**
* Executed after each test
*
* @param DatabaseTester $I
* @return void
*/
public function _after(DatabaseTester $I): void
{
if ($this->invoiceMigration) {
$this->invoiceMigration->clear();
}
}

/**
* Tests Phalcon\Mvc\Model :: sum()
*
* @param DatabaseTester $I
*
* @author Phalcon Team <team@phalcon.io>
* @since 2020-01-30
*
Expand All @@ -38,19 +76,15 @@ public function _before(DatabaseTester $I)
*/
public function mvcModelSum(DatabaseTester $I)
{

/**
* The following tests need to skip sqlite because we will get
* a General Error 5 database is locked error
* @todo The following tests are skipped for sqlite because we will get
* a General Error 5 database is locked error.
*/
/** @var PDO $connection */
$connection = $I->getConnection();
$migration = new InvoicesMigration($connection);
$invId = ('sqlite' === $I->getDriver()) ? 'null' : 'default';

$this->insertDataInvoices($migration, 7, $invId, 2, 'ccc');
$this->insertDataInvoices($migration, 1, $invId, 3, 'aaa');
$this->insertDataInvoices($migration, 11, $invId, 1, 'aaa');
$invId = ('sqlite' === $I->getDriver()) ? 'null' : 'default';

$this->insertDataInvoices($this->invoiceMigration, 7, $invId, 2, 'ccc');
$this->insertDataInvoices($this->invoiceMigration, 1, $invId, 3, 'aaa');
$this->insertDataInvoices($this->invoiceMigration, 11, $invId, 1, 'aaa');


$total = Invoices::sum(
Expand Down