Skip to content
Permalink
Browse files

Added tests

  • Loading branch information
niden committed Nov 16, 2019
1 parent 997947b commit afe7716888f93e01220cfc68dca338b36d5c45bb
@@ -0,0 +1,56 @@
<?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.md
* file that was distributed with this source code.
*/
namespace Phalcon\Test\Fixtures\Migrations;
use Phalcon\Db\Adapter\AdapterInterface;
class InvoicesMigration
{
public function __invoke(AdapterInterface $db)
{
$sql = <<<SQL
drop table if exists `co_invoices`
SQL;
$db->execute($sql);
$sql = <<<SQL
create table co_invoices
(
inv_id int(10) auto_increment primary key,
inv_cst_id int(10) null,
inv_status_flag tinyint(1) null,
inv_title varchar(100) null,
inv_total float(10, 2) null,
inv_created_at datetime null
);
SQL;
$db->execute($sql);
$sql = <<<SQL
create index co_invoices_inv_created_at_index
on co_invoices (inv_created_at);
SQL;
$db->execute($sql);
$sql = <<<SQL
create index co_invoices_inv_cst_id_index
on co_invoices (inv_cst_id);
SQL;
$db->execute($sql);
$sql = <<<SQL
create index co_invoices_inv_status_flag_index
on co_invoices (inv_status_flag);
SQL;
$db->execute($sql);
}
}
@@ -0,0 +1,29 @@
<?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.md
* file that was distributed with this source code.
*/
namespace Phalcon\Test\Models;
use Phalcon\Mvc\Model;
class Invoices extends Model
{
public $inv_id;
public $inv_cst_id;
public $inv_status_flag;
public $inv_title;
public $inv_total;
public $inv_created_at;
public function initialize()
{
$this->setSource('co_invoices');
}
}
@@ -0,0 +1,33 @@
<?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.md
* file that was distributed with this source code.
*/
namespace Phalcon\Test\Models;
use Phalcon\Mvc\Model;
use function getenv;
class InvoicesSchema extends Model
{
public $inv_id;
public $inv_cst_id;
public $inv_status_flag;
public $inv_title;
public $inv_total;
public $inv_created_at;
public function initialize()
{
$this->setSource('co_invoices');
$this->setSchema(
getenv('DATA_MYSQL_NAME')
);
}
}
@@ -6,7 +6,7 @@
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view the LICENSE.txt
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
@@ -15,14 +15,18 @@
use IntegrationTester;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\MetaData;
use Phalcon\Test\Fixtures\Migrations\InvoicesMigration;
use Phalcon\Test\Fixtures\Traits\DiTrait;
use Phalcon\Test\Models\AlbumORama\Albums;
use Phalcon\Test\Models\AlbumORama\Artists;
use Phalcon\Test\Models\Invoices;
use Phalcon\Test\Models\InvoicesSchema;
use Phalcon\Test\Models\Parts;
use Phalcon\Test\Models\Robots;
use Phalcon\Test\Models\RobotsParts;
use Phalcon\Test\Models\Users;
use Phalcon\Test\Models\TinyIntTest;
use function uniqid;
class SaveCest
{
@@ -345,6 +349,9 @@ public function mvcModelSaveAfterWithoutDefaultValues(IntegrationTester $I)
);
}
/**
* Tests Phalcon\Mvc\Model :: save() with circular unsaved relations
*/
public function mvcModelSaveCircularRelation(IntegrationTester $I)
{
$I->wantToTest('Mvc\Model::save() with circular unsaved relations');
@@ -377,7 +384,15 @@ public function mvcModelSaveCircularRelation(IntegrationTester $I)
$I->assertNotNull($artist->id);
}
public function mvcModelSaveAfterFetchingRelatedIssue14270(IntegrationTester $I)
/**
* Tests Phalcon\Mvc\Model :: save() after fetching related using magic getter
*
* @see https://github.com/phalcon/cphalcon/issues/14270
*
* @author Phalcon Team <team@phalcon.io>
* @since 2019-08-02
*/
public function mvcModelSaveAfterFetchingRelatedWithMagicGetter(IntegrationTester $I)
{
$I->wantToTest('Mvc\Model::save() after fetching related using magic getter');
@@ -439,9 +454,17 @@ public function mvcModelSaveAfterFetchingRelatedIssue14270(IntegrationTester $I)
);
}
public function tinyIntNotStoredIssue14355(IntegrationTester $I)
/**
* Tests Phalcon\Mvc\Model :: save() with a tinyint(1)
*
* @see https://github.com/phalcon/cphalcon/issues/14355
*
* @author Phalcon Team <team@phalcon.io>
* @since 2019-08-02
*/
public function mvcModelSaveWithTinyInt(IntegrationTester $I)
{
$I->wantToTest('Saving a tinyint(1)');
$I->wantToTest('Mvc\Model::save() with a tinyint(1)');
$referenceModel = new TinyIntTest();
$referenceModel->test = 0;
@@ -460,4 +483,43 @@ public function tinyIntNotStoredIssue14355(IntegrationTester $I)
$storedModel->test
);
}
/**
* Tests Phalcon\Mvc\Model\ :: save() with schema
*
* @author Phalcon Team <team@phalcon.io>
* @since 2019-11-16
*/
public function mvcModelSaveWithSchema(IntegrationTester $I)
{
$I->wantToTest('Mvc\Model - save() with a schema');
/**
* Setup the table
*/
(new InvoicesMigration())($this->container->get('db'));
$model = new Invoices();
$model->inv_cst_id = 1;
$model->inv_status_flag = 1;
$model->inv_title = uniqid();
$model->inv_total = 100;
$model->inv_created_at = date('Y-m-d H:i:s');
$result = $model->save();
$I->assertNotFalse($result);
$model = new InvoicesSchema();
$model->inv_cst_id = 1;
$model->inv_status_flag = 1;
$model->inv_title = uniqid();
$model->inv_total = 100;
$model->inv_created_at = date('Y-m-d H:i:s');
$result = $model->save();
$I->assertNotFalse($result);
}
}

0 comments on commit afe7716

Please sign in to comment.
You can’t perform that action at this time.