Skip to content

Commit

Permalink
Confirmed valid traits; Paginator db tests; New models
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Feb 3, 2020
1 parent 076b477 commit 74aa882
Show file tree
Hide file tree
Showing 61 changed files with 1,127 additions and 978 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ composer.lock
php_test_results_*.txt
docker-compose.yml
build/gccarch
tests/_data/phalcon_test*
tests/_output/*

.php_cs.cache
Expand Down
24 changes: 16 additions & 8 deletions tests/_data/fixtures/Migrations/InvoicesMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,31 @@ class InvoicesMigration extends AbstractMigration

/**
* @param int $id
* @param int|null $custId
* @param int $status
* @param string|null $title
* @param float $total
* @param string|null $createdAt
*
* @return int
*/
public function insert(
int $id,
string $title = null
$id,
int $custId = null,
int $status = 0,
string $title = null,
float $total = 0,
string $createdAt = null
): int {
$title = $title ?: uniqid();
$now = date('Y-m-d H:i:s');
$total = 100 + $id;
$flag = (int) ($id % 2);
$sql = <<<SQL
$id = $id ?: 'null';
$title = $title ?: uniqid();
$custId = $custId ?: 1;
$now = $createdAt ?: date('Y-m-d H:i:s');
$sql = <<<SQL
insert into co_invoices (
`inv_id`, `inv_cst_id`, `inv_status_flag`, `inv_title`, `inv_total`, `inv_created_at`
) values (
{$id}, 1, {$flag}, "{$title}", {$total}, "{$now}"
{$id}, {$custId}, {$status}, "{$title}", {$total}, "{$now}"
)
SQL;

Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/ApcuTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/ConfigTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/CookieTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/DiTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/FactoryTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/GdTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/ImagickTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/LibmemcachedTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/_data/fixtures/Traits/LoaderTrait.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* 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 UnitTester;
Expand Down
4 changes: 2 additions & 2 deletions tests/_data/fixtures/Traits/LoggerTrait.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* 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 DateTime;
Expand Down
77 changes: 77 additions & 0 deletions tests/_data/fixtures/Traits/RecordsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (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.
*/

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 function uniqid;

trait RecordsTrait
{
/**
* @param InvoicesMigration $migration
* @param int $count
* @param int $custId
* @param string $prefix
*/
private function insertDataInvoices(
InvoicesMigration $migration,
int $count,
int $custId,
string $prefix
) {
$title = uniqid($prefix . '-');
for ($counter = 1; $counter <= $count; $counter++) {
$migration->insert(
null,
$custId,
1,
$title
);
}
}
}
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/RedisTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/RouterTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/SessionBagTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/SessionTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/TranslateArrayTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/TranslateCsvTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/TranslateGettextTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/ValidationTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/VersionTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
1 change: 1 addition & 0 deletions tests/_data/fixtures/Traits/ViewTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/**
Expand Down
File renamed without changes.
53 changes: 53 additions & 0 deletions tests/_data/fixtures/models/InvoicesMap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (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.
*/

namespace Phalcon\Test\Models;

use Phalcon\Mvc\Model;

/**
* Class InvoicesMap
*
* @property int $inv_id
* @property int $inv_cst_id
* @property int $inv_status_flag
* @property string $inv_title
* @property float $inv_total
* @property string $inv_created_at
*/
class InvoicesMap 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');
}

public function columnMap()
{
return [
'inv_id' => 'id',
'inv_cst_id' => 'cst_id',
'inv_status_flag' => 'status_flag',
'inv_title' => 'title',
'inv_total' => 'total',
'inv_created_at' => 'created_at',
];
}
}
56 changes: 56 additions & 0 deletions tests/database/Mvc/Model/ConstructCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* This file is part of the Phalcon Framework.
*
* (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.
*/

declare(strict_types=1);

namespace Phalcon\Test\Database\Mvc\Model;

use DatabaseTester;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\ModelInterface;
use Phalcon\Test\Fixtures\Traits\DiTrait;
use Phalcon\Test\Models\Invoices;

/**
* Class ConstructCest
*/
class ConstructCest
{
use DiTrait;

public function _before(DatabaseTester $I)
{
$this->setNewFactoryDefault();
$this->setDatabase($I);
}

/**
* Tests Phalcon\Mvc\Model :: __construct()
*
* @author Phalcon Team <[email protected]>
* @since 2018-11-13
*/
public function mvcModelConstruct(DatabaseTester $I)
{
$I->wantToTest('Mvc\Model - __construct()');

$invoice = new Invoices();

$I->assertInstanceOf(
Model::class,
$invoice
);
$I->assertInstanceOf(
ModelInterface::class,
$invoice
);
}
}
Loading

0 comments on commit 74aa882

Please sign in to comment.