Skip to content

Commit

Permalink
Merge pull request #15009 from phalcon/fix/model-events-manager-retur…
Browse files Browse the repository at this point in the history
…n-type-hint

Changed return type hint for Model::getEventsManager
  • Loading branch information
sergeyklay authored May 5, 2020
2 parents d182cd3 + ba6cdfd commit 45ee3a4
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 85 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- 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 hint for `Phalcon\Mvc\ModelInterface::sum` [#15000](https://github.com/phalcon/cphalcon/issues/15000)
- Changed return type for `Phalcon\Mvc\Model\Criteria::getLimit` so that integer, NULL or array will be returned [#15004](https://github.com/phalcon/cphalcon/issues/15004)
- Changed return type hint for `Phalcon\Mvc\Model\Manager::getCustomEventsManager` to return NULL instead of boolean FALSE if there is no special events manager [#15008](https://github.com/phalcon/cphalcon/issues/15008)

## 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 @@ -46,6 +47,7 @@
- Fixed return type hint for `Phalcon\Mvc\Model::sum` [#15000](https://github.com/phalcon/cphalcon/issues/15000)
- Fixed return type hint for `Phalcon\Mvc\Model\CriteriaInterface::getLimit` and `Phalcon\Mvc\Model\Criteria::getLimit` to follow documentation and original purpose [#15004](https://github.com/phalcon/cphalcon/issues/15004)
- Fixed return type hint for `Phalcon\Mvc\Model::count` and `Phalcon\Mvc\ModelInterface::count` to reflect original behavior [#15006](https://github.com/phalcon/cphalcon/issues/15006)
- Fixed return type hint for `Phalcon\Mvc\Model::getEventsManager` to reflect original behavior [#15008](https://github.com/phalcon/cphalcon/issues/15008)

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

Expand Down
4 changes: 2 additions & 2 deletions ext/phalcon/mvc/model.zep.h

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

8 changes: 4 additions & 4 deletions ext/phalcon/mvc/model/manager.zep.c

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

6 changes: 5 additions & 1 deletion ext/phalcon/mvc/model/manager.zep.h

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

4 changes: 2 additions & 2 deletions phalcon/Mvc/Model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -1700,9 +1700,9 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
}

/**
* Returns the custom events manager
* Returns the custom events manager or null if there is no custom events manager
*/
public function getEventsManager() -> <EventsManagerInterface>
public function getEventsManager() -> <EventsManagerInterface> | null
{
return this->modelsManager->getCustomEventsManager(this);
}
Expand Down
10 changes: 5 additions & 5 deletions phalcon/Mvc/Model/Manager.zep
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,17 @@ class Manager implements ManagerInterface, InjectionAwareInterface, EventsAwareI
}

/**
* Returns a custom events manager related to a model
* Returns a custom events manager related to a model or null if there is no related events manager
*/
public function getCustomEventsManager(<ModelInterface> model) -> <EventsManagerInterface> | bool
public function getCustomEventsManager(<ModelInterface> model) -> <EventsManagerInterface> | null
{
var eventsManager;

if !fetch eventsManager, this->customEventsManager[get_class_lower(model)] {
return false;
if fetch eventsManager, this->customEventsManager[get_class_lower(model)] {
return eventsManager;
}

return eventsManager;
return null;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/_data/fixtures/models/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* @property string $inv_title
* @property float $inv_total
* @property string $inv_created_at
*
* @method static static findFirst($parameters = null)
* @method static Model\Resultset\Simple|static[] find($parameters = null)
*/
class Invoices extends Model
{
Expand Down
13 changes: 0 additions & 13 deletions tests/database/Db/Adapter/Pdo/DescribeColumnsCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,6 @@ public function _before(DatabaseTester $I): void
$this->migration = new ComplexDefaultMigration($I->getConnection());
}

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

/**
* Tests Phalcon\Db\Adapter\Pdo :: describeColumns()
*
Expand Down
13 changes: 0 additions & 13 deletions tests/database/Mvc/Model/CountCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@ 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();
}
}

/**
* Tests Phalcon\Mvc\Model :: count()
*
Expand Down
42 changes: 27 additions & 15 deletions tests/database/Mvc/Model/GetSetEventsManagerCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* (c) Phalcon Team <[email protected]>
*
* 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);
Expand All @@ -15,6 +15,7 @@

use DatabaseTester;
use Phalcon\Events\Manager;
use Phalcon\Storage\Exception;
use Phalcon\Test\Fixtures\Migrations\InvoicesMigration;
use Phalcon\Test\Fixtures\Traits\DiTrait;
use Phalcon\Test\Models\Invoices;
Expand All @@ -28,20 +29,35 @@ class GetSetEventsManagerCest
{
use DiTrait;

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());
}

/**
* Tests Phalcon\Mvc\Model :: getEventsManager()
*
* @param DatabaseTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2020-02-01
*
Expand All @@ -53,19 +69,15 @@ public function mvcModelGetEventsManager(DatabaseTester $I)
{
$I->wantToTest('Mvc\Model - getEventsManager()');

$title = uniqid('inv-');
/** @var PDO $connection */
$connection = $I->getConnection();
$migration = new InvoicesMigration($connection);
$migration->insert(4, null, 0, $title);
$this->invoiceMigration->insert(4, null, 0, uniqid('inv-', true));

$invoice = Invoices::findFirst();
$manager = new Manager();

$I->assertFalse(
$I->assertNull(
$invoice->getEventsManager()
);

$manager = new Manager();
$invoice->setEventsManager($manager);

$I->assertEquals(
Expand Down
17 changes: 0 additions & 17 deletions tests/database/Mvc/Model/QueryCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,6 @@ 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
13 changes: 0 additions & 13 deletions tests/database/Mvc/Model/SumCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,6 @@ 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();
}
}

/**
* Tests Phalcon\Mvc\Model :: sum()
*
Expand Down

0 comments on commit 45ee3a4

Please sign in to comment.