Skip to content

Commit

Permalink
[#14733] - Fixtures for DM
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Feb 8, 2020
1 parent 91672fa commit e03565f
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/_data/fixtures/DM/Pdo/ConnectionFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* This file is part of the Phalcon Framework.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Test\Fixtures\DM\Pdo;

use Phalcon\DM\Pdo\Connection;
use Phalcon\DM\Pdo\Profiler\ProfilerInterface;

class ConnectionFixture extends Connection
{
public function __construct(
string $dsn,
string $username = null,
string $password = null,
array $options = [],
array $queries = [],
ProfilerInterface $profiler = null
) {
$this->pdo = new PdoFixture();
}
}
20 changes: 20 additions & 0 deletions tests/_data/fixtures/DM/Pdo/PdoFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* This file is part of the Phalcon Framework.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Test\Fixtures\DM\Pdo;

class PdoFixture
{
public function callMe(string $name): string
{
return $name;
}
}
79 changes: 79 additions & 0 deletions tests/_data/fixtures/Migrations/Invoices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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\Fixtures\Migrations;

use Phalcon\DM\Pdo\Connection;

use function date;
use function uniqid;

class Invoices
{
/**
* Invoices constructor.
*
* @param Connection $connection
*/
public function __construct(Connection $connection)
{
$this->truncate($connection);
}

/**
* @param Connection $connection
* @param int $id
* @param string|null $title
*
* @return int
*/
public function insert(
Connection $connection,
int $id,
string $title = null
): int {
$title = $title ?: uniqid();
$now = date('Y-m-d H:i:s');
$total = 100 + $id;
$flag = (int) ($id % 2);
$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}"
)
SQL;

return $connection->exec($sql);
}

/**
* @param Connection $connection
*/
public function truncate(Connection $connection): void
{
$sql = "delete from co_invoices";

$connection->exec($sql);
}
}
22 changes: 22 additions & 0 deletions tests/_data/fixtures/Resultset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/**
* This file is part of the Phalcon Framework.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Phalcon\Test\Fixtures;

class Resultset
{
public $calculated = '';

public function __construct(string $calculated)
{
$this->calculated = $calculated;
}
}

0 comments on commit e03565f

Please sign in to comment.